From 01199a16ca101675f7894bea3ce929526f9ad77f Mon Sep 17 00:00:00 2001 From: Chaminda Divitotawela Date: Tue, 1 Dec 2026 11:11:19 +1000 Subject: [PATCH 1/2] feat(update-release-changelog): skip the update when the release tag exists The update-release-changelog action runs on every push to a release branch. Once the release is tagged it has shipped, and auto-changelog rejects the update with "Current version already has a tag", so any later push failed the run. Those pushes are housekeeping, not new changes: the merge of the changelog PR itself, or a merge of `stable` into the branch. Add a `skip-if-tag-exists` input, defaulting to `true`. A new first step derives `v` from a `release/X.Y.Z` or `release/X.Y.Z-ota` branch name (the pattern the updater itself accepts) and checks for that tag with one GitHub API call. If the tag exists, the remaining steps are skipped and the run finishes successfully, with a notice and a job summary that report how many commits sit on the branch after the tag. Set `skip-if-tag-exists: 'false'` to keep the previous behaviour. The skip applies whenever the tag exists, including for a release that is not the most recent one, which auto-changelog did not reject. The check runs before the full-history checkout, so a skipped run does not pay for it. It fails open: a branch name it cannot parse, or any API error other than a 404, logs a warning and runs the update as before. The branch name goes through `env:` and a strict regex, never into the shell directly, text echoed into workflow commands has newlines stripped, and the step blanks AI_ANALYZER_LITELLM_KEY like the other steps that do not need it. Refs: INFRA-3151 Co-Authored-By: Claude Sonnet 5.5 --- .../update-release-changelog/action.yml | 63 ++++++++++++++++++- CHANGELOG.md | 9 +++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/.github/actions/update-release-changelog/action.yml b/.github/actions/update-release-changelog/action.yml index d5003fa2..2a119e93 100644 --- a/.github/actions/update-release-changelog/action.yml +++ b/.github/actions/update-release-changelog/action.yml @@ -15,12 +15,68 @@ inputs: github-token: required: true description: 'GitHub token with write access to the invoking repository and read access to planning resources.' + skip-if-tag-exists: + required: false + default: 'true' + description: >- + Skip the changelog update, and finish successfully, when the release tag + (v, derived from the release branch name) already exists. A tagged + release has already shipped, and `auto-changelog` rejects the update for it. + The skip is reported in the job summary, with the number of commits on the + branch after the tag. Set to 'false' to always run the update. runs: using: composite steps: - # Step 1: Checkout invoking repository (metamask-mobile | metamask-extension) + # Step 1: Once a release is tagged it has shipped, and `auto-changelog` fails when asked to + # update the changelog for it. Skip instead of failing. This runs before the checkout (a + # full-history fetch that can take minutes) and only needs one API call. It fails open: any + # problem checking the tag falls back to running the update, which is the behaviour without + # this step. + - name: Check whether the release tag already exists + id: tag-check + if: ${{ inputs.skip-if-tag-exists == 'true' }} + shell: bash + env: + AI_ANALYZER_LITELLM_KEY: '' + GH_TOKEN: ${{ inputs.github-token }} + RELEASE_BRANCH: ${{ inputs.release-branch }} + REPOSITORY: ${{ github.repository }} + run: | + set -euo pipefail + + # release/8.20.2-ota and release/13.59.0 -> v8.20.2 and v13.59.0 (`-ota` is a + # branch-name convention only). The pattern matches the one the updater accepts + # (parseReleaseBranch in .github/scripts/release-version-utils.mts). + # Strip newlines before echoing untrusted text, so it cannot start a workflow command. + SAFE_BRANCH="${RELEASE_BRANCH//[$'\r\n']/ }" + if [[ ! "$RELEASE_BRANCH" =~ ^release/([0-9]+\.[0-9]+\.[0-9]+)(-ota)?$ ]]; then + echo "::notice::Cannot derive a version from '${SAFE_BRANCH}'; not checking for an existing tag." + echo "skip=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + TAG="v${BASH_REMATCH[1]}" + + # `git/ref/` matches one exact ref. (`git/refs/` would match every tag with this prefix.) + STDERR_FILE="$(mktemp)" + if gh api "repos/${REPOSITORY}/git/ref/tags/${TAG}" --silent 2>"$STDERR_FILE"; then + echo "skip=true" >> "$GITHUB_OUTPUT" + # Informational and best effort: the number of commits on the branch after the tag + # (usually the changelog PR merge or a merge of `stable`), so a skipped run is not silent. + AHEAD="$(gh api "repos/${REPOSITORY}/compare/${TAG}...${RELEASE_BRANCH}" --jq .ahead_by 2>/dev/null || echo unknown)" + echo "::notice::Tag ${TAG} already exists, so the release has shipped. Skipping the changelog update. Commits on ${SAFE_BRANCH} after the tag: ${AHEAD}." + echo "Skipped the changelog update for \`${SAFE_BRANCH}\`: tag \`${TAG}\` already exists. Commits on the branch after the tag: ${AHEAD}." >> "$GITHUB_STEP_SUMMARY" + elif grep -q 'HTTP 404' "$STDERR_FILE"; then + echo "skip=false" >> "$GITHUB_OUTPUT" + echo "Tag ${TAG} does not exist yet. Updating the changelog." + else + echo "::warning::Could not check whether tag ${TAG} exists; updating the changelog anyway. $(head -c 300 "$STDERR_FILE" | tr '\r\n' ' ')" + echo "skip=false" >> "$GITHUB_OUTPUT" + fi + + # Step 2: Checkout invoking repository (metamask-mobile | metamask-extension) - name: Checkout invoking repository + if: ${{ steps.tag-check.outputs.skip != 'true' }} uses: actions/checkout@v6 env: AI_ANALYZER_LITELLM_KEY: '' @@ -30,6 +86,7 @@ runs: token: ${{ inputs.github-token }} - name: Set up Node 24 for release changelog automation + if: ${{ steps.tag-check.outputs.skip != 'true' }} uses: actions/setup-node@v6 env: AI_ANALYZER_LITELLM_KEY: '' @@ -39,6 +96,7 @@ runs: # Corepack resolves Yarn from the working directory, so install from the # github-tools root to use its own pinned Yarn and lockfile. - name: Install github-tools dependencies + if: ${{ steps.tag-check.outputs.skip != 'true' }} shell: bash working-directory: ${{ github.action_path }}/../../.. env: @@ -49,6 +107,7 @@ runs: corepack yarn install --immutable - name: Update changelog branch + if: ${{ steps.tag-check.outputs.skip != 'true' }} shell: bash env: GITHUB_TOKEN: ${{ inputs.github-token }} @@ -67,7 +126,7 @@ runs: "$REPOSITORY_URL" - name: Upload clean-room proofread report - if: ${{ always() && hashFiles('.tmp/release-changelog-ai/*.json') != '' }} + if: ${{ always() && steps.tag-check.outputs.skip != 'true' && hashFiles('.tmp/release-changelog-ai/*.json') != '' }} uses: actions/upload-artifact@v7 env: AI_ANALYZER_LITELLM_KEY: '' diff --git a/CHANGELOG.md b/CHANGELOG.md index 186a7ca4..fefd4523 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add a `skip-if-tag-exists` input to the `update-release-changelog` action, defaulting to `true` + - When the release tag (`v`, derived from a `release/X.Y.Z` or `release/X.Y.Z-ota` branch name) already exists, the action skips the update and finishes successfully, instead of failing in `auto-changelog` with "Current version already has a tag". Pushes that land after tagging, such as the merge of the changelog PR or a merge of `stable`, no longer cause failed runs. + - The skip is reported in the job summary, with the number of commits on the branch after the tag. + - The skip applies whenever the tag exists, including a release that is not the most recent one. `auto-changelog` only rejected the most recent tag, so pushes to an older tagged release branch are now skipped too. + - The check runs before the repository checkout, uses one GitHub API call, and falls back to running the update if the tag cannot be checked. + - Set `skip-if-tag-exists: 'false'` to keep the previous behaviour. + ## [1.28.0] ### Added From f79de22ecf4e366bb31b7f6515442bcdc1e003fa Mon Sep 17 00:00:00 2001 From: Chaminda Divitotawela Date: Tue, 1 Dec 2026 11:16:11 +1000 Subject: [PATCH 2/2] docs(changelog): link the skip-if-tag-exists entry to its PR Refs: INFRA-3151 Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fefd4523..e3000a9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Add a `skip-if-tag-exists` input to the `update-release-changelog` action, defaulting to `true` +- Add a `skip-if-tag-exists` input to the `update-release-changelog` action, defaulting to `true` ([#351](https://github.com/MetaMask/github-tools/pull/351)) - When the release tag (`v`, derived from a `release/X.Y.Z` or `release/X.Y.Z-ota` branch name) already exists, the action skips the update and finishes successfully, instead of failing in `auto-changelog` with "Current version already has a tag". Pushes that land after tagging, such as the merge of the changelog PR or a merge of `stable`, no longer cause failed runs. - The skip is reported in the job summary, with the number of commits on the branch after the tag. - The skip applies whenever the tag exists, including a release that is not the most recent one. `auto-changelog` only rejected the most recent tag, so pushes to an older tagged release branch are now skipped too.