Skip to content

Commit 86ad644

Browse files
committed
fix: name the child repository PR after the tag being released
- Resolve the template version from the tag when the workflow runs on a tag push, which is the only way it ever runs: the Release workflow creates the release with GITHUB_TOKEN, and GitHub raises no workflow events for that token, so github.event.release was always empty and every pull request was titled "version latest" - Use the resolved version for the title, body, commit message and branch name, keeping the run number for manual runs so their branches do not collide - Build the release notes link from the tag instead of the release payload, so the line is no longer always empty
1 parent bf179f1 commit 86ad644

1 file changed

Lines changed: 38 additions & 6 deletions

File tree

‎.github/workflows/trigger-template-update.yml‎

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,38 @@ jobs:
2727
- name: Install uv
2828
uses: astral-sh/setup-uv@v10.0.1
2929

30+
- name: Resolve template version
31+
id: version
32+
env:
33+
# The Release workflow creates the release with GITHUB_TOKEN, and
34+
# GitHub does not start workflow runs from events raised by that
35+
# token, so the release trigger only fires for a release published by
36+
# hand. A tag push has no release context and must name itself.
37+
RELEASE_TAG: ${{ github.event.release.tag_name }}
38+
REF_TYPE: ${{ github.ref_type }}
39+
REF_NAME: ${{ github.ref_name }}
40+
RUN_NUMBER: ${{ github.run_number }}
41+
SERVER_URL: ${{ github.server_url }}
42+
REPOSITORY: ${{ github.repository }}
43+
run: |
44+
if [ -n "${RELEASE_TAG}" ]; then
45+
version="${RELEASE_TAG}"
46+
elif [ "${REF_TYPE}" = "tag" ]; then
47+
version="${REF_NAME}"
48+
else
49+
version="latest"
50+
fi
51+
echo "value=${version}" >> "$GITHUB_OUTPUT"
52+
# A manual run has no version to name its branch after, so fall back
53+
# to the run number to keep branches from colliding, and link no
54+
# release notes because there is no release to point at.
55+
if [ "${version}" = "latest" ]; then
56+
echo "slug=${RUN_NUMBER}" >> "$GITHUB_OUTPUT"
57+
else
58+
echo "slug=${version}" >> "$GITHUB_OUTPUT"
59+
echo "release_url=${SERVER_URL}/${REPOSITORY}/releases/tag/${version}" >> "$GITHUB_OUTPUT"
60+
fi
61+
3062
- name: Update template in child repository
3163
id: update
3264
working-directory: child-repo
@@ -78,17 +110,17 @@ jobs:
78110
token: ${{ secrets.CHILD_REPO_TOKEN }}
79111
path: child-repo
80112
commit-message: |
81-
Update template to version ${{ github.event.release.tag_name || 'latest' }}
82-
title: "Update template to version ${{ github.event.release.tag_name || 'latest' }}${{ steps.update.outputs.conflicts == 'true' && ' (resolve conflicts)' || '' }}"
113+
Update template to version ${{ steps.version.outputs.value }}
114+
title: "Update template to version ${{ steps.version.outputs.value }}${{ steps.update.outputs.conflicts == 'true' && ' (resolve conflicts)' || '' }}"
83115
body: |
84116
## Template Update
85117
86-
This PR updates the project template to version `${{ github.event.release.tag_name || 'latest' }}`.
118+
This PR updates the project template to version `${{ steps.version.outputs.value }}`.
87119
88120
### Changes
89121
- Updated from template: ${{ github.repository }}
90-
- Template version: ${{ github.event.release.tag_name || 'latest' }}
91-
${{ github.event.release.html_url && format('- Release notes: {0}', github.event.release.html_url) || '' }}
122+
- Template version: ${{ steps.version.outputs.value }}
123+
${{ steps.version.outputs.release_url && format('- Release notes: {0}', steps.version.outputs.release_url) || '' }}
92124
93125
${{ steps.update.outputs.conflict_note }}
94126
@@ -97,5 +129,5 @@ jobs:
97129
98130
---
99131
*This PR was automatically created by the template update workflow.*
100-
branch: template-update-${{ github.event.release.tag_name || github.run_number }}
132+
branch: template-update-${{ steps.version.outputs.slug }}
101133
delete-branch: true

0 commit comments

Comments
 (0)