forked from opentiny/tiny-vue
feat(ci): add pr preview action (#1351)
* feat(ci): add pr preview action * fix(ci): pr preview error * fix(ci): pr preview permission fix
This commit is contained in:
parent
7f766a30e7
commit
b0ee847315
|
@ -0,0 +1,66 @@
|
|||
name: Preview Build
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build-site:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: 8.3.1
|
||||
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 20
|
||||
- name: Get pnpm store directory
|
||||
id: pnpm-cache
|
||||
run: |
|
||||
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
|
||||
|
||||
- uses: actions/cache@v3
|
||||
name: Setup pnpm cache
|
||||
with:
|
||||
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
|
||||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-store-
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: Build website
|
||||
run: pnpm build:site
|
||||
env:
|
||||
NODE_OPTIONS: --max-old-space-size=4096
|
||||
|
||||
- name: Compressed into zip
|
||||
run: |
|
||||
zip -r site.zip examples/sites/dist/
|
||||
|
||||
- name: Upload Site Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: site
|
||||
path: site.zip
|
||||
retention-days: 3
|
||||
|
||||
- name: Save PR number
|
||||
if: ${{ always() }}
|
||||
run: echo ${{ github.event.number }} > ./pr-id.txt
|
||||
|
||||
- name: Upload PR number
|
||||
if: ${{ always() }}
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: pr
|
||||
path: ./pr-id.txt
|
|
@ -0,0 +1,77 @@
|
|||
name: Preview Deploy
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ['Preview Build']
|
||||
types:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
success:
|
||||
name: Build successfully
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||
steps:
|
||||
- name: Download Pr Artifact
|
||||
uses: dawidd6/action-download-artifact@v2
|
||||
with:
|
||||
workflow: ${{ github.event.workflow_run.workflow_id }}
|
||||
name: pr
|
||||
- name: Save PR Id
|
||||
id: pr
|
||||
run: echo "::set-output name=id::$(<pr-id.txt)"
|
||||
|
||||
- name: Download Dist Artifact
|
||||
uses: dawidd6/action-download-artifact@v2
|
||||
with:
|
||||
workflow: ${{ github.event.workflow_run.workflow_id }}
|
||||
workflow_conclusion: success
|
||||
name: site
|
||||
|
||||
- name: Unzip
|
||||
run: |
|
||||
unzip site.zip
|
||||
|
||||
- name: Upload To Surge
|
||||
id: deploy
|
||||
run: |
|
||||
export DEPLOY_DOMAIN=https://tiny-vue-pr-${{ steps.pr.outputs.id }}.surge.sh
|
||||
npx surge --project examples/sites/dist/ --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }}
|
||||
|
||||
- name: Create Comment
|
||||
uses: peter-evans/create-or-update-comment@v2
|
||||
with:
|
||||
issue-number: ${{ steps.pr.outputs.id }}
|
||||
body: |
|
||||
PR preview has been successfully built and deployed to https://tiny-vue-pr-${{ steps.pr.outputs.id }}.surge.sh.
|
||||
|
||||
- run: |
|
||||
rm -rf examples/sites/dist/
|
||||
|
||||
- name: The job Failed
|
||||
if: ${{ failure() }}
|
||||
uses: peter-evans/create-or-update-comment@v2
|
||||
with:
|
||||
issue-number: ${{ steps.pr.outputs.id }}
|
||||
body: |
|
||||
Deploy PR preview failed.
|
||||
|
||||
failed:
|
||||
name: Build failure
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
|
||||
steps:
|
||||
- name: Download Pr Artifact
|
||||
uses: dawidd6/action-download-artifact@v2
|
||||
with:
|
||||
workflow: ${{ github.event.workflow_run.workflow_id }}
|
||||
name: pr
|
||||
- name: Save PR Id
|
||||
id: pr
|
||||
run: echo "::set-output name=id::$(<pr-id.txt)"
|
||||
- name: The job Failed
|
||||
uses: peter-evans/create-or-update-comment@v2
|
||||
with:
|
||||
issue-number: ${{ steps.pr.outputs.id }}
|
||||
body: |
|
||||
Deploy PR preview failed.
|
|
@ -12,6 +12,7 @@
|
|||
"build:mobile:prod": "vite build --mode mobileprod",
|
||||
"build:inner:saas": "vite build --mode innersaas",
|
||||
"build:inner:prod": "vite build --mode innerprod",
|
||||
"build": "vite build",
|
||||
"build:open": "vite build --mode open",
|
||||
"prettier": "npx prettier --write ./**/*.{ts,tsx,css,less,scss,vue}",
|
||||
"stylelint": "npx stylelint ./src/**/*.scss ./src/**/*.less ./src/**/*.css --fix",
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
"build:themeMobile": "pnpm -C packages/theme-mobile build:fast",
|
||||
"build:themejson": "gulp themeJson",
|
||||
"build:internals": "pnpm \"--filter=./internals/*\" build",
|
||||
"build:site": "gulp themeConcat && pnpm -C examples/sites build",
|
||||
"release:aurora": "pnpm -C internals/cli release:aurora",
|
||||
"// ---------- 使用pnpm批量发布npm包 ----------": "",
|
||||
"pub2": "pnpm --filter=\"./packages/dist2/**\" publish --tag v2-latest --no-git-checks --access=public",
|
||||
|
|
Loading…
Reference in New Issue