Skip to content

Commit e14afbe

Browse files
committed
ci: post end-of-run Slack notices from their own job
A failed Slack post now fails only the notify job, not the deploy or publish job or its GitHub deployment, and "Re-run failed jobs" re-posts without running the work again. Start notices stay in the work jobs.
1 parent 2a441c8 commit e14afbe

3 files changed

Lines changed: 61 additions & 33 deletions

File tree

‎.github/workflows/publish-dev-to-pypi.yml‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,18 @@ jobs:
124124
# version should be a no-op, not a red build.
125125
skip-existing: true
126126

127-
# Before the success notice, so a failed success post cannot trigger it.
127+
# End-of-run notices run in their own job: a failed Slack post fails only this
128+
# job, not the publish or its GitHub deployment, and "Re-run failed jobs"
129+
# re-posts without publishing again.
130+
notify:
131+
name: Notify Slack
132+
needs: [build, publish-dev]
133+
if: ${{ !cancelled() && vars.SLACK_CHANNEL_ID != '' && contains(fromJSON('["success", "failure"]'), needs.publish-dev.result) }}
134+
runs-on: ubuntu-latest
135+
136+
steps:
128137
- name: Notify Slack (failure)
129-
if: ${{ failure() && vars.SLACK_CHANNEL_ID != '' }}
138+
if: ${{ needs.publish-dev.result == 'failure' }}
130139
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
131140
with:
132141
method: chat.postMessage
@@ -141,7 +150,7 @@ jobs:
141150
# Spell out the --pre install: a plain "pip install codeplain" will
142151
# NOT pick this up, which otherwise reads as a broken publish.
143152
- name: Notify Slack (success)
144-
if: ${{ success() && vars.SLACK_CHANNEL_ID != '' }}
153+
if: ${{ needs.publish-dev.result == 'success' }}
145154
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
146155
with:
147156
method: chat.postMessage

‎.github/workflows/publish-install-script.yml‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- name: Short SHA for Slack
19-
run: echo "SHORT_SHA=${GITHUB_SHA:0:7}" >> "$GITHUB_ENV"
20-
2118
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2219

2320
- name: Upload install scripts to R2
@@ -57,9 +54,21 @@ jobs:
5754
--content-type "text/plain"
5855
echo "✓ examples.ps1 uploaded to R2"
5956
60-
# Before the success notice, so a failed success post cannot trigger it.
57+
# End-of-run notices run in their own job: a failed Slack post fails only this
58+
# job, and "Re-run failed jobs" re-posts without uploading again.
59+
notify:
60+
name: Notify Slack
61+
needs: publish
62+
if: ${{ !cancelled() && vars.SLACK_CHANNEL_ID != '' }}
63+
runs-on: ubuntu-latest
64+
permissions: {}
65+
66+
steps:
67+
- name: Short SHA
68+
run: echo "SHORT_SHA=${GITHUB_SHA:0:7}" >> "$GITHUB_ENV"
69+
6170
- name: Notify Slack (failure)
62-
if: ${{ failure() && vars.SLACK_CHANNEL_ID != '' }}
71+
if: ${{ needs.publish.result == 'failure' }}
6372
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
6473
with:
6574
method: chat.postMessage
@@ -73,7 +82,7 @@ jobs:
7382
See <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|the run log>.
7483
7584
- name: Notify Slack (success)
76-
if: ${{ success() && vars.SLACK_CHANNEL_ID != '' }}
85+
if: ${{ needs.publish.result == 'success' }}
7786
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
7887
with:
7988
method: chat.postMessage

