Repository navigation
644 lines (588 loc) · 26.9 KB
/
Copy pathrelease.yml
File metadata and controls
644 lines (588 loc) · 26.9 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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# npm publish for the four public packages, PyPI for python/trueforge_sdk, two
# server images, and the Helm chart. One dispatch, one run, one conclusion:
# success means published.
#
# npm and PyPI trusted publishers are bound to this filename (`release.yml`).
# Do not rename it without updating every package on npmjs.com and PyPI.
#
# Releases run on release-vX.Y.Z, never on main. main only collects changesets.
# The parent chart's release dispatches this workflow with tfy_chart_version
# (X.Y.Z or X.Y.Z-rc.N) on ref release-vX.Y.Z. There is no push trigger: that
# dispatch is the only entry point, so a run's conclusion is the release
# outcome.
#
# version-release prepares pre mode and any 0.0.0 packages, runs
# `changeset version`, and commits the result straight to the release branch.
# Every later job checks out that commit: actions/checkout defaults to the SHA
# at dispatch time, which predates the version bump.
#
# changesets/action/select-mode then reports whether anything is left to
# publish. `publish` means pack (build/test) + Windows npx smoke gate npm and
# PyPI. `none` is normal and not an error: a line with no changesets since the
# last release still has to publish a chart at the requested version.
#
# The image and chart path is independent of npm. It is gated on the
# charts/trueforge@<tfy_chart_version> tag: absent means this version has not
# been cut yet, so build both images (public on node:24-slim, hardened on the
# private hardened node bases) and publish the chart. Present means a
# re-run - reuse the images the tagged commit already references and let
# release-chart.yml finish whatever is missing.
#
# Auth is GitHub OIDC (no NPM_TOKEN / PYPI_TOKEN). An `_authToken` in user
# `.npmrc` disables pnpm's OIDC exchange, so the npm publish job must not set
# NPM_TOKEN / NODE_AUTH_TOKEN. id-token is granted on the publish jobs and on
# the image jobs (OIDC into the private registry for the hardened bases, and
# Cosign signing).
name: Version or publish packages
on:
workflow_dispatch:
inputs:
tfy_chart_version:
description: 'Chart version to publish: X.Y.Z or X.Y.Z-rc.N'
required: true
type: string
# DRY-RUN (temporary): exercise the whole pipeline without publishing
# anything outside this repo. Commits to the release branch still happen
# - downstream jobs check that commit out - so dispatch it on a scratch
# release-v* branch you are willing to delete. Grep DRY-RUN to remove.
dry_run:
description: 'Dry run: skip npm, PyPI, images, git tags, the OCI push and the back-merge'
required: false
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# Never cancel a publish that is already talking to npm.
cancel-in-progress: false
permissions: {}
jobs:
version-release:
name: Version packages for the release
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
# Every downstream job checks this out; actions/checkout's default ref is
# the pre-version SHA from the dispatch.
sha: ${{ steps.commit.outputs.sha }}
final_minor: ${{ steps.commit.outputs.final_minor }}
mode: ${{ steps.select-mode.outputs.mode }}
publish-plan-artifact-id: ${{ steps.select-mode.outputs.publish-plan-artifact-id }}
permissions:
contents: write
steps:
- id: app-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ secrets.TRUEFORGE_GENERATE_SDK_APP_ID }}
private-key: ${{ secrets.TRUEFORGE_GENERATE_SDK_APP_PRIVATE_KEY }}
- name: Check out repo
uses: actions/checkout@v7
with:
# Full history so `changeset version` can write CHANGELOG from commits.
fetch-depth: 0
persist-credentials: false
token: ${{ steps.app-token.outputs.token }}
- uses: pnpm/action-setup@v6
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Prepare release and version packages
env:
TFY_CHART_VERSION: ${{ inputs.tfy_chart_version }}
RELEASE_BRANCH: ${{ github.ref_name }}
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
run: |
node scripts/prepare-release.mjs
pnpm run version
- name: Commit versions to the release branch
id: commit
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
RELEASE_BRANCH: ${{ github.ref_name }}
TFY_CHART_VERSION: ${{ inputs.tfy_chart_version }}
HUSKY: '0'
run: |
set -euo pipefail
# Only a final minor drains main. A hotfix (X.Y.Z, Z>0) must not:
# its changeset still sits on main from the source PR and belongs in
# the next minor's changelog too.
if [[ "$TFY_CHART_VERSION" =~ ^[0-9]+\.[0-9]+\.0$ ]]; then
echo "final_minor=true" >> "$GITHUB_OUTPUT"
else
echo "final_minor=false" >> "$GITHUB_OUTPUT"
fi
if [ -z "$(git status --porcelain)" ]; then
SHA="$(git rev-parse HEAD)"
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
echo "Nothing to version; releasing ${RELEASE_BRANCH} at $SHA"
exit 0
fi
gh auth setup-git
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Version Packages for ${TFY_CHART_VERSION}"
git push origin "HEAD:${RELEASE_BRANCH}"
SHA="$(git rev-parse HEAD)"
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
echo "Committed versions for ${TFY_CHART_VERSION} as $SHA"
# After the commit, so it reads the versioned tree. `none` is a valid
# outcome and is not treated as a failure.
- name: Select Changesets mode
id: select-mode
uses: changesets/action/select-mode@v2
pack:
name: Pack packages
if: needs.version-release.outputs.mode == 'publish'
needs: [version-release]
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
pack-dir-artifact-id: ${{ steps.pack.outputs.pack-dir-artifact-id }}
permissions:
contents: read
steps:
- name: Check out repo
uses: actions/checkout@v7
with:
ref: ${{ needs.version-release.outputs.sha }}
persist-credentials: false
- uses: pnpm/action-setup@v6
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 24
package-manager-cache: false
- run: pnpm install --frozen-lockfile
- run: pnpm build
- run: pnpm test
# Root build copies FE into packages/trueforge/dist/_frontend; refuse an API-only tarball.
- name: Verify packaged UI is present
run: |
test -f packages/trueforge/dist/cli.js
test -f packages/trueforge/dist/_frontend/index.html
- name: Pack packages
id: pack
uses: changesets/action/pack@v2
with:
publish-plan-artifact-id: ${{ needs.version-release.outputs.publish-plan-artifact-id }}
windows-npx-smoke:
name: Windows npx smoke
if: needs.version-release.outputs.mode == 'publish'
needs: [version-release]
runs-on: windows-latest
timeout-minutes: 30
permissions:
contents: read
steps:
- name: Check out repo
uses: actions/checkout@v7
with:
ref: ${{ needs.version-release.outputs.sha }}
persist-credentials: false
- uses: pnpm/action-setup@v6
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 24
# No package-manager cache: this job checks out a commit this run just
# created (version-release.outputs.sha), and writing an Actions cache
# from an expression-derived ref is the cache-poisoning shape CodeQL
# flags. The other two jobs on this ref already opt out.
package-manager-cache: false
- run: pnpm install --frozen-lockfile
- name: Pack and boot published CLI
run: pnpm smoke:npx
publish:
name: Publish packages
# resolve-image is in `needs` for its veto, not its outputs. npm and PyPI
# are the only irreversible steps in this workflow - npm allows 72h to
# unpublish, PyPI never does - so neither may run while any part of the
# release has already refused. Without this they publish in parallel with
# the image path and land a version no image or chart will ever match.
needs: [version-release, pack, windows-npx-smoke, resolve-image]
if: ${{ inputs.dry_run != true }} # DRY-RUN (temporary)
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: write
id-token: write
steps:
- name: Check out repo
uses: actions/checkout@v7
with:
ref: ${{ needs.version-release.outputs.sha }}
persist-credentials: false
- uses: pnpm/action-setup@v6
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 24
# No registry-url / NODE_AUTH_TOKEN: an `_authToken` in .npmrc disables
# pnpm's OIDC exchange for npm trusted publishing.
package-manager-cache: false
- run: pnpm install --frozen-lockfile
- name: Publish packages
id: publish
uses: changesets/action/publish@v2
with:
pack-dir-artifact-id: ${{ needs.pack.outputs.pack-dir-artifact-id }}
create-github-releases: true
env:
# Attest source repo + commit on every publish. Trusted publishing
# already uses OIDC (`id-token: write`); this flag is what changesets
# / pnpm honor (they do not accept `--provenance`).
# publishConfig.provenance is true on every public package.
NPM_CONFIG_PROVENANCE: 'true'
# Sibling of npm publish (same gates). Skips when pyproject version is already on PyPI.
publish-python:
name: Publish Python SDK
# Same veto as `publish`; PyPI is the one registry that never lets a
# version be reused, so it must not outrun a refusal either.
needs: [version-release, pack, windows-npx-smoke, resolve-image]
if: ${{ inputs.dry_run != true }} # DRY-RUN (temporary)
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
id-token: write
steps:
- name: Check out repo
uses: actions/checkout@v7
with:
ref: ${{ needs.version-release.outputs.sha }}
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.12'
- name: Install build tools
run: python -m pip install --upgrade pip build packaging
- name: Read version and skip if published
id: version
working-directory: python/trueforge_sdk
run: |
set -euo pipefail
VERSION="$(python3 -c '
import re, pathlib
from packaging.version import Version
text = pathlib.Path("pyproject.toml").read_text()
match = re.search(r"(?m)^version\s*=\s*\"([^\"]+)\"", text)
if match is None:
raise SystemExit("missing version in pyproject.toml")
print(Version(match.group(1)))
')"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
code="$(curl -sS -L -o /dev/null -w '%{http_code}' "https://pypi.org/pypi/trueforge-sdk/${VERSION}/json")"
if [[ "$code" == "200" ]]; then
echo "already=true" >> "$GITHUB_OUTPUT"
echo "trueforge-sdk==$VERSION already on PyPI; skipping"
elif [[ "$code" == "404" ]]; then
echo "already=false" >> "$GITHUB_OUTPUT"
else
echo "Unexpected PyPI response HTTP $code for trueforge-sdk==$VERSION" >&2
exit 1
fi
- name: Build distributions
if: steps.version.outputs.already == 'false'
working-directory: python/trueforge_sdk
run: python -m build
- name: Publish to PyPI
if: steps.version.outputs.already == 'false'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: python/trueforge_sdk/dist
# Independent of npm. The chart version is the dispatch input, so "already
# released?" is answered by the charts/trueforge@<version> tag, which
# release-chart.yml writes before it pushes to OCI. A line with no changesets
# since the last release publishes no packages and still needs a chart.
resolve-image:
name: Resolve image identity
needs: [version-release]
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
app_version: ${{ steps.resolve.outputs.app_version }}
image_tag: ${{ steps.resolve.outputs.image_tag }}
# "build" or "skip", not true/false. GitHub drops a job output whose
# value is the string false, which would skip the image builds.
image: ${{ steps.resolve.outputs.image }}
permissions:
contents: read
steps:
- name: Check out repo
uses: actions/checkout@v7
with:
ref: ${{ needs.version-release.outputs.sha }}
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 24
- name: Resolve image identity
id: resolve
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHART_VERSION: ${{ inputs.tfy_chart_version }}
run: |
set -euo pipefail
SEMVER='^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$'
APP_VERSION=$(node -p "require('./packages/trueforge/package.json').version")
if [[ -z "$APP_VERSION" || "$APP_VERSION" == "undefined" ]] || ! printf '%s' "$APP_VERSION" | grep -Eq "$SEMVER"; then
echo "app_version '$APP_VERSION' is not a semver-like version" >&2
exit 1
fi
IMAGE_TAG="${APP_VERSION}-$(git rev-parse --short=7 HEAD)"
# matching-refs, not git/ref: a miss returns 200 + [], so "absent" is
# distinguishable from an API error. It is a prefix match, hence the
# exact-.ref filter. git ls-remote is unavailable here because the
# checkout runs with persist-credentials: false.
TAG="charts/trueforge@${CHART_VERSION}"
FOUND=$(gh api "repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/${TAG}" \
--jq "[.[] | select(.ref == \"refs/tags/${TAG}\")] | length")
if [[ "$FOUND" == "0" ]]; then
echo "image=build" >> "$GITHUB_OUTPUT"
echo "app_version=$APP_VERSION" >> "$GITHUB_OUTPUT"
echo "image_tag=$IMAGE_TAG" >> "$GITHUB_OUTPUT"
echo "$TAG does not exist; building image $IMAGE_TAG"
exit 0
fi
# Re-run of an already-cut version. The tagged commit names the image
# that belongs to this chart version; rebuilding under a new SHA would
# make the same chart version disagree with itself. Empty outputs tell
# release-chart.yml to keep the values already on the branch.
echo "image=skip" >> "$GITHUB_OUTPUT"
echo "app_version=" >> "$GITHUB_OUTPUT"
echo "image_tag=" >> "$GITHUB_OUTPUT"
echo "$TAG already exists; reusing the image the tagged commit references"
# Two images, same tag, different Artifactory repos. The public one keeps the
# Dockerfile's public bases so it stays redistributable; the hardened one is
# built from Chainguard bases whose licence forbids publishing them, so it
# only goes to the private repo that TrueFoundry SaaS pulls from.
build-image-public:
name: Build and push public server image
# DRY-RUN (temporary): `&& inputs.dry_run != true`
if: needs.resolve-image.outputs.image == 'build' && inputs.dry_run != true
# version-release must be a DIRECT dependency: the needs context only
# exposes outputs from jobs listed here, so checkout_ref below would be
# empty otherwise and checkout would silently fall back to github.sha.
needs: [version-release, resolve-image]
uses: truefoundry/github-workflows-public/.github/workflows/build.yml@main
permissions:
id-token: write
contents: read
packages: write
with:
artifactory_oidc_provider_name: github-jfrog-trueforge
# The shared build.yml inherits THIS run's github.sha, which is the
# pre-version dispatch commit. version-release has already pushed the
# bumped tree, so name it explicitly or the image ships the old
# versions baked into its generated SDK while the tag claims the new.
checkout_ref: ${{ needs.version-release.outputs.sha }}
artifactory_registry_url: ${{ vars.TRUEFOUNDRY_ARTIFACTORY_REGISTRY_URL }}
artifactory_repository_url: ${{ vars.TRUEFOUNDRY_ARTIFACTORY_PUBLIC_REPOSITORY }}
image_artifact_name: trueforge
image_tag: ${{ needs.resolve-image.outputs.image_tag }}
image_context: .
dockerfile_path: Dockerfile
platforms: linux/amd64
enable_jfrog: true
enable_public_ecr: false
build-image-private:
name: Build and push hardened server image
# DRY-RUN (temporary): `&& inputs.dry_run != true`
if: needs.resolve-image.outputs.image == 'build' && inputs.dry_run != true
# version-release must be a DIRECT dependency: the needs context only
# exposes outputs from jobs listed here, so checkout_ref below would be
# empty otherwise and checkout would silently fall back to github.sha.
needs: [version-release, resolve-image]
uses: truefoundry/github-workflows-public/.github/workflows/build.yml@main
permissions:
id-token: write
contents: read
packages: write
with:
artifactory_oidc_provider_name: github-jfrog-trueforge-private
# Same reason as the public image: build the version commit, not the
# dispatch commit.
checkout_ref: ${{ needs.version-release.outputs.sha }}
artifactory_registry_url: ${{ vars.TRUEFOUNDRY_ARTIFACTORY_REGISTRY_URL }}
artifactory_repository_url: ${{ vars.TRUEFOUNDRY_ARTIFACTORY_PRIVATE_REPOSITORY }}
image_artifact_name: trueforge
image_tag: ${{ needs.resolve-image.outputs.image_tag }}
image_context: .
dockerfile_path: Dockerfile
platforms: linux/amd64
enable_jfrog: true
enable_public_ecr: false
# Pull-only credential for the devtest account that helm-charts mirrors the
# hardened bases into; the image itself still goes to Artifactory.
enable_private_ecr_pull: true
private_ecr_pull_registry: 526077812922.dkr.ecr.us-east-1.amazonaws.com
image_build_args: |
BUILD_BASE_IMAGE=526077812922.dkr.ecr.us-east-1.amazonaws.com/tfy-internal/node:24-dev
RUNTIME_BASE_IMAGE=526077812922.dkr.ecr.us-east-1.amazonaws.com/tfy-internal/node:24
VITE_POSTHOG_HOST=https://eu.i.posthog.com/
secrets:
private_ecr_pull_role_arn: ${{ secrets.AWS_DEVTEST_ECR_IAM_ROLE_ARN }}
# Caller with: has no secrets context; pass secret build-args here so the
# shared workflow can append them to image_build_args.
image_build_secrets: |
VITE_POSTHOG_API_KEY=${{ secrets.TRUEFORGE_POSTHOG_API_KEY }}
VITE_SENTRY_DSN=${{ secrets.TRUEFORGE_SENTRY_DSN }}
release-chart:
name: Publish Helm chart
needs: [resolve-image, build-image-public, build-image-private]
# The image jobs are legitimately skipped on a re-run of an already-tagged
# version, and a plain `needs` would skip the chart along with them. The
# chart job is idempotent, so it runs in both cases and finishes whatever
# the previous attempt left undone.
if: ${{ !cancelled()
&& needs.resolve-image.result == 'success'
&& (needs.build-image-public.result == 'success' || needs.build-image-public.result == 'skipped')
&& (needs.build-image-private.result == 'success' || needs.build-image-private.result == 'skipped') }}
uses: ./.github/workflows/release-chart.yml
permissions:
contents: write
with:
branch: ${{ github.ref_name }}
chart_version: ${{ inputs.tfy_chart_version }}
# Empty on a re-run: keep whatever the tagged metadata commit already has.
app_version: ${{ needs.resolve-image.outputs.app_version }}
image_tag: ${{ needs.resolve-image.outputs.image_tag }}
dry_run: ${{ inputs.dry_run }} # DRY-RUN (temporary)
secrets: inherit
# A final minor is the only release that drains main. main has been
# append-only for changesets since the release moved onto release-v* branches,
# so without this every new line re-consumes the backlog and repeats its
# changelog entries, and the CHANGELOG sections written here never reach main.
#
# Only .changeset/*.md deletions and packages/*/CHANGELOG.md move. Every
# version field is left alone: main stays at 0.0.0 by design, and excluding
# them is what keeps this conflict-free.
#
# continue-on-error: this job runs after release-chart has already pushed to
# OCI, inside the run the caller gates its own chart phase on. A changelog
# drain must never fail a release whose chart is live and correct. A failure is
# reported as a ::error:: annotation and recovered by re-dispatching.
back-merge-main:
name: Back-merge changelogs to main
needs: [version-release, release-chart]
# release-chart must have actually SUCCEEDED. It is never legitimately
# skipped: it runs on a first cut, on a re-run of an already-cut version
# (idempotent - it finishes whatever the last attempt left), when there was
# nothing to version, and in a dry run. The only way it skips is a failure
# upstream, so accepting `skipped` here would drain consumed changesets off
# main for a release that never published a chart. A retry still works: the
# re-run's release-chart succeeds, and this job runs then.
if: ${{ !cancelled()
&& needs.version-release.result == 'success'
&& needs.version-release.outputs.final_minor == 'true'
&& needs.release-chart.result == 'success'
&& inputs.dry_run != true }} # DRY-RUN (temporary)
runs-on: ubuntu-latest
timeout-minutes: 60
continue-on-error: true
permissions:
contents: write
pull-requests: write
steps:
- id: app-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ secrets.TRUEFORGE_GENERATE_SDK_APP_ID }}
private-key: ${{ secrets.TRUEFORGE_GENERATE_SDK_APP_PRIVATE_KEY }}
- name: Check out repo
uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
token: ${{ steps.app-token.outputs.token }}
- name: Build the back-merge commit
id: build
env:
RELEASE_SHA: ${{ needs.version-release.outputs.sha }}
TFY_CHART_VERSION: ${{ inputs.tfy_chart_version }}
run: |
set -euo pipefail
git fetch --no-tags origin main
git fetch --no-tags origin "$RELEASE_SHA"
# Consumed = present at the branch cut, absent on the release branch
# now. After `changeset pre exit` that covers both the files deleted
# outright and the ones that passed through .changeset/pre/.
# ls-tree is non-recursive on purpose: .changeset/pre/ contents are
# release-branch-only state and must not be listed.
base="$(git merge-base origin/main "$RELEASE_SHA")"
list() {
git ls-tree --name-only "$1" .changeset/ | grep '\.md$' | grep -v '/README\.md$' | sort
}
consumed="$(comm -23 <(list "$base") <(list "$RELEASE_SHA") || true)"
git checkout -B "back-merge/v${TFY_CHART_VERSION}" origin/main
if [ -n "$consumed" ]; then
printf '%s\n' "$consumed" | xargs -r git rm -q --ignore-unmatch --
printf 'dropping consumed changesets:\n%s\n' "$consumed"
fi
changelogs="$(git ls-tree --name-only -r "$RELEASE_SHA" packages/ | grep '/CHANGELOG\.md$' || true)"
if [ -n "$changelogs" ]; then
printf '%s\n' "$changelogs" | xargs -r git checkout "$RELEASE_SHA" --
fi
if git diff --staged --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "main already carries this line's changesets and changelogs"
exit 0
fi
echo "changed=true" >> "$GITHUB_OUTPUT"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "Back-merge changelogs for ${TFY_CHART_VERSION}"
- name: Open and merge the back-merge PR
if: steps.build.outputs.changed == 'true'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
BACK_MERGE_BRANCH: back-merge/v${{ inputs.tfy_chart_version }}
TFY_CHART_VERSION: ${{ inputs.tfy_chart_version }}
run: |
set -euo pipefail
gh auth setup-git
git push --force origin "HEAD:refs/heads/${BACK_MERGE_BRANCH}"
find_pr() {
gh pr list --repo "$GITHUB_REPOSITORY" --head "$BACK_MERGE_BRANCH" \
--base main --state open --json number --jq '.[0].number // empty'
}
PR="$(find_pr)"
if [ -z "$PR" ]; then
gh pr create \
--repo "$GITHUB_REPOSITORY" \
--base main \
--head "$BACK_MERGE_BRANCH" \
--title "Back-merge changelogs for ${TFY_CHART_VERSION}" \
--body "Drains the changesets consumed by release-v${TFY_CHART_VERSION} and carries that line's packages/*/CHANGELOG.md back to main. No version field moves: main stays at 0.0.0."
PR="$(find_pr)"
fi
if [ -z "$PR" ]; then
echo "::error::could not open or find the back-merge PR"
exit 1
fi
# "Nothing to back-merge" was already handled above, so anything that
# stops this PR landing is reported loudly: silently skipping the
# drain leaves main re-consuming the backlog on the next line.
gh pr merge "$PR" --repo "$GITHUB_REPOSITORY" --squash --delete-branch --admin \
|| echo "merge command failed; verifying PR state (it may already be merged)"
STATE="$(gh pr view "$PR" --repo "$GITHUB_REPOSITORY" --json state --jq .state)"
if [ "$STATE" != "MERGED" ]; then
echo "::error::back-merge PR #${PR} did not merge (state=${STATE})"
exit 1
fi
echo "Back-merged into main via #${PR}"
# The steps above annotate their own known failures, but a step dying
# under `set -euo pipefail` does not. The release is already published at
# this point, so surface the drain failure without failing the run.
- name: Report back-merge failure
if: failure()
env:
TFY_CHART_VERSION: ${{ inputs.tfy_chart_version }}
run: |
echo "::error::back-merge to main failed for ${TFY_CHART_VERSION}; main still carries this line's consumed changesets. Re-dispatch this release to retry the drain."