-
Notifications
You must be signed in to change notification settings - Fork 39
262 lines (251 loc) · 9.51 KB
/
Copy pathpublish-packages.yml
File metadata and controls
262 lines (251 loc) · 9.51 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
name: Publish AtomicMemory Packages
# Only ops-orchestrated releases. The local publish-monorepo-packages
# script repository-dispatches `atomicmemory-package-release` with the
# release manifest as the client_payload.
#
# `run-name` surfaces the manifest's `correlation_id` so the ops side can
# locate the exact run it dispatched (by token, not by timestamp).
run-name: >-
Publish ${{ github.event.client_payload.public_sha }}
[${{ github.event.client_payload.correlation_id }}]
on:
repository_dispatch:
types:
- atomicmemory-package-release
permissions:
contents: read
concurrency:
group: publish-packages-${{ github.event.client_payload.public_sha }}
cancel-in-progress: false
env:
NODE_VERSION: "22"
PNPM_VERSION: "9.15.4"
defaults:
run:
shell: bash
jobs:
manifest:
name: parse release manifest
runs-on: ubuntu-24.04
timeout-minutes: 5
outputs:
manifest_json: ${{ steps.parse.outputs.manifest_json }}
public_sha: ${{ steps.parse.outputs.public_sha }}
publish: ${{ steps.parse.outputs.publish }}
core_selected: ${{ steps.parse.outputs.core_selected }}
core_version: ${{ steps.parse.outputs.core_version }}
selected_summary: ${{ steps.parse.outputs.selected_summary }}
steps:
- name: Parse and validate client_payload
id: parse
env:
MANIFEST: ${{ toJSON(github.event.client_payload) }}
run: |
set -euo pipefail
schema="$(jq -r '.schema_version' <<<"${MANIFEST}")"
if [[ "${schema}" != "1" ]]; then
echo "::error::Unsupported manifest schema_version='${schema}'."
exit 1
fi
public_sha="$(jq -r '.public_sha' <<<"${MANIFEST}")"
if [[ -z "${public_sha}" || "${public_sha}" == "null" ]]; then
echo "::error::Manifest is missing public_sha."
exit 1
fi
correlation_id="$(jq -r '.correlation_id' <<<"${MANIFEST}")"
if [[ -z "${correlation_id}" || "${correlation_id}" == "null" ]]; then
echo "::error::Manifest is missing correlation_id."
exit 1
fi
publish="$(jq -r '.publish // false' <<<"${MANIFEST}")"
core_version="$(jq -r '.selected_targets[]? | select(.registry=="npm" and .id=="core") | .version' <<<"${MANIFEST}")"
core_selected="false"
if [[ -n "${core_version}" ]]; then
core_selected="true"
fi
summary="$(jq -r '.selected_targets[] | "- " + .registry + " " + .name + "@" + .version' <<<"${MANIFEST}")"
{
echo "manifest_json<<EOF_MANIFEST"
echo "${MANIFEST}"
echo "EOF_MANIFEST"
} >>"${GITHUB_OUTPUT}"
{
echo "public_sha=${public_sha}"
echo "publish=${publish}"
echo "core_selected=${core_selected}"
echo "core_version=${core_version}"
} >>"${GITHUB_OUTPUT}"
{
echo "selected_summary<<EOF_SUMMARY"
echo "${summary}"
echo "EOF_SUMMARY"
} >>"${GITHUB_OUTPUT}"
{
echo "### Release manifest"
echo ""
echo "- public_sha: \`${public_sha}\`"
echo "- publish: \`${publish}\`"
echo "- selected:"
echo ""
echo "${summary}"
} >>"${GITHUB_STEP_SUMMARY}"
preflight:
name: preflight (pack-dry-run)
needs: manifest
runs-on: ubuntu-24.04
timeout-minutes: 30
env:
MANIFEST_JSON: ${{ needs.manifest.outputs.manifest_json }}
PUBLIC_SHA: ${{ needs.manifest.outputs.public_sha }}
steps:
- name: Checkout public_sha
uses: actions/checkout@v4
with:
ref: ${{ needs.manifest.outputs.public_sha }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup pnpm
run: |
corepack enable
corepack prepare pnpm@${PNPM_VERSION} --activate
- name: Verify checked-out package versions match manifest
run: |
set -euo pipefail
while IFS=$'\t' read -r name version path registry; do
if [[ "${registry}" != "npm" ]]; then
continue
fi
actual="$(node -p "require('./${path}/package.json').version")"
if [[ "${actual}" != "${version}" ]]; then
echo "::error::${path}/package.json is ${actual}, manifest says ${version}"
exit 1
fi
echo "ok: ${name}@${version} at ${path}"
done < <(jq -r '.selected_targets[] | [.name,.version,.path,.registry] | @tsv' <<<"${MANIFEST_JSON}")
- name: pnpm install
run: pnpm install --frozen-lockfile --ignore-scripts
- name: pnpm build
run: pnpm run build
- name: pnpm typecheck
run: pnpm run typecheck
- name: pnpm test (excluding core db tests)
run: pnpm run test
- name: Package metadata
run: pnpm run package-metadata
- name: pack-dry-run for the whole workspace
run: pnpm run pack-dry-run
- name: per-selected-package npm pack --dry-run
run: |
set -euo pipefail
while IFS=$'\t' read -r name version path registry; do
if [[ "${registry}" != "npm" ]]; then
continue
fi
echo "::group::npm pack --dry-run ${name}@${version}"
(cd "${path}" && npm pack --dry-run --json)
echo "::endgroup::"
done < <(jq -r '.selected_targets[] | [.name,.version,.path,.registry] | @tsv' <<<"${MANIFEST_JSON}")
publish-npm:
name: publish npm (Trusted Publishing)
needs: [manifest, preflight]
if: needs.manifest.outputs.publish == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 30
environment: npm-release
permissions:
contents: read
id-token: write
env:
MANIFEST_JSON: ${{ needs.manifest.outputs.manifest_json }}
PUBLIC_SHA: ${{ needs.manifest.outputs.public_sha }}
ATOMICMEMORY_RELEASE_WORKFLOW: publish-packages
steps:
- name: Checkout public_sha
uses: actions/checkout@v4
with:
ref: ${{ needs.manifest.outputs.public_sha }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: "https://registry.npmjs.org/"
- name: Setup pnpm
run: |
corepack enable
corepack prepare pnpm@${PNPM_VERSION} --activate
- name: Require npm >= 11.5.1 for Trusted Publishing
run: |
set -euo pipefail
npm install -g npm@latest
npm --version
- name: Install dependencies and build
run: |
set -euo pipefail
pnpm install --frozen-lockfile --ignore-scripts
pnpm run build
- name: Write release manifest to disk
id: manifest_file
run: |
set -euo pipefail
path="${RUNNER_TEMP}/atomicmemory-release-manifest.json"
printf '%s' "${MANIFEST_JSON}" >"${path}"
echo "path=${path}" >>"${GITHUB_OUTPUT}"
- name: Publish selected npm packages
env:
ATOMICMEMORY_RELEASE_MANIFEST: ${{ steps.manifest_file.outputs.path }}
run: |
set -euo pipefail
while IFS=$'\t' read -r name version path registry; do
if [[ "${registry}" != "npm" ]]; then
continue
fi
echo "::group::npm publish ${name}@${version}"
(cd "${path}" && npm publish --access public)
echo "::endgroup::"
done < <(jq -r '.selected_targets[] | [.name,.version,.path,.registry] | @tsv' <<<"${MANIFEST_JSON}")
verify-npm:
name: verify npm registry visibility
needs: [manifest, publish-npm]
if: needs.manifest.outputs.publish == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 15
env:
MANIFEST_JSON: ${{ needs.manifest.outputs.manifest_json }}
PUBLIC_SHA: ${{ needs.manifest.outputs.public_sha }}
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Verify each selected npm package is visible and pinned to public_sha
run: |
set -euo pipefail
while IFS=$'\t' read -r name version path registry; do
if [[ "${registry}" != "npm" ]]; then
continue
fi
metadata="$(npm view "${name}@${version}" version gitHead --json)"
actual_version="$(jq -r '.version' <<<"${metadata}")"
actual_head="$(jq -r '.gitHead' <<<"${metadata}")"
if [[ "${actual_version}" != "${version}" ]]; then
echo "::error::${name}@${version} npm view returned version=${actual_version}"
exit 1
fi
if [[ "${actual_head}" != "${PUBLIC_SHA}" ]]; then
echo "::error::${name}@${version} npm gitHead=${actual_head}, manifest public_sha=${PUBLIC_SHA}"
exit 1
fi
echo "verified ${name}@${version} (gitHead=${actual_head})"
done < <(jq -r '.selected_targets[] | [.name,.version,.path,.registry] | @tsv' <<<"${MANIFEST_JSON}")
publish-core-docker:
name: publish Core Docker image
needs: [manifest, verify-npm]
if: needs.manifest.outputs.publish == 'true' && needs.manifest.outputs.core_selected == 'true'
uses: ./.github/workflows/publish-core-docker.yml
permissions:
contents: read
packages: write
with:
core_version: ${{ needs.manifest.outputs.core_version }}