diff --git a/.github/workflows/generate-preview-link.yml b/.github/workflows/generate-preview-link.yml index 010f7375006..fe4c6fd3e30 100644 --- a/.github/workflows/generate-preview-link.yml +++ b/.github/workflows/generate-preview-link.yml @@ -36,6 +36,11 @@ jobs: run_id: ${{ github.event.workflow_run.id }} name: 'pr-${{ github.event.workflow_run.id }}' + - name: Retrieve pull request and verify user organization + id: pr_information + run: | + echo "issue_number=$(cat ./NR)" > $GITHUB_OUTPUT + - name: 'Generate action link comment' id: generate_action_url uses: actions/github-script@v3 @@ -44,23 +49,23 @@ jobs: script: | const action_url = "${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}" const comment = [ - `**Preview Link**: ${action_url}`, - '| Name | Link |', + '| Name | Result |', '| :--- | :------ |', + `| **Build status** | Building 🔨 |`, `| **Action URL** | [Visit Action](${action_url}) |`, '' ].join('\n') core.setOutput("comment", comment); - - name: Post Cloudflare Pages Preview comment + - name: Post Cloudflare Pages Action comment uses: marocchino/sticky-pull-request-comment@v2 with: - header: Cloudflare Pages Action Comment - number: ${{github.event.workflow_run.pull_requests[0].number}} + header: Cloudflare Pages Preview Comment + number: ${{steps.pr_information.outputs.issue_number}} message: ${{steps.generate_action_url.outputs.comment}} recreate: true - - name: Retrieve pull request and verify user organization - id: pr_information + - name: Verify user organization + id: verify_user_organization run: | echo "Verifying user's organization..." user=$(cat ./USERNAME) @@ -77,7 +82,6 @@ jobs: else echo "User is a member of binary-com organization." echo "Proceeding to build and deploy for the pull request: https://github.com/binary-com/deriv-com/pull/$(cat ./NR)" - echo "issue_number=$(cat ./NR)" > $GITHUB_OUTPUT fi - name: Checkout to repo uses: actions/checkout@v3 @@ -135,22 +139,37 @@ jobs: exit 1 fi - name: 'Generate preview link comment' + if: always() id: generate_preview_url uses: actions/github-script@v3 with: github-token: ${{ github.token }} script: | - const preview_url = "${{steps.publish-to-pages.outputs.preview_url}}" - const comment = [ - `**Preview Link**: ${preview_url}`, - '| Name | Result |', - '| :--- | :------ |', - `| **Build status** | Completed ✅ |`, - `| **Preview URL** | [Visit Preview](${preview_url}) |`, - '' - ].join('\n') + let comment; + const action_url = "${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}" + if (${{steps.publish-to-pages.outcome}} == 'success') { + const preview_url = "${{steps.publish-to-pages.outputs.preview_url}}" + comment = [ + `**Preview Link**: ${preview_url}`, + '| Name | Result |', + '| :--- | :------ |', + `| **Build status** | Completed ✅ |`, + `| **Preview URL** | [Visit Preview](${preview_url}) |`, + `| **Action URL** | [Visit Action](${action_url}) |`, + '' + ].join('\n') + } else { + comment = [ + '| Name | Result |', + '| :--- | :------ |', + `| **Build status** | Failed ❌ |`, + `| **Action URL** | [Visit Action](${action_url}) |`, + '' + ].join('\n') + } core.setOutput("comment", comment); - name: Post Cloudflare Pages Preview comment + if: always() uses: marocchino/sticky-pull-request-comment@v2 with: header: Cloudflare Pages Preview Comment