1515# git subtree split is not used because it walks the entire monorepo history
1616# on every run, which takes tens of minutes at this repository's size.
1717#
18- # When a new maintained branch (2.3.x, ...) starts, update the branch trigger
18+ # Tag pushes (2.2.*) first bring the split branch up to date and then tag
19+ # the split commit replayed from the last turbo-ext-touching commit at or
20+ # before the tagged monorepo commit. Packagist picks the tag up as a
21+ # phpstan/turbo release, and the release workflow in phpstan/phpstan
22+ # attaches the PIE binary assets to a phpstan/turbo-ext release of the same
23+ # name.
24+ #
25+ # When a new maintained branch (2.3.x, ...) starts, update the triggers
1926# below (like phar.yml) and create the same-named branch in phpstan/turbo-ext
2027# from the previous branch's head — that head's trailer keeps the replay
2128# incremental across the branch point.
2734 push :
2835 branches :
2936 - " 2.2.x"
30- paths :
31- - " turbo-ext/**"
32- - " .github/workflows/subsplit-turbo-ext.yml"
37+ tags :
38+ - " 2.2.*"
3339
3440# The replay chain builds on the split branch's current head; two runs
3541# building on the same head would race each other, so queue them instead.
@@ -60,10 +66,27 @@ jobs:
6066 - name : " Replay commits touching turbo-ext/ and push them to phpstan/turbo-ext"
6167 env :
6268 PUSH_TOKEN : ${{ secrets.PHPSTAN_BOT_TOKEN }}
63- BRANCH : ${{ github.ref_name }}
69+ REF_TYPE : ${{ github.ref_type }}
70+ REF_NAME : ${{ github.ref_name }}
6471 run : |
6572 PREFIX="turbo-ext"
6673
74+ # A tag lives on its maintained branch (2.2.8 → 2.2.x). The replay
75+ # always follows the branch — a tag run just also marks the split
76+ # commit corresponding to the tagged monorepo commit afterwards.
77+ if [ "$REF_TYPE" = "tag" ]; then
78+ BRANCH="${REF_NAME%.*}.x"
79+ git fetch --no-tags origin "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH"
80+ replay_tip="$(git rev-parse "refs/remotes/origin/$BRANCH")"
81+ if ! git merge-base --is-ancestor HEAD "$replay_tip"; then
82+ echo "::error::Tag $REF_NAME does not point into branch $BRANCH."
83+ exit 1
84+ fi
85+ else
86+ BRANCH="$REF_NAME"
87+ replay_tip="$(git rev-parse HEAD)"
88+ fi
89+
6790 # The split branch must already exist (see the header comment); the
6891 # fetch fails loudly when it does not.
6992 git fetch --no-tags https://github.com/phpstan/turbo-ext.git "refs/heads/$BRANCH"
7396 # replay stopped. No trailer anywhere (the split repository only
7497 # has its initial commit) means the full history gets replayed.
7598 last_synced="$(git log FETCH_HEAD --format='%(trailers:key=Split-From,valueonly)' | grep -m1 . || true)"
76- if [ -n "$last_synced" ] && ! git merge-base --is-ancestor "$last_synced" HEAD ; then
99+ if [ -n "$last_synced" ] && ! git merge-base --is-ancestor "$last_synced" "$replay_tip" ; then
77100 echo "::error::$BRANCH does not contain $last_synced, the most recent Split-From trailer in the split repository. Was the branch history rewritten?"
78101 exit 1
79102 fi
@@ -82,43 +105,73 @@ jobs:
82105 # chain (verified July 2026), and first-parent order is append-only,
83106 # so the replay never reorders. A maintained-branch forward merge
84107 # that touches turbo-ext/ replays as the merge commit itself.
85- mapfile -t commits < <(git rev-list --reverse --first-parent ${last_synced:+"$last_synced.."}HEAD -- "$PREFIX")
86- if [ "${#commits[@]}" -eq 0 ]; then
108+ mapfile -t commits < <(git rev-list --reverse --first-parent ${last_synced:+"$last_synced.."}"$replay_tip" -- "$PREFIX")
109+
110+ tip="$target_head"
111+ if [ "${#commits[@]}" -gt 0 ]; then
112+ for commit in "${commits[@]}"; do
113+ # The version at this commit, mirroring the Makefile's git
114+ # computation: the last commit touching turbo-ext/src or a
115+ # non-vendored PHP class from the manifest as it existed at this
116+ # commit ("dev" before that layout existed).
117+ watched=("$PREFIX/src")
118+ while IFS= read -r mapped; do
119+ watched+=("$mapped")
120+ done < <(git show "$commit:$PREFIX/shadowed-classes.json" 2>/dev/null | jq -r '.[] | select(.vendored != true) | .php' 2>/dev/null || true)
121+ version="$(git log -1 --format=%H "$commit" -- "${watched[@]}" | cut -c1-7)"
122+ blob="$(printf '%s\n' "${version:-dev}" | git hash-object -w --stdin)"
123+ # a commit removing the directory altogether replays as an empty tree
124+ if subtree="$(git rev-parse -q --verify "$commit:$PREFIX")"; then
125+ tree="$({ git ls-tree "$subtree" | awk -F'\t' '$2 != "VERSION.txt"'; printf '100644 blob %s\tVERSION.txt\n' "$blob"; } | git mktree)"
126+ else
127+ tree="$(git hash-object -t tree /dev/null)"
128+ fi
129+ tip="$(
130+ git log -1 --format=%B "$commit" \
131+ | git interpret-trailers --trailer "Split-From: $commit" \
132+ | GIT_AUTHOR_NAME="$(git log -1 --format=%an "$commit")" \
133+ GIT_AUTHOR_EMAIL="$(git log -1 --format=%ae "$commit")" \
134+ GIT_AUTHOR_DATE="$(git log -1 --format=%aD "$commit")" \
135+ GIT_COMMITTER_NAME="$(git log -1 --format=%cn "$commit")" \
136+ GIT_COMMITTER_EMAIL="$(git log -1 --format=%ce "$commit")" \
137+ GIT_COMMITTER_DATE="$(git log -1 --format=%cD "$commit")" \
138+ git commit-tree "$tree" -p "$tip"
139+ )"
140+ echo "$commit -> $tip"
141+ done
142+
143+ echo "Replayed ${#commits[@]} commit(s), pushing to $BRANCH"
144+ git push "https://x-access-token:${PUSH_TOKEN}@github.com/phpstan/turbo-ext.git" "$tip:refs/heads/$BRANCH"
145+ else
87146 echo "The split repository is up to date at $target_head."
147+ fi
148+
149+ if [ "$REF_TYPE" != "tag" ]; then
88150 exit 0
89151 fi
90152
91- parent="$target_head"
92- for commit in "${commits[@]}"; do
93- # The version at this commit, mirroring the Makefile's git
94- # computation: the last commit touching turbo-ext/src or a
95- # non-vendored PHP class from the manifest as it existed at this
96- # commit ("dev" before that layout existed).
97- watched=("$PREFIX/src")
98- while IFS= read -r mapped; do
99- watched+=("$mapped")
100- done < <(git show "$commit:$PREFIX/shadowed-classes.json" 2>/dev/null | jq -r '.[] | select(.vendored != true) | .php' 2>/dev/null || true)
101- version="$(git log -1 --format=%H "$commit" -- "${watched[@]}" | cut -c1-7)"
102- blob="$(printf '%s\n' "${version:-dev}" | git hash-object -w --stdin)"
103- # a commit removing the directory altogether replays as an empty tree
104- if subtree="$(git rev-parse -q --verify "$commit:$PREFIX")"; then
105- tree="$({ git ls-tree "$subtree" | awk -F'\t' '$2 != "VERSION.txt"'; printf '100644 blob %s\tVERSION.txt\n' "$blob"; } | git mktree)"
106- else
107- tree="$(git hash-object -t tree /dev/null)"
108- fi
109- parent="$(
110- git log -1 --format=%B "$commit" \
111- | git interpret-trailers --trailer "Split-From: $commit" \
112- | GIT_AUTHOR_NAME="$(git log -1 --format=%an "$commit")" \
113- GIT_AUTHOR_EMAIL="$(git log -1 --format=%ae "$commit")" \
114- GIT_AUTHOR_DATE="$(git log -1 --format=%aD "$commit")" \
115- GIT_COMMITTER_NAME="$(git log -1 --format=%cn "$commit")" \
116- GIT_COMMITTER_EMAIL="$(git log -1 --format=%ce "$commit")" \
117- GIT_COMMITTER_DATE="$(git log -1 --format=%cD "$commit")" \
118- git commit-tree "$tree" -p "$parent"
119- )"
120- echo "$commit -> $parent"
121- done
122-
123- echo "Replayed ${#commits[@]} commit(s), pushing to $BRANCH"
124- git push "https://x-access-token:${PUSH_TOKEN}@github.com/phpstan/turbo-ext.git" "$parent:refs/heads/$BRANCH"
153+ # Tag the split commit replayed from the last turbo-ext-touching
154+ # commit at or before the tagged monorepo commit (HEAD on tag runs).
155+ tag_src="$(git rev-list -1 --first-parent HEAD -- "$PREFIX")"
156+ if [ -z "$tag_src" ]; then
157+ echo "::error::No commit touching $PREFIX/ precedes tag $REF_NAME."
158+ exit 1
159+ fi
160+ split_commit="$(git log "$tip" --format='%H%x09%(trailers:key=Split-From,valueonly,separator=)' | awk -F'\t' -v want="$tag_src" '$2 == want {print $1; exit}')"
161+ if [ -z "$split_commit" ]; then
162+ echo "::error::No split commit carries Split-From: $tag_src — was $tag_src replayed?"
163+ exit 1
164+ fi
165+
166+ existing="$(git ls-remote https://github.com/phpstan/turbo-ext.git "refs/tags/$REF_NAME" | cut -f1)"
167+ if [ "$existing" = "$split_commit" ]; then
168+ echo "Tag $REF_NAME already points at $split_commit."
169+ exit 0
170+ fi
171+ if [ -n "$existing" ]; then
172+ echo "::error::Tag $REF_NAME already exists in phpstan/turbo-ext at $existing, expected $split_commit. Delete it there if it must move."
173+ exit 1
174+ fi
175+
176+ echo "Tagging $split_commit (replayed from $tag_src) as $REF_NAME"
177+ git push "https://x-access-token:${PUSH_TOKEN}@github.com/phpstan/turbo-ext.git" "$split_commit:refs/tags/$REF_NAME"
0 commit comments