|
1
|
name: Notify Release Published |
|
2
|
|
|
3
|
on: |
|
4
|
release: |
|
5
|
types: [published] |
|
6
|
workflow_dispatch: |
|
7
|
inputs: |
|
8
|
tag: |
|
9
|
description: "Release tag to announce as published (e.g. v2.21.1)" |
|
10
|
required: true |
|
11
|
type: string |
|
12
|
|
|
13
|
concurrency: |
|
14
|
group: notify-release-published |
|
15
|
cancel-in-progress: false |
|
16
|
|
|
17
|
jobs: |
|
18
|
notify: |
|
19
|
name: Notify ${{ matrix.repo }} |
|
20
|
runs-on: ubuntu-latest |
|
21
|
strategy: |
|
22
|
fail-fast: false |
|
23
|
matrix: |
|
24
|
repo: |
|
25
|
- medusa-mcp |
|
26
|
steps: |
|
27
|
- name: Resolve the release |
|
28
|
id: release |
|
29
|
env: |
|
30
|
GH_TOKEN: ${{ github.token }} |
|
31
|
REPO: ${{ github.repository }} |
|
32
|
INPUT_TAG: ${{ github.event.inputs.tag }} |
|
33
|
run: | |
|
34
|
set -euo pipefail |
|
35
|
|
|
36
|
if [ -n "${INPUT_TAG:-}" ]; then |
|
37
|
gh release view "$INPUT_TAG" --repo "$REPO" \ |
|
38
|
--json tagName,url,publishedAt,isDraft > /tmp/release.json |
|
39
|
else |
|
40
|
jq -n \ |
|
41
|
--arg tagName "${{ github.event.release.tag_name }}" \ |
|
42
|
--arg url "${{ github.event.release.html_url }}" \ |
|
43
|
--arg publishedAt "${{ github.event.release.published_at }}" \ |
|
44
|
--argjson isDraft ${{ github.event.release.draft }} \ |
|
45
|
'{tagName: $tagName, url: $url, publishedAt: $publishedAt, isDraft: $isDraft}' \ |
|
46
|
> /tmp/release.json |
|
47
|
fi |
|
48
|
|
|
49
|
node --input-type=module << 'EOF' |
|
50
|
import { readFileSync, appendFileSync } from "fs" |
|
51
|
|
|
52
|
const release = JSON.parse(readFileSync("/tmp/release.json", "utf8")) |
|
53
|
const out = (key, value) => |
|
54
|
appendFileSync(process.env.GITHUB_OUTPUT, `${key}=${value}\n`) |
|
55
|
|
|
56
|
// Snapshots (`preview`, `next`, `canary`, …) do not clear anything: |
|
57
|
// the upcoming items are still upcoming. Neither do drafts — nothing |
|
58
|
// is out until the release is actually published. |
|
59
|
const version = release.tagName?.replace(/^v/, "") ?? "" |
|
60
|
const isStable = /^\d+\.\d+\.\d+$/.test(version) |
|
61
|
|
|
62
|
if (release.isDraft || !isStable) { |
|
63
|
console.log(`Skipping ${release.tagName}: not a published stable release.`) |
|
64
|
out("should_notify", "false") |
|
65
|
process.exit(0) |
|
66
|
} |
|
67
|
|
|
68
|
out("should_notify", "true") |
|
69
|
out("version", version) |
|
70
|
out("tag", release.tagName) |
|
71
|
out("url", release.url ?? "") |
|
72
|
out("published_at", release.publishedAt ?? "") |
|
73
|
console.log(`Announcing published release ${release.tagName}`) |
|
74
|
EOF |
|
75
|
|
|
76
|
- name: Generate GitHub App token |
|
77
|
if: steps.release.outputs.should_notify == 'true' |
|
78
|
id: app-token |
|
79
|
uses: actions/create-github-app-token@v1 |
|
80
|
with: |
|
81
|
app-id: ${{ secrets.MEDUSA_APP_ID }} |
|
82
|
private-key: ${{ secrets.MEDUSA_APP_PRIVATE_KEY }} |
|
83
|
owner: ${{ github.repository_owner }} |
|
84
|
repositories: ${{ matrix.repo }} |
|
85
|
|
|
86
|
- name: Send repository dispatch |
|
87
|
if: steps.release.outputs.should_notify == 'true' |
|
88
|
env: |
|
89
|
# Needs the `Contents: write` repository permission. |
|
90
|
GH_TOKEN: ${{ steps.app-token.outputs.token }} |
|
91
|
TARGET_REPO: ${{ github.repository_owner }}/${{ matrix.repo }} |
|
92
|
run: | |
|
93
|
set -euo pipefail |
|
94
|
|
|
95
|
jq -n \ |
|
96
|
--arg repository "$GITHUB_REPOSITORY" \ |
|
97
|
--arg version "${{ steps.release.outputs.version }}" \ |
|
98
|
--arg tag "${{ steps.release.outputs.tag }}" \ |
|
99
|
--arg release_url "${{ steps.release.outputs.url }}" \ |
|
100
|
--arg published_at "${{ steps.release.outputs.published_at }}" \ |
|
101
|
'{ |
|
102
|
event_type: "medusa-release-published", |
|
103
|
client_payload: { |
|
104
|
repository: $repository, |
|
105
|
version: $version, |
|
106
|
tag: $tag, |
|
107
|
release_url: $release_url, |
|
108
|
published_at: $published_at |
|
109
|
} |
|
110
|
}' \ |
|
111
|
| gh api "repos/$TARGET_REPO/dispatches" --method POST --input - |
|
112
|
|
|
113
|
echo "Dispatched medusa-release-published (${{ steps.release.outputs.tag }}) to $TARGET_REPO" |