Skip to content

Commit

Permalink
Merge branch 'comment-on-failure'
Browse files Browse the repository at this point in the history
  • Loading branch information
balakrishna-deriv committed Sep 27, 2023
2 parents cc84155 + 1920f31 commit c19dd43
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions .github/workflows/generate-preview-link.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c19dd43

Please sign in to comment.