name: Preview Deploy on: workflow_run: workflows: ['Preview Build'] types: [completed] permissions: actions: read contents: read issues: write pull-requests: write 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@v6 with: workflow: ${{ github.event.workflow_run.workflow_id }} name: pr - name: save PR id id: pr run: echo "::set-output name=id::$( with: github-token: ${{ secrets.GITHUB_TOKEN }} retries: 3 script: | const issueNumber = Number(process.env.PR_NUMBER); const body = process.env.COMMENT_BODY; const marker = ''; const comments = await github.paginate(github.rest.issues.listComments, { ...context.repo, issue_number: issueNumber, per_page: 100, }); const existing = comments.find((comment) => comment.body?.includes(marker)); if (existing) { await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body, }); } else { await github.rest.issues.createComment({ ...context.repo, issue_number: issueNumber, body, }); } - name: The job failed if: ${{ failure() }} uses: actions/github-script@v9 env: PR_NUMBER: ${{ steps.pr.outputs.id }} COMMENT_BODY: | 😭 Deploy PR Preview failed. with: github-token: ${{ secrets.GITHUB_TOKEN }} retries: 3 script: | const issueNumber = Number(process.env.PR_NUMBER); const body = process.env.COMMENT_BODY; const marker = ''; const comments = await github.paginate(github.rest.issues.listComments, { ...context.repo, issue_number: issueNumber, per_page: 100, }); const existing = comments.find((comment) => comment.body?.includes(marker)); if (existing) { await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body, }); } else { await github.rest.issues.createComment({ ...context.repo, issue_number: issueNumber, body, }); } 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 }} name: pr - name: save PR id id: pr run: echo "::set-output name=id::$( with: github-token: ${{ secrets.GITHUB_TOKEN }} retries: 3 script: | const issueNumber = Number(process.env.PR_NUMBER); const body = process.env.COMMENT_BODY; const marker = ''; const comments = await github.paginate(github.rest.issues.listComments, { ...context.repo, issue_number: issueNumber, per_page: 100, }); const existing = comments.find((comment) => comment.body?.includes(marker)); if (existing) { await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body, }); } else { await github.rest.issues.createComment({ ...context.repo, issue_number: issueNumber, body, }); }