Repository navigation
224 lines (199 loc) · 9.76 KB
/
Copy pathupdate-connect-release.yml
File metadata and controls
224 lines (199 loc) · 9.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: Update Connect release
on:
repository_dispatch:
types: [connect-client-release-published]
workflow_dispatch:
inputs:
tag:
description: Published mdbase Connect release tag
required: true
type: string
permissions:
contents: read
concurrency:
group: connect-release-update
cancel-in-progress: false
jobs:
update:
name: Verify release and open pull request
runs-on: ubuntu-24.04
steps:
- name: Select release tag
id: release
env:
DISPATCH_TAG: ${{ github.event.client_payload.tag }}
MANUAL_TAG: ${{ inputs.tag }}
run: |
tag="${DISPATCH_TAG:-$MANUAL_TAG}"
if [[ ! "$tag" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then
echo "Invalid Connect release tag." >&2
exit 1
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "branch=automation/connect-release-$tag" >> "$GITHUB_OUTPUT"
- name: Check out website
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
persist-credentials: false
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
with:
version: 10
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 22
cache: pnpm
- name: Install cosign
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
- name: Install website dependencies
run: pnpm install --frozen-lockfile
- name: Verify public evidence and generate release record
env:
GH_TOKEN: ${{ github.token }}
MDBASE_RELEASE_NPM_ATTEMPTS: "15"
MDBASE_RELEASE_NPM_DELAY_MS: "60000"
run: node scripts/update-connect-release.mjs '${{ steps.release.outputs.tag }}'
# Read after the release record, which moves the Connect ref to the tag.
- name: Read pinned source identities
id: sources
run: |
echo "spec_repository=$(jq -r '.specification.repository' site-sources.json)" >> "$GITHUB_OUTPUT"
echo "spec_ref=$(jq -r '.specification.ref' site-sources.json)" >> "$GITHUB_OUTPUT"
echo "connect_repository=$(jq -r '.connect.repository' site-sources.json)" >> "$GITHUB_OUTPUT"
echo "connect_ref=$(jq -r '.connect.ref' site-sources.json)" >> "$GITHUB_OUTPUT"
echo "contracts_repository=$(jq -r '.contracts.repository' site-sources.json)" >> "$GITHUB_OUTPUT"
echo "contracts_ref=$(jq -r '.contracts.ref' site-sources.json)" >> "$GITHUB_OUTPUT"
echo "rust_repository=$(jq -r '.implementations[] | select(.id == "rust") | .repository' site-sources.json)" >> "$GITHUB_OUTPUT"
echo "rust_ref=$(jq -r '.implementations[] | select(.id == "rust") | .ref' site-sources.json)" >> "$GITHUB_OUTPUT"
echo "typescript_repository=$(jq -r '.implementations[] | select(.id == "typescript") | .repository' site-sources.json)" >> "$GITHUB_OUTPUT"
echo "typescript_ref=$(jq -r '.implementations[] | select(.id == "typescript") | .ref' site-sources.json)" >> "$GITHUB_OUTPUT"
- name: Check out specification
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ steps.sources.outputs.spec_repository }}
ref: ${{ steps.sources.outputs.spec_ref }}
path: .sources/mdbase-spec
persist-credentials: false
- name: Check out Connect
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ steps.sources.outputs.connect_repository }}
ref: ${{ steps.sources.outputs.connect_ref }}
path: .sources/mdbase-connect
persist-credentials: false
- name: Check out contracts
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ steps.sources.outputs.contracts_repository }}
ref: ${{ steps.sources.outputs.contracts_ref }}
path: .sources/mdbase-contracts
persist-credentials: false
- name: Check out Rust implementation
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ steps.sources.outputs.rust_repository }}
ref: ${{ steps.sources.outputs.rust_ref }}
path: .sources/mdbase-rs
persist-credentials: false
- name: Check out TypeScript implementation
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ steps.sources.outputs.typescript_repository }}
ref: ${{ steps.sources.outputs.typescript_ref }}
path: .sources/mdbase
persist-credentials: false
- name: Build contract catalog
working-directory: .sources/mdbase-contracts
run: npm ci && npm run build
- name: Build specification artifact
working-directory: .sources/mdbase-spec/site
run: npm ci && npm run build
- name: Build the MCP server for the tool reference
working-directory: .sources/mdbase-connect
run: |
pnpm_version="$(jq -r '.packageManager | sub("^pnpm@"; "")' package.json)"
npx --yes "pnpm@$pnpm_version" install --frozen-lockfile --filter "@mdbase/connect-mcp..."
npx --yes "pnpm@$pnpm_version" --filter "@mdbase/connect-mcp..." build
- name: Synchronize schemas, contracts, and conformance claims
run: pnpm sync:sources
env:
MDBASE_SPEC_DIR: .sources/mdbase-spec
MDBASE_CONNECT_DIR: .sources/mdbase-connect
MDBASE_CONTRACTS_DIR: .sources/mdbase-contracts
MDBASE_RS_DIR: .sources/mdbase-rs
MDBASE_TS_DIR: .sources/mdbase
- name: Validate generated website
env:
GH_TOKEN: ${{ github.token }}
MDBASE_SPEC_DIR: .sources/mdbase-spec
run: pnpm test
- name: Require a release-only change
id: changes
run: |
mapfile -t changed < <(git diff --name-only)
if [ "${#changed[@]}" -eq 0 ]; then
echo "present=false" >> "$GITHUB_OUTPUT"
exit 0
fi
printf '%s\n' "${changed[@]}" | sort > "$RUNNER_TEMP/changed"
printf '%s\n' site-sources.json src/data/connect-release.json | sort > "$RUNNER_TEMP/expected"
diff -u "$RUNNER_TEMP/expected" "$RUNNER_TEMP/changed"
echo "present=true" >> "$GITHUB_OUTPUT"
- name: Create website automation token
if: steps.changes.outputs.present == 'true'
id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ vars.RELEASE_AUTOMATION_CLIENT_ID }}
private-key: ${{ secrets.RELEASE_AUTOMATION_APP_PRIVATE_KEY }}
owner: mdbase-dev
repositories: mdbase.dev
permission-contents: write
permission-pull-requests: write
- name: Open release update pull request
if: steps.changes.outputs.present == 'true'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
BRANCH: ${{ steps.release.outputs.branch }}
TAG: ${{ steps.release.outputs.tag }}
run: |
existing="$(gh pr list --repo "$GITHUB_REPOSITORY" --state all --head "$BRANCH" --json url,state --jq '.[0] // empty')"
if [ -n "$existing" ]; then
state="$(jq -r .state <<<"$existing")"
url="$(jq -r .url <<<"$existing")"
if [ "$state" = "OPEN" ] || [ "$state" = "MERGED" ]; then
echo "Release update already represented by $url"
exit 0
fi
echo "The deterministic release PR was closed without merging: $url" >&2
exit 1
fi
if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
echo "Remote branch $BRANCH exists without a pull request; refusing to overwrite it." >&2
exit 1
fi
git switch -c "$BRANCH"
git config user.name "mdbase release automation[bot]"
git config user.email "mdbase-release-automation[bot]@users.noreply.github.com"
git add site-sources.json src/data/connect-release.json
git commit -m "Update Connect downloads to $TAG"
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git push --set-upstream origin "$BRANCH"
url="$(gh pr create \
--repo "$GITHUB_REPOSITORY" \
--base main \
--head "$BRANCH" \
--title "Update Connect downloads to $TAG" \
--body "Updates the Downloads release record from the published, Sigstore-verified mdbase Connect channel for [$TAG](https://github.com/mdbase-dev/mdbase-connect/releases/tag/$TAG).\n\nThe website release checks and full test suite passed before this PR was opened.")"
echo "Opened $url"
# An open update for an older release can only be merged over this
# one, so close it. Newer releases' updates are never touched.
prefix=automation/connect-release-
gh pr list --repo "$GITHUB_REPOSITORY" --state open --json number,headRefName \
--jq ".[] | select(.headRefName | startswith(\"$prefix\")) | \"\\(.number) \\(.headRefName)\"" |
while read -r number head; do
older="${head#"$prefix"}"
[ "$older" != "$TAG" ] || continue
[ "$(printf '%s\n%s\n' "${older#v}" "${TAG#v}" | sort -V | head -1)" = "${older#v}" ] || continue
gh pr close "$number" --repo "$GITHUB_REPOSITORY" --delete-branch --comment "Superseded by $url."
done