|
1 | | -# 文件名建议统一为 preview-publish |
2 | | -# 应用 preview.yml 的 demo |
3 | 1 | name: PREVIEW_PUBLISH |
4 | 2 |
|
5 | 3 | on: |
|
9 | 7 | - completed |
10 | 8 |
|
11 | 9 | jobs: |
12 | | - call-preview: |
13 | | - uses: TDesignOteam/workflows/.github/workflows/reusable-pr-preview.yml@main |
14 | | - secrets: |
15 | | - TDESIGN_SURGE_TOKEN: ${{ secrets.TDESIGN_SURGE_TOKEN }} |
| 10 | + preview-deploy: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: > |
| 13 | + github.event.workflow_run.event == 'pull_request' && |
| 14 | + github.event.workflow_run.conclusion == 'success' |
| 15 | + steps: |
| 16 | + - name: Download pr artifact |
| 17 | + uses: dawidd6/action-download-artifact@v8 |
| 18 | + with: |
| 19 | + workflow: ${{ github.event.workflow_run.workflow_id }} |
| 20 | + run_id: ${{ github.event.workflow_run.id }} |
| 21 | + name: pr |
| 22 | + |
| 23 | + - name: Save PR id |
| 24 | + id: pr |
| 25 | + run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT |
| 26 | + |
| 27 | + - name: Download site artifact |
| 28 | + uses: dawidd6/action-download-artifact@v8 |
| 29 | + with: |
| 30 | + workflow: ${{ github.event.workflow_run.workflow_id }} |
| 31 | + run_id: ${{ github.event.workflow_run.id }} |
| 32 | + name: _site |
| 33 | + |
| 34 | + - run: unzip _site.zip |
| 35 | + |
| 36 | + - name: Deploy to Surge |
| 37 | + id: deploy |
| 38 | + run: | |
| 39 | + export DEPLOY_DOMAIN=https://preview-pr-${{ steps.pr.outputs.id }}-tdesign-starter-cli.surge.sh |
| 40 | + npx surge --project ./_site --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }} |
| 41 | + echo "url=$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT |
| 42 | +
|
| 43 | + - name: Comment preview URL |
| 44 | + uses: actions-cool/maintain-one-comment@v3 |
| 45 | + with: |
| 46 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + body: | |
| 48 | + <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> |
| 49 | + <!-- AUTO_PREVIEW_HOOK --> |
| 50 | + number: ${{ steps.pr.outputs.id }} |
| 51 | + body-include: <!-- AUTO_PREVIEW_HOOK --> |
| 52 | + |
| 53 | + - name: Clean up |
| 54 | + run: rm -rf _site/ |
| 55 | + |
| 56 | + - name: Deploy failed |
| 57 | + if: failure() |
| 58 | + uses: actions-cool/maintain-one-comment@v3 |
| 59 | + with: |
| 60 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + body: | |
| 62 | + [<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 }}) |
| 63 | + <!-- AUTO_PREVIEW_HOOK --> |
| 64 | + number: ${{ steps.pr.outputs.id }} |
| 65 | + body-include: <!-- AUTO_PREVIEW_HOOK --> |
| 66 | + |
| 67 | + preview-failed: |
| 68 | + runs-on: ubuntu-latest |
| 69 | + if: > |
| 70 | + github.event.workflow_run.event == 'pull_request' && |
| 71 | + github.event.workflow_run.conclusion == 'failure' |
| 72 | + steps: |
| 73 | + - name: Download pr artifact |
| 74 | + uses: dawidd6/action-download-artifact@v8 |
| 75 | + with: |
| 76 | + workflow: ${{ github.event.workflow_run.workflow_id }} |
| 77 | + run_id: ${{ github.event.workflow_run.id }} |
| 78 | + name: pr |
| 79 | + |
| 80 | + - name: Save PR id |
| 81 | + id: pr |
| 82 | + run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT |
| 83 | + |
| 84 | + - name: Comment failure |
| 85 | + uses: actions-cool/maintain-one-comment@v3 |
| 86 | + with: |
| 87 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + body: | |
| 89 | + [<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 }}) |
| 90 | + <!-- AUTO_PREVIEW_HOOK --> |
| 91 | + number: ${{ steps.pr.outputs.id }} |
| 92 | + body-include: <!-- AUTO_PREVIEW_HOOK --> |
0 commit comments