From 86ad644ee614ac1d8bb7b6994656ceacd719fa69 Mon Sep 17 00:00:00 2001 From: Junya Morioka Date: Wed, 9 Sep 2026 01:14:11 +0900 Subject: [PATCH] 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 --- .github/workflows/trigger-template-update.yml | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/.github/workflows/trigger-template-update.yml b/.github/workflows/trigger-template-update.yml index be512b7..1d7a44e 100644 --- a/.github/workflows/trigger-template-update.yml +++ b/.github/workflows/trigger-template-update.yml @@ -27,6 +27,38 @@ jobs: - name: Install uv uses: astral-sh/setup-uv@v10.0.1 + - name: Resolve template version + id: version + env: + # The Release workflow creates the release with GITHUB_TOKEN, and + # GitHub does not start workflow runs from events raised by that + # token, so the release trigger only fires for a release published by + # hand. A tag push has no release context and must name itself. + RELEASE_TAG: ${{ github.event.release.tag_name }} + REF_TYPE: ${{ github.ref_type }} + REF_NAME: ${{ github.ref_name }} + RUN_NUMBER: ${{ github.run_number }} + SERVER_URL: ${{ github.server_url }} + REPOSITORY: ${{ github.repository }} + run: | + if [ -n "${RELEASE_TAG}" ]; then + version="${RELEASE_TAG}" + elif [ "${REF_TYPE}" = "tag" ]; then + version="${REF_NAME}" + else + version="latest" + fi + echo "value=${version}" >> "$GITHUB_OUTPUT" + # A manual run has no version to name its branch after, so fall back + # to the run number to keep branches from colliding, and link no + # release notes because there is no release to point at. + if [ "${version}" = "latest" ]; then + echo "slug=${RUN_NUMBER}" >> "$GITHUB_OUTPUT" + else + echo "slug=${version}" >> "$GITHUB_OUTPUT" + echo "release_url=${SERVER_URL}/${REPOSITORY}/releases/tag/${version}" >> "$GITHUB_OUTPUT" + fi + - name: Update template in child repository id: update working-directory: child-repo @@ -78,17 +110,17 @@ jobs: token: ${{ secrets.CHILD_REPO_TOKEN }} path: child-repo commit-message: | - Update template to version ${{ github.event.release.tag_name || 'latest' }} - title: "Update template to version ${{ github.event.release.tag_name || 'latest' }}${{ steps.update.outputs.conflicts == 'true' && ' (resolve conflicts)' || '' }}" + Update template to version ${{ steps.version.outputs.value }} + title: "Update template to version ${{ steps.version.outputs.value }}${{ steps.update.outputs.conflicts == 'true' && ' (resolve conflicts)' || '' }}" body: | ## Template Update - This PR updates the project template to version `${{ github.event.release.tag_name || 'latest' }}`. + This PR updates the project template to version `${{ steps.version.outputs.value }}`. ### Changes - Updated from template: ${{ github.repository }} - - Template version: ${{ github.event.release.tag_name || 'latest' }} - ${{ github.event.release.html_url && format('- Release notes: {0}', github.event.release.html_url) || '' }} + - Template version: ${{ steps.version.outputs.value }} + ${{ steps.version.outputs.release_url && format('- Release notes: {0}', steps.version.outputs.release_url) || '' }} ${{ steps.update.outputs.conflict_note }} @@ -97,5 +129,5 @@ jobs: --- *This PR was automatically created by the template update workflow.* - branch: template-update-${{ github.event.release.tag_name || github.run_number }} + branch: template-update-${{ steps.version.outputs.slug }} delete-branch: true