Surge Preview Deploy #137
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: Surge Preview Deploy | |
| on: | |
| workflow_run: | |
| workflows: ["Surge Preview Build"] | |
| types: | |
| - completed | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' && github.repository == 'doocs/md' | |
| steps: | |
| - name: Download PR artifact | |
| uses: dawidd6/action-download-artifact@v11 | |
| with: | |
| workflow: ${{ github.event.workflow_run.workflow_id }} | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: pr | |
| - name: Save PR id | |
| id: pr | |
| run: | | |
| pr_id=$(<pr-id.txt) | |
| if ! [[ "$pr_id" =~ ^[0-9]+$ ]]; then | |
| echo "Error: pr-id.txt does not contain a valid numeric PR id. Please check." | |
| exit 1 | |
| fi | |
| echo "id=$pr_id" >> $GITHUB_OUTPUT | |
| - name: Download dist artifact | |
| uses: dawidd6/action-download-artifact@v11 | |
| with: | |
| workflow: ${{ github.event.workflow_run.workflow_id }} | |
| run_id: ${{ github.event.workflow_run.id }} | |
| workflow_conclusion: success | |
| name: dist | |
| - name: Upload surge service | |
| id: deploy | |
| run: | | |
| export DEPLOY_DOMAIN=https://doocs-md-preview-pr-${{ steps.pr.outputs.id }}.surge.sh | |
| npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }} | |
| - name: Comment PR with preview link | |
| uses: actions-cool/maintain-one-comment@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| body: | | |
| 🚀 Surge Preview has been successfully deployed! | |
| **Preview URL:** https://doocs-md-preview-pr-${{ steps.pr.outputs.id }}.surge.sh | |
| <sub>Built with commit ${{ github.event.workflow_run.head_sha }}</sub> | |
| <!-- Surge Preview Comment --> | |
| body-include: '<!-- Surge Preview Comment -->' | |
| number: ${{ steps.pr.outputs.id }} | |
| - name: Deploy failed | |
| if: ${{ failure() }} | |
| uses: actions-cool/maintain-one-comment@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| body: | | |
| 😭 Surge Preview deployment failed. | |
| Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details. | |
| <!-- Surge Preview Comment --> | |
| body-include: '<!-- Surge Preview Comment -->' | |
| number: ${{ steps.pr.outputs.id }} | |
| failed: | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' && github.repository == 'doocs/md' | |
| steps: | |
| - name: Download PR artifact | |
| uses: dawidd6/action-download-artifact@v11 | |
| with: | |
| workflow: ${{ github.event.workflow_run.workflow_id }} | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: pr | |
| - name: Save PR id | |
| id: pr | |
| run: | | |
| pr_id=$(<pr-id.txt) | |
| if ! [[ "$pr_id" =~ ^[0-9]+$ ]]; then | |
| echo "Error: pr-id.txt does not contain a valid numeric PR id. Please check." | |
| exit 1 | |
| fi | |
| echo "id=$pr_id" >> $GITHUB_OUTPUT | |
| - name: Comment PR with build failure | |
| uses: actions-cool/maintain-one-comment@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| body: | | |
| 😭 Surge Preview build failed. | |
| Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) for details. | |
| <!-- Surge Preview Comment --> | |
| body-include: '<!-- Surge Preview Comment -->' | |
| number: ${{ steps.pr.outputs.id }} |