From aafdf2fa2749c224581bb1318fded9466b5fb92f Mon Sep 17 00:00:00 2001 From: Rory Abraham Date: Tue, 28 Jun 2022 15:28:16 -0700 Subject: [PATCH] Use composite action for failed workflows --- .../announceFailedWorkflowInSlack/action.yml | 22 ++++++++++ .github/workflows/createNewVersion.yml | 22 +--------- .github/workflows/deployBlocker.yml | 22 +--------- .github/workflows/finishReleaseCycle.yml | 22 +--------- .github/workflows/lockDeploys.yml | 22 +--------- .github/workflows/platformDeploy.yml | 18 +------- .github/workflows/preDeploy.yml | 44 ++----------------- .github/workflows/updateProtectedBranch.yml | 22 +--------- .github/workflows/warnCPLabel.yml | 22 +--------- 9 files changed, 39 insertions(+), 177 deletions(-) create mode 100644 .github/actions/composite/announceFailedWorkflowInSlack/action.yml diff --git a/.github/actions/composite/announceFailedWorkflowInSlack/action.yml b/.github/actions/composite/announceFailedWorkflowInSlack/action.yml new file mode 100644 index 000000000000..6a21642ad1ff --- /dev/null +++ b/.github/actions/composite/announceFailedWorkflowInSlack/action.yml @@ -0,0 +1,22 @@ +name: 'Announce failed workflow in Slack' +description: 'Post failed workflow in Slack #announce channel' +runs: + using: composite + steps: + - uses: 8398a7/action-slack@v3 + name: Job failed Slack notification + with: + status: custom + fields: workflow, repo + custom_payload: | + { + channel: '#announce', + attachments: [{ + color: "#DB4545", + pretext: ``, + text: `💥 ${process.env.AS_REPO} failed on ${process.env.AS_WORKFLOW} workflow 💥`, + }] + } + env: + GITHUB_TOKEN: ${{ github.token }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} diff --git a/.github/workflows/createNewVersion.yml b/.github/workflows/createNewVersion.yml index 73cc2c10b7b4..3c6d0f7374e0 100644 --- a/.github/workflows/createNewVersion.yml +++ b/.github/workflows/createNewVersion.yml @@ -73,23 +73,5 @@ jobs: WORKFLOW: updateProtectedBranch.yml INPUTS: '{ "TARGET_BRANCH": "main", "SOURCE_BRANCH": "${{ env.VERSION_BRANCH }}" }' - # This Slack step is duplicated in all workflows, if you make a change to this step, make sure to update all - # the other workflows with the same change - - uses: 8398a7/action-slack@v3 - name: Job failed Slack notification - if: ${{ failure() }} - with: - status: custom - fields: workflow, repo - custom_payload: | - { - channel: '#announce', - attachments: [{ - color: "#DB4545", - pretext: ``, - text: `💥 ${process.env.AS_REPO} failed on ${process.env.AS_WORKFLOW} workflow 💥`, - }] - } - env: - GITHUB_TOKEN: ${{ github.token }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + - if: ${{ failure() }} + uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main diff --git a/.github/workflows/deployBlocker.yml b/.github/workflows/deployBlocker.yml index af2f68319dce..d21fe9809f23 100644 --- a/.github/workflows/deployBlocker.yml +++ b/.github/workflows/deployBlocker.yml @@ -64,23 +64,5 @@ jobs: 2. Find someone who can quickly fix the issue. 3. Fix the issue yourself. - # This Slack step is duplicated in all workflows, if you make a change to this step, make sure to update all - # the other workflows with the same change - - uses: 8398a7/action-slack@v3 - name: Job failed Slack notification - if: ${{ failure() }} - with: - status: custom - fields: workflow, repo - custom_payload: | - { - channel: '#announce', - attachments: [{ - color: "#DB4545", - pretext: ``, - text: `💥 ${process.env.AS_REPO} failed on ${process.env.AS_WORKFLOW} workflow 💥`, - }] - } - env: - GITHUB_TOKEN: ${{ github.token }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + - if: ${{ failure() }} + uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main diff --git a/.github/workflows/finishReleaseCycle.yml b/.github/workflows/finishReleaseCycle.yml index 999e9198245e..f6ddc198f518 100644 --- a/.github/workflows/finishReleaseCycle.yml +++ b/.github/workflows/finishReleaseCycle.yml @@ -121,23 +121,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} NPM_VERSION: ${{ env.NEW_VERSION }} - # This Slack step is duplicated in all workflows, if you make a change to this step, make sure to update all - # the other workflows with the same change - - uses: 8398a7/action-slack@v3 - name: Job failed Slack notification - if: ${{ failure() }} - with: - status: custom - fields: workflow, repo - custom_payload: | - { - channel: '#announce', - attachments: [{ - color: "#DB4545", - pretext: ``, - text: `💥 ${process.env.AS_REPO} failed on ${process.env.AS_WORKFLOW} workflow 💥`, - }] - } - env: - GITHUB_TOKEN: ${{ github.token }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + - if: ${{ failure() }} + uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main diff --git a/.github/workflows/lockDeploys.yml b/.github/workflows/lockDeploys.yml index c862307fe958..b182c1a734e0 100644 --- a/.github/workflows/lockDeploys.yml +++ b/.github/workflows/lockDeploys.yml @@ -29,23 +29,5 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} - # This Slack step is duplicated in all workflows, if you make a change to this step, make sure to update all - # the other workflows with the same change - - uses: 8398a7/action-slack@v3 - name: Job failed Slack notification - if: ${{ failure() }} - with: - status: custom - fields: workflow, repo - custom_payload: | - { - channel: '#announce', - attachments: [{ - color: "#DB4545", - pretext: ``, - text: `💥 ${process.env.AS_REPO} failed on ${process.env.AS_WORKFLOW} workflow 💥`, - }] - } - env: - GITHUB_TOKEN: ${{ github.token }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + - if: ${{ failure() }} + uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main diff --git a/.github/workflows/platformDeploy.yml b/.github/workflows/platformDeploy.yml index 5dde0740209a..1bf682557149 100644 --- a/.github/workflows/platformDeploy.yml +++ b/.github/workflows/platformDeploy.yml @@ -356,23 +356,7 @@ jobs: if: ${{ failure() }} needs: [android, desktop, iOS, web] steps: - - uses: 8398a7/action-slack@v3 - name: Job failed Slack notification - with: - status: custom - fields: workflow, repo - custom_payload: | - { - channel: '#announce', - attachments: [{ - color: "#DB4545", - pretext: ``, - text: `💥 ${process.env.AS_REPO} failed on ${process.env.AS_WORKFLOW} workflow 💥`, - }] - } - env: - GITHUB_TOKEN: ${{ github.token }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + - uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main postSlackMessageOnSuccess: name: Post a Slack message when all platforms deploy successfully diff --git a/.github/workflows/preDeploy.yml b/.github/workflows/preDeploy.yml index edb217781c3c..a3c852ea6f0a 100644 --- a/.github/workflows/preDeploy.yml +++ b/.github/workflows/preDeploy.yml @@ -17,26 +17,8 @@ jobs: if: ${{ always() }} steps: - # This Slack step is duplicated in all workflows, if you make a change to this step, make sure to update all - # the other workflows with the same change - - uses: 8398a7/action-slack@v3 - name: Job failed Slack notification - if: ${{ needs.lint.result == 'failure' || needs.test.result == 'failure' }} - with: - status: custom - fields: workflow, repo - custom_payload: | - { - channel: '#announce', - attachments: [{ - color: "#DB4545", - pretext: ``, - text: `💥 ${process.env.AS_REPO} failed on ${process.env.AS_WORKFLOW} workflow 💥`, - }] - } - env: - GITHUB_TOKEN: ${{ github.token }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + - if: ${{ needs.lint.result == 'failure' || needs.test.result == 'failure' }} + uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main - if: ${{ needs.lint.result == 'failure' || needs.test.result == 'failure' }} run: exit 1 @@ -184,26 +166,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} - # This Slack step is duplicated in all workflows, if you make a change to this step, make sure to update all - # the other workflows with the same change - - uses: 8398a7/action-slack@v3 - name: Job failed Slack notification - if: ${{ failure() }} - with: - status: custom - fields: workflow, repo - custom_payload: | - { - channel: '#announce', - attachments: [{ - color: "#DB4545", - pretext: ``, - text: `💥 ${process.env.AS_REPO} failed on ${process.env.AS_WORKFLOW} workflow 💥`, - }] - } - env: - GITHUB_TOKEN: ${{ github.token }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + - if: ${{ failure() }} + uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main # Check if actor is member of Expensify organization by looking for Expensify/expensify team isExpensifyEmployee: diff --git a/.github/workflows/updateProtectedBranch.yml b/.github/workflows/updateProtectedBranch.yml index ff5d65a9079d..4be1b286cbb4 100644 --- a/.github/workflows/updateProtectedBranch.yml +++ b/.github/workflows/updateProtectedBranch.yml @@ -134,23 +134,5 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} - # This Slack step is duplicated in all workflows, if you make a change to this step, make sure to update all - # the other workflows with the same change - - uses: 8398a7/action-slack@v3 - name: Job failed Slack notification - if: ${{ failure() }} - with: - status: custom - fields: workflow, repo - custom_payload: | - { - channel: '#announce', - attachments: [{ - color: "#DB4545", - pretext: ``, - text: `💥 ${process.env.AS_REPO} failed on ${process.env.AS_WORKFLOW} workflow 💥`, - }] - } - env: - GITHUB_TOKEN: ${{ github.token }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + - if: ${{ failure() }} + uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main diff --git a/.github/workflows/warnCPLabel.yml b/.github/workflows/warnCPLabel.yml index fe3d034c7d13..bad9fd6677f6 100644 --- a/.github/workflows/warnCPLabel.yml +++ b/.github/workflows/warnCPLabel.yml @@ -19,23 +19,5 @@ jobs: :warning: :warning: **Heads up! This pull request has the `CP Staging` label.** :warning: :warning: Merging it will cause it to be immediately deployed to staging, _even if the [open `StagingDeployCash` deploy checklist](https://github.com/Expensify/App/issues?q=is%3Aopen+is%3Aissue+label%3AStagingDeployCash) is locked._ - # This Slack step is duplicated in all workflows, if you make a change to this step, make sure to update all - # the other workflows with the same change - - uses: 8398a7/action-slack@v3 - name: Job failed Slack notification - if: ${{ failure() }} - with: - status: custom - fields: workflow, repo - custom_payload: | - { - channel: '#announce', - attachments: [{ - color: "#DB4545", - pretext: ``, - text: `💥 ${process.env.AS_REPO} failed on ${process.env.AS_WORKFLOW} workflow 💥`, - }] - } - env: - GITHUB_TOKEN: ${{ github.token }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + - if: ${{ failure() }} + uses: Expensify/App/.github/actions/composite/announceFailedWorkflowInSlack@main