PREVIEW_PUBLISH #2688
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PREVIEW_PUBLISH | |
on: | |
workflow_run: | |
workflows: ["MAIN_PULL_REQUEST"] | |
types: | |
- completed | |
jobs: | |
preview-success: | |
runs-on: ubuntu-latest | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' | |
steps: | |
- name: download _site artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: _site | |
- shell: bash | |
run: | | |
if [ -f "_site.zip" ];then | |
unzip _site.zip | |
else | |
echo "文件不存在" && exit 1 | |
fi | |
- run: ls | |
- name: save PR id | |
id: pr | |
run: echo "::set-output name=id::$(<_site/pr-id.txt)" | |
- name: Upload surge service and generate preview URL | |
id: deploy | |
run: | | |
repository=${{github.repository}} | |
project_name=${repository#*/} | |
export DEPLOY_DOMAIN=https://preview-pr${{ steps.pr.outputs.id }}-$project_name.surge.sh | |
npx surge --project ./_site --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }} | |
echo the preview URL is $DEPLOY_DOMAIN | |
echo "::set-output name=url::$DEPLOY_DOMAIN" | |
- name: update status comment | |
uses: actions-cool/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body: | | |
tdesign-vue preview 地址:(如果你有 DOM 变动请自行在对应技术栈仓库中发起 PR) | |
<a href="${{steps.deploy.outputs.url}}"><img height="96" alt="完成" src="https://user-images.githubusercontent.com/15634204/150816437-9f5bb788-cd67-4cbc-9897-b82d74e9aa65.png" /></a> | |
<!-- [工作流地址](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) --> | |
<!-- AUTO_PREVIEW_HOOK --> | |
number: ${{ steps.pr.outputs.id }} | |
body-include: "<!-- AUTO_PREVIEW_HOOK -->" | |
- run: | | |
rm -rf _site/ | |
- name: The job failed | |
if: ${{ failure() }} | |
uses: actions-cool/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body: | | |
[<img height="96" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) | |
<!-- AUTO_PREVIEW_HOOK --> | |
number: ${{ steps.pr.outputs.id }} | |
body-include: "<!-- AUTO_PREVIEW_HOOK -->" | |
preview-failed: | |
runs-on: ubuntu-latest | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'failure' | |
steps: | |
- name: The job failed | |
run: | | |
id=${{ github.event.workflow_run.id }} | |
echo 工作流 $id 失败了 |