Skip to content

Commit 1b075ef

Browse files
committed
chore: add release back-sync trigger workflow
1 parent 8fbce67 commit 1b075ef

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Trigger staging back-sync on release
2+
3+
# On a published release, notify the staging repo to sync from production immediately.
4+
# This workflow is dispatch-only: it cannot write production or staging contents.
5+
on:
6+
release:
7+
types: [published]
8+
workflow_dispatch: {}
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
notify:
15+
runs-on: ubuntu-latest
16+
if: github.repository == 'sentdm/sent-dm-python'
17+
env:
18+
STAGING_REPO: sentdm/sent-dm-python-staging
19+
steps:
20+
- name: Dispatch back-sync to staging
21+
env:
22+
DISPATCH_TOKEN: ${{ secrets.STAGING_DISPATCH_TOKEN }}
23+
REF_NAME: ${{ github.ref_name }}
24+
run: |
25+
set -euo pipefail
26+
[ -n "${DISPATCH_TOKEN:-}" ] || { echo "STAGING_DISPATCH_TOKEN not set" >&2; exit 1; }
27+
payload=$(jq -n --arg ref "$REF_NAME" '{event_type:"prod-released",client_payload:{ref:$ref}}')
28+
code=$(curl -sS -o /tmp/dispatch.txt -w '%{http_code}' -X POST \
29+
-H "Authorization: Bearer ${DISPATCH_TOKEN}" \
30+
-H "Accept: application/vnd.github+json" \
31+
-H "X-GitHub-Api-Version: 2022-11-28" \
32+
"https://api.github.com/repos/${STAGING_REPO}/dispatches" \
33+
-d "$payload")
34+
if [ "$code" = "204" ]; then
35+
echo "Back-sync dispatched to ${STAGING_REPO}."
36+
else
37+
echo "Dispatch failed (HTTP $code)" >&2; cat /tmp/dispatch.txt >&2; exit 1
38+
fi

0 commit comments

Comments
 (0)