From 748b9f08bc77e36047175a14313c4d593846ce4f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 15 Jun 2022 09:34:44 +0200 Subject: [PATCH] ci: send slack alerts for sims only on status change (#12225) * ci: send slack sims notification only on status change Co-authored-by: Marko --- .../actions/last-workflow-status/action.yaml | 36 ++++++++++++++ .github/workflows/sims-045.yml | 31 +++++++++++- .github/workflows/sims-046.yml | 31 +++++++++++- .github/workflows/sims.yml | 48 +++++++++++-------- 4 files changed, 123 insertions(+), 23 deletions(-) create mode 100644 .github/actions/last-workflow-status/action.yaml diff --git a/.github/actions/last-workflow-status/action.yaml b/.github/actions/last-workflow-status/action.yaml new file mode 100644 index 0000000000..b057c3152a --- /dev/null +++ b/.github/actions/last-workflow-status/action.yaml @@ -0,0 +1,36 @@ +# from https://github.com/MercymeIlya/last-workflow-status with fixes +name: "Get status of last workflow" +description: "Get conclusion of last workflow run on current branch." +branding: + icon: "arrow-left" + color: "yellow" +inputs: + github_token: + description: Secret GitHub API token to use for making API requests. + default: ${{ github.token }} + required: true +outputs: + last_status: + description: "Conclusion of last workflow run on current branch" + value: ${{ steps.last_status.outputs.last_status }} +runs: + using: "composite" + steps: + - name: Get workflow id + shell: bash + run: | + WORKFLOW_ID=$(curl --header 'authorization: Bearer ${{ inputs.github_token }}' \ + --header 'content-type: application/json' \ + https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }} | jq -r .workflow_id) + echo "WORKFLOW_ID=$WORKFLOW_ID" >> $GITHUB_ENV + echo "Workflow id: ${WORKFLOW_ID}" + - name: Get previous build status + shell: bash + id: last_status + run: | + last_status=$(curl --silent --header 'authorization: Bearer ${{ inputs.github_token }}' \ + --header 'content-type: application/json' \ + "https://api.github.com/repos/${{ github.repository }}/actions/workflows/${{ env.WORKFLOW_ID }}/runs?per_page=1&status=completed&branch=${{ env.GITHUB_HEAD_REF }}" \ + | jq -r .workflow_runs[0].conclusion) + echo "Status of the previous build: $last_status" + echo "::set-output name=last_status::${last_status}" diff --git a/.github/workflows/sims-045.yml b/.github/workflows/sims-045.yml index 17c6b1bc1b..0f1f696d5e 100644 --- a/.github/workflows/sims-045.yml +++ b/.github/workflows/sims-045.yml @@ -104,11 +104,38 @@ jobs: run: | make test-sim-multi-seed-short - sims-fail: + sims-notify-success: needs: [test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export] - if: ${{ failure() }} runs-on: ubuntu-latest + if: ${{ success() }} + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Get previous workflow status + uses: ./.github/actions/last-workflow-status + id: last_status + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Notify Slack on success + if: ${{ steps.last_status.outputs.last_status == 'failure' }} + uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_CHANNEL: cosmos-sdk-sims + SLACK_USERNAME: Sim Tests release/0.45.x + SLACK_ICON_EMOJI: ":white_check_mark:" + SLACK_COLOR: good + SLACK_MESSAGE: 0.45.x Sims are passing + SLACK_FOOTER: "" + + sims-notify-failure: + needs: + [test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export] + runs-on: ubuntu-latest + if: ${{ failure() }} steps: - name: Notify Slack on failure uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7 diff --git a/.github/workflows/sims-046.yml b/.github/workflows/sims-046.yml index e79f9cecde..39932196db 100644 --- a/.github/workflows/sims-046.yml +++ b/.github/workflows/sims-046.yml @@ -104,11 +104,38 @@ jobs: run: | make test-sim-multi-seed-short - sims-fail: + sims-notify-success: needs: [test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export] - if: ${{ failure() }} runs-on: ubuntu-latest + if: ${{ success() }} + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Get previous workflow status + uses: ./.github/actions/last-workflow-status + id: last_status + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Notify Slack on success + if: ${{ steps.last_status.outputs.last_status == 'failure' }} + uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_CHANNEL: cosmos-sdk-sims + SLACK_USERNAME: Sim Tests release/0.46.x + SLACK_ICON_EMOJI: ":white_check_mark:" + SLACK_COLOR: good + SLACK_MESSAGE: 0.46.x Sims are passing + SLACK_FOOTER: "" + + sims-notify-failure: + needs: + [test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export] + runs-on: ubuntu-latest + if: ${{ failure() }} steps: - name: Notify Slack on failure uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7 diff --git a/.github/workflows/sims.yml b/.github/workflows/sims.yml index 8cce13d452..33cadac082 100644 --- a/.github/workflows/sims.yml +++ b/.github/workflows/sims.yml @@ -102,11 +102,38 @@ jobs: run: | make test-sim-multi-seed-short - sims-fail: + sims-notify-success: needs: [test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export] - if: ${{ failure() }} runs-on: ubuntu-latest + if: ${{ success() }} + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Get previous workflow status + uses: ./.github/actions/last-workflow-status + id: last_status + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Notify Slack on success + if: ${{ steps.last_status.outputs.last_status == 'failure' }} + uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_CHANNEL: cosmos-sdk-sims + SLACK_USERNAME: Sim Tests + SLACK_ICON_EMOJI: ":white_check_mark:" + SLACK_COLOR: good + SLACK_MESSAGE: Sims are passing + SLACK_FOOTER: "" + + sims-notify-failure: + needs: + [test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export] + runs-on: ubuntu-latest + if: ${{ failure() }} steps: - name: Notify Slack on failure uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7 @@ -118,20 +145,3 @@ jobs: SLACK_COLOR: danger SLACK_MESSAGE: Sims are failing SLACK_FOOTER: "" - - sims-success: - needs: - [test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export] - if: ${{ success() }} - runs-on: ubuntu-latest - steps: - - name: Notify Slack on failure - uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7 - env: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - SLACK_CHANNEL: cosmos-sdk-sims - SLACK_USERNAME: Sim Tests - SLACK_ICON_EMOJI: ":white_check_mark:" - SLACK_COLOR: good - SLACK_MESSAGE: Sims are passing - SLACK_FOOTER: ""