Repository navigation
332 lines (289 loc) · 13.5 KB
/
Copy pathsquad-promote.yml
File metadata and controls
332 lines (289 loc) · 13.5 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
name: Squad Promote
on:
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run - validate the sanitized merge without pushing main'
required: false
default: 'false'
type: choice
options: ['false', 'true']
promotion_branch:
description: 'Existing validated in-repository promotion branch to open as a bot-authored PR'
required: false
default: ''
type: string
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
actions: write
contents: write
jobs:
open-existing-promotion:
if: ${{ inputs.promotion_branch != '' }}
name: Open validated promotion PR
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Validate promotion branch input
env:
BRANCH: ${{ inputs.promotion_branch }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
if [[ ! "${BRANCH}" =~ ^chore/promote(-v)?-[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Promotion branch must match chore/promote-X.Y.Z or chore/promote-vX.Y.Z."
exit 1
fi
gh api "repos/${GITHUB_REPOSITORY}/git/ref/heads/${BRANCH}" --silent
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
with:
fetch-depth: 0
ref: ${{ inputs.promotion_branch }}
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 #v6
with:
node-version: 22
cache: 'npm'
- name: Validate existing promotion tree
id: validate
run: |
set -euo pipefail
git fetch origin '+refs/heads/main:refs/remotes/origin/main'
git merge-base --is-ancestor origin/main HEAD || {
echo "::error::Promotion branch must descend from the current main branch."
exit 1
}
forbidden="$(git ls-files | grep -E '^(\.(ai-team|squad|ai-team-templates)/|team-docs/|docs/proposals/)' || true)"
if [ -n "${forbidden}" ]; then
echo "::error::Forbidden internal files remain in the promotion branch:"
printf '%s\n' "${forbidden}"
exit 1
fi
changesets="$(git ls-files '.changeset/*.md' | grep -v '^.changeset/README.md$' || true)"
if [ -n "${changesets}" ]; then
echo "::error::Consumed changesets remain in the promotion branch:"
printf '%s\n' "${changesets}"
exit 1
fi
version="$(node -p 'require("./package.json").version')"
stable_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
if [[ ! "${version}" =~ ${stable_re} ]]; then
echo "::error::Stable promotion requires a MAJOR.MINOR.PATCH version, got '${version}'."
exit 1
fi
for manifest in packages/squad-sdk/package.json packages/squad-cli/package.json; do
package_version="$(node -p "require('./${manifest}').version")"
if [ "${package_version}" != "${version}" ]; then
echo "::error::${manifest} version '${package_version}' does not match root version '${version}'."
exit 1
fi
done
lock_root="$(node -p 'require("./package-lock.json").version')"
lock_sdk="$(node -p 'require("./package-lock.json").packages["packages/squad-sdk"].version')"
lock_cli="$(node -p 'require("./package-lock.json").packages["packages/squad-cli"].version')"
if [ "${lock_root}" != "${version}" ] || [ "${lock_sdk}" != "${version}" ] || [ "${lock_cli}" != "${version}" ]; then
echo "::error::package-lock.json package versions must all match '${version}'."
exit 1
fi
expected_sdk_dependency=">=${version}"
sdk_dependency="$(node -p "require('./packages/squad-cli/package.json').dependencies['@bradygaster/squad-sdk']")"
lock_dependency="$(node -p "require('./package-lock.json').packages['packages/squad-cli'].dependencies['@bradygaster/squad-sdk']")"
if [ "${sdk_dependency}" != "${expected_sdk_dependency}" ] || [ "${lock_dependency}" != "${expected_sdk_dependency}" ]; then
echo "::error::CLI SDK dependency floors must both be '${expected_sdk_dependency}'."
exit 1
fi
grep -Fq "## [${version}]" CHANGELOG.md || {
echo "::error::Version ${version} is missing from CHANGELOG.md."
exit 1
}
test -z "$(git status --porcelain)" || {
echo "::error::Promotion branch checkout is not clean."
git status --short
exit 1
}
echo "version=${version}" >> "$GITHUB_OUTPUT"
- name: Install dependencies
run: npm ci
- name: Build release tree
env:
SKIP_BUILD_BUMP: '1'
run: npm run build
- name: Run release tests
run: node --test test/*.test.cjs
- name: Verify validation did not mutate the branch
run: |
test -z "$(git status --porcelain)" || {
echo "::error::Build or tests modified the promotion branch."
git status --short
exit 1
}
- name: Open bot-authored promotion PR
if: inputs.dry_run == 'false'
env:
BRANCH: ${{ inputs.promotion_branch }}
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.validate.outputs.version }}
run: |
set -euo pipefail
existing_url="$(gh pr list \
--repo "${GITHUB_REPOSITORY}" \
--state open \
--base main \
--head "${BRANCH}" \
--json url \
--jq '.[0].url // ""')"
if [ -n "${existing_url}" ]; then
echo "Promotion PR already exists: ${existing_url}"
exit 0
fi
gh pr create \
--repo "${GITHUB_REPOSITORY}" \
--base main \
--head "${BRANCH}" \
--title "chore(release): promote dev to main (v${VERSION})" \
--body "Bot-authored promotion PR for validated Squad v${VERSION} release branch \`${BRANCH}\`.
Validation run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}
The repository's required pull-request checks may initially wait for a maintainer to approve workflow execution because this PR was created with \`GITHUB_TOKEN\`."
dev-to-main:
if: ${{ inputs.promotion_branch == '' }}
name: Promote sanitized dev to main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 #v6
with:
node-version: 22
cache: 'npm'
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Prepare sanitized stable promotion
id: prepare
run: |
set -euo pipefail
git fetch origin \
'+refs/heads/dev:refs/remotes/origin/dev' \
'+refs/heads/main:refs/remotes/origin/main' \
--tags
echo "=== dev HEAD ==="
git log origin/dev -1 --oneline
echo "=== main HEAD ==="
git log origin/main -1 --oneline
if git merge-base --is-ancestor origin/dev origin/main; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "main already contains dev; nothing to promote."
exit 0
fi
git checkout -B main origin/main
# -X no-renames: dev has many newly-added template/charter files that
# don't exist at the merge-base; without this, git's rename-detection
# heuristic falsely pairs them with unrelated files independently
# deleted on main, producing spurious rename/delete conflicts.
git merge origin/dev --no-commit --no-ff -X theirs -X no-renames || true
# Strip internal-only paths *before* checking for unresolved
# conflicts. These paths are always removed from the release tree
# regardless of merge outcome, so a delete(main)/modify(dev)
# conflict on them isn't a real decision — resolve it here so it
# doesn't block the dev-to-main promotion below.
git rm -rf --cached --ignore-unmatch \
.ai-team/ \
.squad/ \
.ai-team-templates/ \
team-docs/ \
docs/proposals/
# squad-preview.yml was intentionally removed on dev (83612744,
# "finalize preview and stable release channels", which consolidated
# preview/stable release logic into squad-release.yml) while main
# independently hardened it with SHA-pinned action refs before that
# redesign landed. Accept dev's removal; the equivalent
# functionality now lives in squad-release.yml.
git rm -f --cached --ignore-unmatch .github/workflows/squad-preview.yml
unmerged="$(git diff --name-only --diff-filter=U)"
if [ -n "$unmerged" ]; then
echo "::error::The dev-to-main merge left unresolved conflicts:"
printf '%s\n' "$unmerged"
exit 1
fi
forbidden="$(git ls-files | grep -E '^(\.(ai-team|squad|ai-team-templates)/|team-docs/|docs/proposals/)' || true)"
if [ -n "$forbidden" ]; then
echo "::error::Forbidden internal files remain in the release tree:"
printf '%s\n' "$forbidden"
exit 1
fi
version="$(node -p 'require("./package.json").version')"
stable_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
if [[ ! "$version" =~ $stable_re ]]; then
echo "::error::Stable promotion requires a MAJOR.MINOR.PATCH version, got '$version'."
exit 1
fi
for manifest in packages/squad-sdk/package.json packages/squad-cli/package.json; do
package_version="$(node -p "require('./${manifest}').version")"
if [ "$package_version" != "$version" ]; then
echo "::error::$manifest version '$package_version' does not match root version '$version'."
exit 1
fi
done
sdk_dependency="$(node -p "require('./packages/squad-cli/package.json').dependencies['@bradygaster/squad-sdk']")"
lock_dependency="$(node -p "require('./package-lock.json').packages['packages/squad-cli'].dependencies['@bradygaster/squad-sdk']")"
if [[ "$sdk_dependency" == *-* ]] || [[ "$lock_dependency" == *-* ]]; then
echo "::error::Stable promotion cannot retain a prerelease SDK dependency floor."
exit 1
fi
if ! grep -Fq "## [$version]" CHANGELOG.md; then
echo "::error::Version $version is missing from CHANGELOG.md."
exit 1
fi
# cr-at-eol: the repo deliberately keeps ~95 .ts files CRLF-encoded
# (see .gitattributes) to avoid a disruptive renormalization commit.
# Without this, --check flags every added line in those files as
# "trailing whitespace" merely for ending in \r\n, which would fail
# every promotion that touches them. This still catches genuine
# trailing spaces/tabs and blank-line-at-EOF issues.
git -c core.whitespace=cr-at-eol diff --cached --check
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Prepared sanitized stable release v$version."
git diff --cached --stat
- name: Install dependencies
if: steps.prepare.outputs.changed == 'true'
run: npm ci
- name: Build release tree
if: steps.prepare.outputs.changed == 'true'
# Internal .squad sources have already been removed from the release
# index, so avoid the root prebuild template synchronization.
run: npm -w packages/squad-sdk run build && npm -w packages/squad-cli run build
- name: Run release tests
if: steps.prepare.outputs.changed == 'true'
run: node --test test/*.test.cjs
- name: Push main and start stable release
if: steps.prepare.outputs.changed == 'true' && inputs.dry_run == 'false'
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.prepare.outputs.version }}
run: |
set -euo pipefail
git commit -m "chore: promote dev to main (v${VERSION})"
git push origin HEAD:main
# Pushes authenticated with GITHUB_TOKEN do not emit another workflow
# run, so explicitly dispatch the stable release at the pushed ref,
# pinning the exact commit so the release guard can refuse a moved main.
gh workflow run squad-release.yml \
--ref main \
-f confirm_tag="v${VERSION}" \
-f expected_sha="$(git rev-parse HEAD)" \
-f publish_standalone=true \
-f publish_package_managers=true
echo "Pushed main and dispatched stable release v${VERSION} at $(git rev-parse HEAD)."
- name: Report dry run
if: steps.prepare.outputs.changed == 'true' && inputs.dry_run == 'true'
env:
VERSION: ${{ steps.prepare.outputs.version }}
run: echo "Dry run passed for sanitized stable release v${VERSION}; main was not changed."