Skip to content

Commit 4c29ec4

Browse files
KevinMindCopilot
andauthored
Make sure _health_check.yml can run on fork PRs by only attempting a slack notification if the channel is defined. (#23716)
* Only attempt slack notification in _health_check.yml workflow if it is defined (it is not defined on forks which now causes PRs to break CI) * Update .github/workflows/_health_check.yml Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 2fb8a91 commit 4c29ec4

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

.github/workflows/_health_check.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ on:
1717
description: Whether to notify the user of the health check outcome
1818
type: boolean
1919
required: false
20+
slack_channel:
21+
description: The Slack channel to send notifications to
22+
type: string
23+
required: false
2024
secrets:
2125
SLACK_TOKEN:
2226
description: The Slack token to use for notifications
@@ -37,6 +41,10 @@ on:
3741
description: Whether to notify the user of the health check outcome
3842
type: boolean
3943
required: false
44+
slack_channel:
45+
description: The Slack channel to send notifications to
46+
type: string
47+
required: false
4048

4149
env:
4250
health_check_file: health_check.json
@@ -46,6 +54,7 @@ jobs:
4654
context:
4755
runs-on: ubuntu-latest
4856
outputs:
57+
slack_channel: ${{ steps.environment.outputs.slack_channel }}
4958
notify: ${{ steps.environment.outputs.notify }}
5059
environment: ${{ steps.environment.outputs.environment }}
5160

@@ -55,6 +64,7 @@ jobs:
5564
env:
5665
notify: ${{ inputs.notify }}
5766
environment: ${{ inputs.environment }}
67+
slack_channel: ${{ inputs.slack_channel }}
5868
run: |
5969
if [[ "$environment" == "prod" ]]; then
6070
environment="prod"
@@ -66,8 +76,11 @@ jobs:
6676
environment="host"
6777
fi
6878
69-
echo "notify=$notify" >> "$GITHUB_OUTPUT"
70-
echo "environment=$environment" >> "$GITHUB_OUTPUT"
79+
{
80+
echo "notify=$notify"
81+
echo "slack_channel=$slack_channel"
82+
echo "environment=$environment"
83+
} >> "$GITHUB_OUTPUT"
7184
cat "$GITHUB_OUTPUT"
7285
7386
health_check:
@@ -125,13 +138,13 @@ jobs:
125138
cat "$GITHUB_OUTPUT"
126139
127140
- name: Notify Failure
128-
if: steps.blocks.outcome == 'success'
141+
if: steps.blocks.outcome == 'success' && needs.context.outputs.slack_channel != ''
129142
uses: mozilla/addons/.github/actions/slack@aa3c320008a837a8faa40badb88006421f63efdb
130143
with:
131144
slack_token: ${{ secrets.SLACK_TOKEN }}
132145
payload: |
133146
{
134-
"channel": "${{ vars.SLACK_ADDONS_PRODUCTION_CHANNEL }}",
147+
"channel": "${{ needs.context.outputs.slack_channel }}",
135148
"blocks": ${{ toJson(steps.blocks.outputs.blocks) }},
136149
"text": "[${{ needs.context.outputs.environment }}] Health check ${{ steps.health_check.outcome }}",
137150
# Don't unfurl links or media

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ jobs:
234234
uses: ./.github/workflows/_health_check.yml
235235
with:
236236
environment: host
237+
slack_channel: ${{ vars.SLACK_ADDONS_PRODUCTION_CHANNEL }}
237238

238239
test:
239240
needs: build
@@ -326,7 +327,7 @@ jobs:
326327
notification:
327328
runs-on: ubuntu-latest
328329
name: Notification (${{ matrix.name }})
329-
if: always()
330+
if: needs.context.outputs.is_fork == 'false' && always()
330331
needs: [context, push_dockerhub, push_gar]
331332
strategy:
332333
matrix:

.github/workflows/health_check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
with:
4343
environment: ${{ matrix.environment }}
4444
notify: ${{ github.event_name == 'schedule' }}
45+
slack_channel: ${{ vars.SLACK_ADDONS_PRODUCTION_CHANNEL }}
4546

4647
post_health_check:
4748
if: always()

0 commit comments

Comments
 (0)