Skip to content

Commit 9cb237c

Browse files
authored
ci(publish): post to #deploy on PyPI publish (#115)
* ci(publish): post to #deploy on PyPI publish * ci(publish): log Slack error on notify failure
1 parent 6790ab1 commit 9cb237c

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,33 @@ jobs:
6767

6868
- name: Publish via Trusted Publishing
6969
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
70+
71+
# Announce the release in #deploy. Runs only when the publish above
72+
# succeeded. Posts via the shared Hotdata CI Slack app (bot token), so the
73+
# same SLACK_CI_BOT_TOKEN org secret drives notifications across SDK repos.
74+
- name: "Notify #deploy on Slack"
75+
# The publish above is irreversible, so a Slack/token hiccup must not
76+
# mark a successful release as failed and trigger false-alarm retries.
77+
continue-on-error: true
78+
env:
79+
SLACK_CI_BOT_TOKEN: ${{ secrets.SLACK_CI_BOT_TOKEN }}
80+
run: |
81+
set -euo pipefail
82+
if [ -z "${SLACK_CI_BOT_TOKEN:-}" ]; then
83+
echo "SLACK_CI_BOT_TOKEN not set; skipping Slack notification" >&2
84+
exit 0
85+
fi
86+
version="${GITHUB_REF_NAME#v}"
87+
text=":package: *hotdata* \`v${version}\` published to PyPI — <https://pypi.org/project/hotdata/${version}/|PyPI> · <https://github.com/${GITHUB_REPOSITORY}/releases/tag/${GITHUB_REF_NAME}|release notes>"
88+
# #deploy channel ID (rename-proof). chat.postMessage returns HTTP 200
89+
# even on logical errors, so capture the body and assert on .ok —
90+
# echoing Slack's error makes a swallowed (continue-on-error) miss
91+
# debuggable in the job log instead of disappearing silently.
92+
response="$(curl -sS -X POST https://slack.com/api/chat.postMessage \
93+
-H "Authorization: Bearer ${SLACK_CI_BOT_TOKEN}" \
94+
-H 'Content-Type: application/json; charset=utf-8' \
95+
--data "$(jq -n --arg ch 'C0ARK84E1D4' --arg text "$text" '{channel:$ch, text:$text}')")"
96+
if ! jq -e '.ok' >/dev/null <<<"$response"; then
97+
echo "Slack notification failed: $(jq -r '.error // "unknown"' <<<"$response")" >&2
98+
exit 1
99+
fi

0 commit comments

Comments
 (0)