From 9f911a87f88b37a939ff9a58a6055117b3e2f62f Mon Sep 17 00:00:00 2001 From: Jacob Shandling Date: Tue, 24 Dec 2024 14:26:34 -0800 Subject: [PATCH] wip - composite action --- .../slack-error-notification/action.yml | 36 ++++++++++ .github/workflows/jacob-experiment.yaml | 67 +++++++++++-------- 2 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 .github/actions/slack-error-notification/action.yml diff --git a/.github/actions/slack-error-notification/action.yml b/.github/actions/slack-error-notification/action.yml new file mode 100644 index 000000000000..44c6e5bd849b --- /dev/null +++ b/.github/actions/slack-error-notification/action.yml @@ -0,0 +1,36 @@ +name: Slack notification on error +description: If the job fails, send a summary of errors to the Slack #help-engineering channel +# Schema: https://json.schemastore.org/github-action.json + +# This action expects the following env vars to be set: +# ? + +# inputs: +runs: + using: "composite" + steps: + - name: Slack Notification + # if: failure() + shell: bash + working-directory: "./" + uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 + with: + payload: | + { + "text": "${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }}", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": " ${{ job.name }} - result: ${{ job.status }}\nhttps://github.com/fleetdm/fleet/actions/runs/${{ github.run_id }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }}" + } + } + ] + } + env: + JOB_STATUS: ${{ job.status }} + EVENT_URL: ${{ github.event.pull_request.html_url || github.event.head.html_url }} + RUN_URL: https://github.com/fleetdm/fleet/actions/runs/${{ github.run_id }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_G_HELP_ENGINEERING_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK diff --git a/.github/workflows/jacob-experiment.yaml b/.github/workflows/jacob-experiment.yaml index efba608a7fcb..a2a3baaa0e69 100644 --- a/.github/workflows/jacob-experiment.yaml +++ b/.github/workflows/jacob-experiment.yaml @@ -17,33 +17,44 @@ jobs: test-job-always-fails: runs-on: ubuntu-latest steps: + - name: Checkout code needed for composite action + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + sparse-checkout: | + .github/actions/slack-error-notification/action.yml + # sparse-checkout-cone-mode: false - name: Always fail - run: exit 1 - - name: Slack notification + run: | + pwd + exit 1 + - name: Notify errors in slack if: failure() - # confirm: - uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 - # confirm: - with: - payload: | - { - "text": "${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }}", - "blocks": [ - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Happy Holidays! Jacob's always fails test result: ${{ job.status }}\nhttps://github.com/fleetdm/fleet/actions/runs/${{ github.run_id }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }}" - } - } - ] - } - env: - # confirm: - JOB_STATUS: ${{ job.status }} - # confirm: - EVENT_URL: ${{ github.event.pull_request.html_url || github.event.head.html_url }} - # confirm: - RUN_URL: https://github.com/fleetdm/fleet/actions/runs/${{ github.run_id }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_G_HELP_ENGINEERING_WEBHOOK_URL }} - SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + uses: ./.github/actions/slack-error-notification + # - name: Slack notification + # if: failure() + # # confirm: + # uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 + # # confirm: + # with: + # payload: | + # { + # "text": "${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }}", + # "blocks": [ + # { + # "type": "section", + # "text": { + # "type": "mrkdwn", + # "text": "Happy Holidays! Jacob's always fails test result: ${{ job.status }}\nhttps://github.com/fleetdm/fleet/actions/runs/${{ github.run_id }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }}" + # } + # } + # ] + # } + # env: + # # confirm: + # JOB_STATUS: ${{ job.status }} + # # confirm: + # EVENT_URL: ${{ github.event.pull_request.html_url || github.event.head.html_url }} + # # confirm: + # RUN_URL: https://github.com/fleetdm/fleet/actions/runs/${{ github.run_id }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }} + # SLACK_WEBHOOK_URL: ${{ secrets.SLACK_G_HELP_ENGINEERING_WEBHOOK_URL }} + # SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK