Skip to content

Commit

Permalink
Merge pull request #44 from Tencent/hotfix/pr-action
Browse files Browse the repository at this point in the history
Hotfix/pr action
  • Loading branch information
94dreamer committed Dec 21, 2021
2 parents 7c3d3da + 5a2e427 commit ac30dea
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 16 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/preview-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: PREVIEW_PUBLISH

on:
workflow_run:
workflows: ['MAIN_PULL_REQUEST']
types:
- completed

jobs:
success:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && 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 _site artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
workflow_conclusion: success
name: _site
- run: |
unzip _site.zip
- name: Upload surge service and generate preview URL
id: deploy
run: |
export DEPLOY_DOMAIN=https://preview-pr${{ steps.pr.outputs.id }}-tdesign-vue.surge.sh
npx surge --project ./_site --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }}
echo the preview URL is $DEPLOY_DOMAIN
- name: update status comment
uses: actions-cool/maintain-one-comment@v1.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
PR 预览产物在 https://preview-pr${{ steps.pr.outputs.id }}-tdesign-vue.surge.sh
number: ${{ steps.pr.outputs.id }}
- run: |
rm -rf _site/
- name: The job failed
if: ${{ failure() }}
uses: actions-cool/maintain-one-comment@v1.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
PR 预览生成失败。
number: ${{ steps.pr.outputs.id }}

failed:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && 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: actions-cool/maintain-one-comment@v1.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
Deploy PR Preview failed.
number: ${{ steps.pr.outputs.id }}
35 changes: 22 additions & 13 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: recursive
ref: ${{ github.event.pull_request.head.sha }}
- name: check_email
run: |
log_emails=$(git log --pretty=format:"%ae" -1) && if [[ ${log_emails} =~ '@tencent.com' ]];then echo $log_emails && echo "邮箱校验非法" && exit 2;else echo "邮箱校验通过";fi
Expand All @@ -19,21 +20,29 @@ jobs:
with:
node-version: 16
- name: Install dependencies
run: |
npm i npm@latest -g
npm install
run: npm install
shell: bash
- run: npm run lint
- run: npm run test

- name: Build site
run: npm run site:preview
- name: Upload surge service and generate preview URL
id: deploy
run: |
export GITHUB_SHA=${{ github.sha }}
export GITHUB_SHA_SUB=${GITHUB_SHA: 0: 7 }
export DEPLOY_DOMAIN=https://preview-$GITHUB_SHA_SUB-tdesign-vue.surge.sh
npx surge --project ./_site --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }}
echo the preview URL is $DEPLOY_DOMAIN
if: ${{ success() }}
- run: echo "🚀 This job's status is ${{ job.status }}."
- run: |
zip -r _site.zip _site
- name: upload _site artifact
uses: actions/upload-artifact@v2
with:
name: _site
path: _site.zip
retention-days: 5

- name: Save PR number
if: ${{ always() }}
run: echo ${{ github.event.number }} > ./pr-id.txt

- name: Upload PR number
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: pr
path: ./pr-id.txt
4 changes: 1 addition & 3 deletions .github/workflows/tag-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ jobs:
with:
node-version: 16
- name: Install dependencies
run: |
npm i npm@latest -g
npm install
run: npm install
shell: bash
- run: echo '${{ github.ref }} ... ${{ github.ref_name }}'
- name: Build site
Expand Down

0 comments on commit ac30dea

Please sign in to comment.