PREVIEW_PUBLISH #17
This file contains hidden or 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: ["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 pr artifact | |
| uses: dawidd6/action-download-artifact@v6 | |
| with: | |
| workflow: ${{ github.event.workflow_run.workflow_id }} | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: pr | |
| - name: save PR id | |
| id: pr | |
| run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT | |
| - name: download preview site artifact | |
| uses: dawidd6/action-download-artifact@v6 | |
| with: | |
| workflow: ${{ github.event.workflow_run.workflow_id }} | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: preview | |
| - run: | | |
| unzip preview.zip | |
| - name: Upload surge service and generate preview URL | |
| id: deploy | |
| run: | | |
| repository=${{github.repository}} | |
| export DEPLOY_DOMAIN=https://preview-pr-${{ steps.pr.outputs.id }}-we-socket.surge.sh | |
| npx surge --project dist --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }} | |
| echo the preview URL is $DEPLOY_DOMAIN | |
| echo "url=$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT | |
| - name: update status comment | |
| uses: actions-cool/maintain-one-comment@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| body: | | |
| <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 -->" | |
| preview-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@v6 | |
| with: | |
| workflow: ${{ github.event.workflow_run.workflow_id }} | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: pr | |
| - name: save PR id | |
| id: pr | |
| run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT | |
| - name: The job failed | |
| uses: actions-cool/maintain-one-comment@v3 | |
| 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 -->" |