From a665d679cc1439ddbc5ee505a2537eb00f437a60 Mon Sep 17 00:00:00 2001 From: Yihau Chen Date: Wed, 30 Nov 2022 00:58:42 +0800 Subject: [PATCH] Merge pull request from GHSA-cq9g-c286-6ch7 * create a reusable workflow for current error reporting logic * make github.event.head_commit.message as a env, COMMIT_MESSAGE * make github.event.head_commit.author.name as a env, COMMIT_AUTHOR_NAME * remove redundant name * replace error reporting step with the reusalble workflow --- .github/workflows/client-targets.yml | 18 +++---------- .github/workflows/docs.yml | 18 +++---------- .github/workflows/error-reporting.yml | 27 ++++++++++++++++++++ .github/workflows/export-github-repo.yml | 18 +++---------- .github/workflows/release-artifacts-auto.yml | 18 +++---------- 5 files changed, 39 insertions(+), 60 deletions(-) create mode 100644 .github/workflows/error-reporting.yml diff --git a/.github/workflows/client-targets.yml b/.github/workflows/client-targets.yml index bd5afc629..3b3d1779a 100644 --- a/.github/workflows/client-targets.yml +++ b/.github/workflows/client-targets.yml @@ -68,18 +68,6 @@ jobs: - android - ios if: failure() && github.event_name == 'push' - runs-on: ubuntu-20.04 - steps: - - name: Slack - run: | - curl -H "Content-Type: application/json" \ - -X POST ${{ secrets.SLACK_ERROR_REPORTING_WEBHOOK }} \ - -d '{ - "attachments": [ - { - "color": "#AC514C", - "text": - "*${{ github.repository }} (${{ github.workflow }})*\n${{ github.event.head_commit.message }} - _${{ github.event.head_commit.author.name }}_\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Build>", - } - ] - }' + uses: ./.github/workflows/error-reporting.yml + secrets: + WEBHOOK: ${{ secrets.SLACK_ERROR_REPORTING_WEBHOOK }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index b47838488..0c2ca666a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -93,18 +93,6 @@ jobs: - check - build_and_deploy if: failure() && github.event_name == 'push' - runs-on: ubuntu-20.04 - steps: - - name: Slack - run: | - curl -H "Content-Type: application/json" \ - -X POST ${{ secrets.SLACK_ERROR_REPORTING_WEBHOOK }} \ - -d '{ - "attachments": [ - { - "color": "#AC514C", - "text": - "*${{ github.repository }} (${{ github.workflow }})*\n${{ github.event.head_commit.message }} - _${{ github.event.head_commit.author.name }}_\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Build>", - } - ] - }' + uses: ./.github/workflows/error-reporting.yml + secrets: + WEBHOOK: ${{ secrets.SLACK_ERROR_REPORTING_WEBHOOK }} diff --git a/.github/workflows/error-reporting.yml b/.github/workflows/error-reporting.yml new file mode 100644 index 000000000..4a5c65619 --- /dev/null +++ b/.github/workflows/error-reporting.yml @@ -0,0 +1,27 @@ +name: error-reporting + +on: + workflow_call: + secrets: + WEBHOOK: + required: true + +jobs: + slack: + runs-on: ubuntu-20.04 + steps: + - env: + COMMIT_MESSAGE: ${{ github.event.head_commit.message }} + COMMIT_AUTHOR_NAME: ${{ github.event.head_commit.author.name }} + run: | + curl -H "Content-Type: application/json" \ + -X POST ${{ secrets.WEBHOOK }} \ + -d '{ + "attachments": [ + { + "color": "#AC514C", + "text": + "*${{ github.repository }} (${{ github.workflow }})*\n'"$COMMIT_MESSAGE"' - _'"$COMMIT_AUTHOR_NAME"'_\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Build>", + } + ] + }' diff --git a/.github/workflows/export-github-repo.yml b/.github/workflows/export-github-repo.yml index b9e3474b1..8a5ab32c1 100644 --- a/.github/workflows/export-github-repo.yml +++ b/.github/workflows/export-github-repo.yml @@ -30,18 +30,6 @@ jobs: needs: - web3 if: failure() && github.event_name == 'push' - runs-on: ubuntu-20.04 - steps: - - name: Slack - run: | - curl -H "Content-Type: application/json" \ - -X POST ${{ secrets.SLACK_ERROR_REPORTING_WEBHOOK }} \ - -d '{ - "attachments": [ - { - "color": "#AC514C", - "text": - "*${{ github.repository }} (${{ github.workflow }})*\n${{ github.event.head_commit.message }} - _${{ github.event.head_commit.author.name }}_\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Build>", - } - ] - }' + uses: ./.github/workflows/error-reporting.yml + secrets: + WEBHOOK: ${{ secrets.SLACK_ERROR_REPORTING_WEBHOOK }} diff --git a/.github/workflows/release-artifacts-auto.yml b/.github/workflows/release-artifacts-auto.yml index 0eb6151fd..5b4c1385c 100644 --- a/.github/workflows/release-artifacts-auto.yml +++ b/.github/workflows/release-artifacts-auto.yml @@ -22,18 +22,6 @@ jobs: needs: - release-artifacts if: failure() && github.event_name == 'push' - runs-on: ubuntu-20.04 - steps: - - name: Slack - run: | - curl -H "Content-Type: application/json" \ - -X POST ${{ secrets.SLACK_ERROR_REPORTING_WEBHOOK }} \ - -d '{ - "attachments": [ - { - "color": "#AC514C", - "text": - "*${{ github.repository }} (${{ github.workflow }})*\n${{ github.event.head_commit.message }} - _${{ github.event.head_commit.author.name }}_\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Build>", - } - ] - }' + uses: ./.github/workflows/error-reporting.yml + secrets: + WEBHOOK: ${{ secrets.SLACK_ERROR_REPORTING_WEBHOOK }}