‎.github/workflows/publish-to-pypi.yml‎

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,6 @@ jobs:
6262
run: |
6363
gh release upload ${{ github.ref_name }} dist/* --clobber
6464
65-
- name: Notify Slack (build failure)
66-
if: ${{ failure() && vars.SLACK_CHANNEL_ID != '' }}
67-
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
68-
with:
69-
method: chat.postMessage
70-
token: ${{ secrets.SLACK_BOT_TOKEN }}
71-
errors: true
72-
payload: |
73-
channel: ${{ vars.SLACK_CHANNEL_ID }}
74-
text: >-
75-
*Codeplain Client*: Build of `${{ github.ref_name }}` FAILED :x:. Nothing was published to PyPI.
76-
See <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|the run log>.
77-
7865
publish-to-pypi:
7966
name: Publish to PyPI
8067
needs: build
@@ -88,13 +75,6 @@ jobs:
8875
id-token: write
8976

9077
steps:
91-
# The tag (v0.4.0rc1) without its "v", for the install command in Slack.
92-
- name: Version from tag
93-
id: version
94-
env:
95-
TAG: ${{ github.ref_name }}
96-
run: echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
97-
9878
- name: Download distribution packages
9979
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
10080
with:
@@ -104,9 +84,31 @@ jobs:
10484
- name: Publish to PyPI
10585
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # release/v1
10686

107-
# Before the success notice, so a failed success post cannot trigger it.
87+
# End-of-run notices run in their own job: a failed Slack post fails only this
88+
# job, not the publish or its GitHub deployment, and "Re-run failed jobs"
89+
# re-posts without publishing again.
90+
notify:
91+
name: Notify Slack
92+
needs: [build, publish-to-pypi]
93+
if: ${{ !cancelled() && vars.SLACK_CHANNEL_ID != '' }}
94+
runs-on: ubuntu-latest
95+
96+
steps:
97+
- name: Notify Slack (build failure)
98+
if: ${{ needs.build.result == 'failure' }}
99+
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
100+
with:
101+
method: chat.postMessage
102+
token: ${{ secrets.SLACK_BOT_TOKEN }}
103+
errors: true
104+
payload: |
105+
channel: ${{ vars.SLACK_CHANNEL_ID }}
106+
text: >-
107+
*Codeplain Client*: Build of `${{ github.ref_name }}` FAILED :x:. Nothing was published to PyPI.
108+
See <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|the run log>.
109+
108110
- name: Notify Slack (failure)
109-
if: ${{ failure() && vars.SLACK_CHANNEL_ID != '' }}
111+
if: ${{ needs.publish-to-pypi.result == 'failure' }}
110112
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
111113
with:
112114
method: chat.postMessage
@@ -118,12 +120,20 @@ jobs:
118120
*Codeplain Client*: Publishing `${{ github.ref_name }}` to PyPI FAILED :x:.
119121
See <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|the run log>.
120122
123+
# The tag (v0.4.0rc1) without its "v", for the install command below.
124+
- name: Version from tag
125+
id: version
126+
if: ${{ needs.publish-to-pypi.result == 'success' }}
127+
env:
128+
TAG: ${{ github.ref_name }}
129+
run: echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
130+
121131
# GitHub marks the release itself as a pre-release; the tag (v0.4.0rc1)
122132
# carries the same intent for PEP 440. pip and uv skip pre-releases by
123133
# default, so "--upgrade" would NOT pick one up. Tell people the command
124134
# that actually works.
125135
- name: Notify Slack (pre-release published)
126-
if: ${{ success() && github.event.release.prerelease && vars.SLACK_CHANNEL_ID != '' }}
136+
if: ${{ needs.publish-to-pypi.result == 'success' && github.event.release.prerelease }}
127137
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
128138
with:
129139
method: chat.postMessage
@@ -136,7 +146,7 @@ jobs:
136146
Normal installs are unaffected — try it with `pip install --pre codeplain==${{ steps.version.outputs.version }}`.
137147
138148
- name: Notify Slack (release published)
139-
if: ${{ success() && !github.event.release.prerelease && vars.SLACK_CHANNEL_ID != '' }}
149+
if: ${{ needs.publish-to-pypi.result == 'success' && !github.event.release.prerelease }}
140150
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
141151
with:
142152
method: chat.postMessage

0 commit comments

Comments
 (0)