Skip to content

Commit ad17e8d

Browse files
ci: run changeset suffix normalizer inside the version: hook (#820) (#822)
The previous attempt added a pre-step that rewrote -ueX.Y suffixes in .changeset/*.md before invoking changesets/action. That did not work: changesets/action creates a fresh changeset-release/<branch> branch and then `git reset --hard`s it to the trigger commit right before running `changeset version`, wiping any working-tree edits made earlier in the workflow (observed on run 24817349995). Move the normalization into the action's `version:` input so it runs inside the release-branch worktree AFTER the reset, then chains into `npx changeset version`. The rewrites now survive. The logic is extracted into .github/scripts/version-with-normalized-suffixes.sh and is otherwise unchanged: idempotent, skips non-UEx.y branches, leaves .changeset/README.md alone. (cherry picked from commit feee263) Co-authored-by: mcottontensor <80377552+mcottontensor@users.noreply.github.com>
1 parent 6271bf8 commit ad17e8d

2 files changed

Lines changed: 43 additions & 36 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
# Runs inside the `changesets/action` release-branch worktree as the `version:`
3+
# command. Normalizes "-ueX.Y" suffixes in changeset files so that changesets
4+
# authored on master (which reference the current-latest suffix, e.g.
5+
# "-ue5.7") are accepted on older UE release branches after auto-backport.
6+
#
7+
# Using the action's `version:` hook rather than a pre-step is deliberate: the
8+
# action performs `git reset --hard <sha>` inside a fresh `changeset-release/*`
9+
# branch right before running this command, which would wipe any working-tree
10+
# edits made earlier in the workflow.
11+
#
12+
# The normalization is idempotent — a branch whose changesets already have the
13+
# correct suffix is a no-op — and only touches .changeset/*.md (not README).
14+
# Branches that do not match `UEX.Y` skip the rewrite entirely.
15+
set -euo pipefail
16+
17+
branch="${GITHUB_REF_NAME:-}"
18+
if [[ "$branch" =~ ^UE([0-9]+\.[0-9]+)$ ]]; then
19+
ver="${BASH_REMATCH[1]}"
20+
echo "Normalizing -ue* suffixes in .changeset/*.md to ue${ver}"
21+
shopt -s nullglob
22+
rewrote=0
23+
for f in .changeset/*.md; do
24+
[[ "$(basename "$f")" == "README.md" ]] && continue
25+
before="$(cat "$f")"
26+
after="$(sed -E "s|(-ue)[0-9]+\.[0-9]+|\1${ver}|g" "$f")"
27+
if [[ "$before" != "$after" ]]; then
28+
printf '%s' "$after" > "$f"
29+
echo " rewrote $f"
30+
rewrote=$((rewrote + 1))
31+
fi
32+
done
33+
echo "Normalized ${rewrote} file(s)."
34+
else
35+
echo "Branch '$branch' is not UEx.y; skipping suffix normalization."
36+
fi
37+
38+
npx changeset version

.github/workflows/changesets-update-changelogs.yml

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,16 @@ jobs:
2929
- name: Install Dependencies
3030
run: npm install
3131

32-
# Changesets authored on master reference the current UE suffix (e.g.
33-
# "@epicgames-ps/lib-pixelstreamingfrontend-ue5.7"). Auto-backport copies
34-
# those files verbatim onto older UE release branches where the matching
35-
# package has a different suffix (e.g. "...-ue5.6", "...-ue5.5"), and the
36-
# changesets CLI then fails with:
37-
# Found changeset ... for package ...-ue5.7 which is not in the workspace
38-
# Normalize any "-ueX.Y" suffix inside .changeset/*.md to match the branch
39-
# this workflow is running on. Idempotent: a no-op when suffixes already
40-
# match. The rewrite lives only in the workflow's working tree; the
41-
# changesets action consumes and removes these files as part of the
42-
# release PR, so nothing needs to be committed back to the branch.
43-
- name: Normalize changeset package suffixes to branch version
44-
shell: bash
45-
run: |
46-
set -euo pipefail
47-
branch="${{ github.ref_name }}"
48-
if [[ ! "$branch" =~ ^UE([0-9]+\.[0-9]+)$ ]]; then
49-
echo "Branch '$branch' is not UEx.y; skipping suffix normalization."
50-
exit 0
51-
fi
52-
ver="${BASH_REMATCH[1]}"
53-
echo "Normalizing -ue* suffixes in .changeset/*.md to ue${ver}"
54-
shopt -s nullglob
55-
rewrote=0
56-
for f in .changeset/*.md; do
57-
[[ "$(basename "$f")" == "README.md" ]] && continue
58-
before="$(cat "$f")"
59-
after="$(sed -E "s|(-ue)[0-9]+\.[0-9]+|\1${ver}|g" "$f")"
60-
if [[ "$before" != "$after" ]]; then
61-
printf '%s' "$after" > "$f"
62-
echo " rewrote $f"
63-
rewrote=$((rewrote + 1))
64-
fi
65-
done
66-
echo "Normalized ${rewrote} file(s)."
67-
32+
# The `version:` script below normalizes "-ueX.Y" suffixes in backported
33+
# changeset files so the changesets CLI can resolve them against this
34+
# branch's workspace. It runs inside the action's release-branch worktree
35+
# (after its internal `git reset --hard`) so the rewrites survive.
6836
- name: Create Release Pull Request
6937
uses: changesets/action@v1.4.10
7038
env:
7139
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7240
with:
7341
title: '[Bot] NPM Packages Release ${{ github.ref_name }}'
7442
commit: 'Updated NPM changelogs'
43+
version: bash .github/scripts/version-with-normalized-suffixes.sh
7544

0 commit comments

Comments
 (0)