|
| 1 | +name: Health Check Completed |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: Health Check |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +jobs: |
| 9 | + health_check_notification: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Download metadata artifact |
| 14 | + uses: actions/download-artifact@v4 |
| 15 | + with: |
| 16 | + name: ${{ vars.health_check_artifact }} |
| 17 | + path: ${{ vars.health_check_file }} |
| 18 | + run-id: ${{ github.event.workflow_run.id }} |
| 19 | + |
| 20 | + - name: Check if we should send a notification |
| 21 | + id: check |
| 22 | + shell: bash |
| 23 | + run: | |
| 24 | + current_time=$(date -d "${{ github.event.workflow_run.created_at }}" +%s) |
| 25 | + current_hour=$(date -d "${{ github.event.workflow_run.created_at }}" +%H) |
| 26 | + current_status="${{ github.event.workflow_run.conclusion }}" |
| 27 | +
|
| 28 | + last_workflow_run=$(gh run list \ |
| 29 | + --status completed \ |
| 30 | + --limit 1 \ |
| 31 | + --event ${{ github.event.workflow_run.event }} \ |
| 32 | + --workflow ${{ github.event.workflow_run.name }} \ |
| 33 | + --json conclusion,createdAt \ |
| 34 | + --jq '.[0]' |
| 35 | + ) |
| 36 | + last_time=$(echo "$last_workflow_run" | jq -r '.createdAt' | date -d -%s) |
| 37 | + last_status=$(echo "$last_workflow_run" | jq -r '.conclusion') |
| 38 | +
|
| 39 | + result="skip" |
| 40 | + # If the current workflow is failing, notify failure |
| 41 | + if [[ "$current_status" == "failure" ]]; then |
| 42 | + result="failure" |
| 43 | + # If the current workflow is success... |
| 44 | + elif [[ "$current_status" == "success" ]]; then |
| 45 | + # if the last workflow was a failure, notify recovery |
| 46 | + if [[ "$last_status" == "failure" ]]; then |
| 47 | + result="recovery" |
| 48 | + # if the last notification was >24 hours ago and the current hour is 11, notify normal |
| 49 | + elif [[ "$(current_time - last_time)" -gt 86400 && "$current_hour" == 11 ]]; then |
| 50 | + result="normal" |
| 51 | + fi |
| 52 | + fi |
| 53 | +
|
| 54 | + echo "result=${result}" >> $GITHUB_OUTPUT |
| 55 | + cat $GITHUB_OUTPUT |
| 56 | +
|
| 57 | + - name: Create message blocks |
| 58 | + if: steps.check.outputs.result != 'skip' |
| 59 | + id: blocks |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + # Create the message blocks file |
| 63 | + health_check_blocks_file="health_check_blocks.json" |
| 64 | + ./scripts/health_check_blocks.py \ |
| 65 | + --input ${{ vars.health_check_file }} \ |
| 66 | + --output $health_check_blocks_file |
| 67 | + # Multiline output needs to use a delimiter to be passed to |
| 68 | + # the GITHUB_OUTPUT file. |
| 69 | + blocks=$(cat $health_check_blocks_file) |
| 70 | + echo "blocks<<EOF"$'\n'$blocks$'\n'EOF >> $GITHUB_OUTPUT |
| 71 | + cat $GITHUB_OUTPUT |
| 72 | +
|
| 73 | + - uses: mozilla/addons/.github/actions/slack@main |
| 74 | + if: steps.check.outputs.result == 'true' |
| 75 | + with: |
| 76 | + slack_token: ${{ secrets.SLACK_TOKEN }} |
| 77 | + payload: | |
| 78 | + { |
| 79 | + "channel": "${{ secrets.SLACK_ADDONS_PRODUCTION_CHANNEL }}", |
| 80 | + "blocks": ${{ toJson(steps.blocks.outputs.blocks) }}, |
| 81 | + # Don't unfurl links or media |
| 82 | + "unfurl_links": false, |
| 83 | + "unfurl_media": false, |
| 84 | + } |
| 85 | +
|
| 86 | +
|
| 87 | +
|
0 commit comments