Skip to content

Commit b41da16

Browse files
committed
ci: add preview
1 parent 9345b76 commit b41da16

File tree

3 files changed

+111
-13
lines changed

3 files changed

+111
-13
lines changed

.github/workflows/prepreview.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: PrePreview
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
PrePreview:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
with:
13+
ref: ${{ github.event.pull_request.head.sha }}
14+
15+
- name: Build site
16+
run: npm run site:preview
17+
18+
- run: |
19+
zip -r _site.zip _site
20+
- name: upload _site artifact
21+
uses: actions/upload-artifact@v2
22+
with:
23+
name: _site
24+
path: _site.zip
25+
retention-days: 5
26+
27+
- name: Save PR number
28+
if: ${{ always() }}
29+
run: echo ${{ github.event.number }} > ./pr-id.txt
30+
31+
- name: Upload PR number
32+
if: ${{ always() }}
33+
uses: actions/upload-artifact@v2
34+
with:
35+
name: pr
36+
path: ./pr-id.txt

.github/workflows/preview-publish.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Preview Publish
2+
3+
on:
4+
workflow_run:
5+
workflows: ['Preview Build']
6+
types:
7+
- completed
8+
9+
jobs:
10+
success:
11+
runs-on: ubuntu-latest
12+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
13+
steps:
14+
- name: download pr artifact
15+
uses: dawidd6/action-download-artifact@v2
16+
with:
17+
workflow: ${{ github.event.workflow_run.workflow_id }}
18+
name: pr
19+
- name: save PR id
20+
id: pr
21+
run: echo "::set-output name=id::$(<pr-id.txt)"
22+
- name: download _site artifact
23+
uses: dawidd6/action-download-artifact@v2
24+
with:
25+
workflow: ${{ github.event.workflow_run.workflow_id }}
26+
workflow_conclusion: success
27+
name: _site
28+
- run: |
29+
unzip _site.zip
30+
31+
- name: Upload surge service and generate preview URL
32+
id: deploy
33+
run: |
34+
export DEPLOY_DOMAIN=https://preview-pr${{ steps.pr.outputs.id }}-tdesign-vue.surge.sh
35+
npx surge --project ./_site --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }}
36+
echo the preview URL is $DEPLOY_DOMAIN
37+
38+
- name: update status comment
39+
uses: actions-cool/maintain-one-comment@v1.1.0
40+
with:
41+
token: ${{ secrets.GITHUB_TOKEN }}
42+
body: |
43+
PR 预览产物在 https://preview-pr${{ steps.pr.outputs.id }}-tdesign-vue.surge.sh
44+
number: ${{ steps.pr.outputs.id }}
45+
- run: |
46+
rm -rf _site/
47+
- name: The job failed
48+
if: ${{ failure() }}
49+
uses: actions-cool/maintain-one-comment@v1.1.0
50+
with:
51+
token: ${{ secrets.GITHUB_TOKEN }}
52+
body: |
53+
PR 预览生成失败。
54+
number: ${{ steps.pr.outputs.id }}
55+
56+
failed:
57+
runs-on: ubuntu-latest
58+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure'
59+
steps:
60+
- name: download pr artifact
61+
uses: dawidd6/action-download-artifact@v2
62+
with:
63+
workflow: ${{ github.event.workflow_run.workflow_id }}
64+
name: pr
65+
- name: save PR id
66+
id: pr
67+
run: echo "::set-output name=id::$(<pr-id.txt)"
68+
- name: The job failed
69+
uses: actions-cool/maintain-one-comment@v1.1.0
70+
with:
71+
token: ${{ secrets.GITHUB_TOKEN }}
72+
body: |
73+
Deploy PR Preview failed.
74+
number: ${{ steps.pr.outputs.id }}

.github/workflows/pull-request.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,4 @@ jobs:
2424
npm install
2525
shell: bash
2626
- run: npm run lint
27-
- run: npm run test
28-
- name: Build site
29-
run: npm run site:preview
30-
- name: Upload surge service and generate preview URL
31-
id: deploy
32-
run: |
33-
export GITHUB_SHA=${{ github.sha }}
34-
export GITHUB_SHA_SUB=${GITHUB_SHA: 0: 7 }
35-
export DEPLOY_DOMAIN=https://preview-$GITHUB_SHA_SUB-tdesign-vue.surge.sh
36-
npx surge --project ./_site --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }}
37-
echo the preview URL is $DEPLOY_DOMAIN
38-
if: ${{ success() }}
39-
- run: echo "🚀 This job's status is ${{ job.status }}."
27+
- run: npm run test

0 commit comments

Comments
 (0)