Skip to content

ci: derive latest-<major> dist-tag from the version in the Tag workflow - #12911

Merged
zkochan merged 1 commit into
mainfrom
fix-tag-workflow
Jul 10, 2026
Merged

zkochan merged 1 commit into
mainfrom
fix-tag-workflow

Conversation

@zkochan

@zkochan zkochan commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #12906.

The Tag workflow (update-latest.yml) hardcoded the latest-11 dist-tag and applied it unconditionally to whatever version was passed in. Each release branch carries its own copy with its own hardcoded major (release/10 hardcodes latest-10), so dispatching the workflow from the wrong branch applied the wrong line's tag — tagging 10.34.5 from main pointed latest-11 at a v10 release. (The registry tags themselves have already been repaired; this PR prevents a recurrence.)

This PR makes the workflow branch-agnostic and adds guardrails:

  • latest-<major> is now derived from the version input instead of being hardcoded, so it always lands on the correct release line no matter which branch the workflow is dispatched from.
  • A validation step fails the run before any dist-tag is touched when:
    • the version isn't an exact semver version,
    • the requested tag is latest-N with an N that doesn't match the version's major (the exact pnpm 10.34.5 is incorrectly tagged as @latest-11 #12906 scenario),
    • the requested tag is latest (the default input) but the version's major is older than the major currently tagged latest — catching the "forgot to change the default tag when tagging a backport" case.

The validation logic was exercised locally against the incident scenario (10.34.5 + latest-11 → fails), correct backport tagging (10.34.5 + latest-10 → passes), a normal release (11.2.0 + latest → passes), a backport with the forgotten default tag (10.34.5 + latest → fails), a prerelease (11.0.0-beta.1 + latest-11 → passes), and a malformed version (v11.2.0 → fails).

The same change should be applied to the workflow copy on release/10 (and future release branches), though with the derivation in place, dispatching from main now works correctly for any release line.

Squash Commit Body

The Tag workflow hardcoded the latest-11 dist-tag (each release branch
carried its own hardcoded major), so dispatching it from the wrong branch
applied the wrong line's tag: tagging 10.34.5 from main pointed latest-11
at a v10 release.

Derive latest-<major> from the version input instead, and fail fast when
the requested tag names a different major than the version, or when a
plain 'latest' tag would move backwards to an older major.

Closes pnpm/pnpm#12906.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pacquet/ port, or the description notes what still needs porting.
    (CI-workflow-only change — nothing to port.)

Written by an agent (Claude Code, claude-fable-5).

Summary by CodeRabbit

  • Bug Fixes

    • Improved release tag validation to ensure version tags follow the expected format.
    • Added safeguards to prevent the default latest tag from being moved to an older major release.
    • Automatically applies major-version tags consistently across supported package distributions.
  • Documentation

    • Updated guidance for tagging older release lines using the latest-<major> format.

The Tag workflow hardcoded the latest-11 dist-tag (each release branch
carried its own hardcoded major), so dispatching it from the wrong branch
applied the wrong line's tag: tagging 10.34.5 from main pointed latest-11
at a v10 release (#12906).

Derive latest-<major> from the version input instead, and fail fast when
the requested tag names a different major than the version, or when a
plain 'latest' tag would move backwards to an older major.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 10, 2026 14:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f273ceca-2e38-49ba-aa72-1824331fd403

📥 Commits

Reviewing files that changed from the base of the PR and between 7074b6b and 52bc452.

📒 Files selected for processing (1)
  • .github/workflows/update-latest.yml

📝 Walkthrough

Walkthrough

The release workflow updates tag guidance, validates semver and major-version tag consistency, prevents backward movement of latest, and derives matching major tags for both pnpm packages.

Changes

Registry tag safety

Layer / File(s) Summary
Validate and update registry tags
.github/workflows/update-latest.yml
The workflow validates version and tag inputs, checks the registry’s current latest major, and updates derived major tags for pnpm and @pnpm/exe without hardcoded version values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions
  participant NpmRegistry
  participant PnpmPackages
  GitHubActions->>GitHubActions: Validate version and requested tag
  GitHubActions->>NpmRegistry: Read current latest major with npm view
  NpmRegistry-->>GitHubActions: Return current latest dist-tag
  GitHubActions->>PnpmPackages: Add derived latest-major dist-tags
  GitHubActions->>PnpmPackages: Add requested non-latest-major tag when needed
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure latest-11 only points to pnpm 11 releases [#12906] ✅
Prevent pnpm 10 releases from advancing the unversioned latest tag backward [#12906] ✅
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-tag-workflow

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

ci: derive latest- dist-tag from version in Tag workflow

🐞 Bug fix ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Derive latest- dist-tag from the input version to avoid cross-branch tagging mistakes.
• Validate semver and tag/major consistency before mutating npm dist-tags.
• Prevent moving latest backwards to an older major; require latest-N for backports.
Diagram

graph TD
  A["workflow_dispatch inputs\n(version, tag)"] --> B["Validate version + tag"] --> C["Update npm dist-tags"] --> D[("npm registry")]
  C --> E["Publish to winget"]
  C --> F["Post announcements\n(Reddit, Mastodon)"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use a Node/github-script step with semver parsing
  • ➕ More robust semver handling (e.g., build metadata) than a shell regex
  • ➕ Cleaner logic and better testability via small JS functions
  • ➖ Slightly more moving parts (script step + Node code) than pure bash
  • ➖ Harder to debug inline than simple shell for some maintainers
2. Always compute the tag from version (remove free-form tag input)
  • ➕ Eliminates an entire class of operator error (no mismatched tag possible)
  • ➕ Simplifies validation and tagging logic
  • ➖ Reduces flexibility if maintainers need non-standard tags (e.g., experiments)
  • ➖ May require a separate workflow/path for special tagging cases

Recommendation: The PR’s approach is a good fit: deriving latest- from the version and adding a preflight validation step directly prevents the incident class (wrong branch / wrong major) with minimal workflow complexity. Consider switching the validation to a small Node step using a semver parser only if you need full semver support beyond the current regex (e.g., build metadata), but for current release/tagging practices the bash guardrails are likely sufficient.

Files changed (1) +37 / -5

Other (1) +37 / -5
update-latest.ymlDerive latest-<major> and validate inputs before updating npm dist-tags +37/-5

Derive latest-<major> and validate inputs before updating npm dist-tags

• Adds a validation step to ensure the provided version is exact semver and that the requested tag is compatible with the version’s major. Updates dist-tagging to compute 'latest-<major>' from the version and avoids re-applying the same tag twice, preventing cross-branch dispatches from corrupting dist-tags.

.github/workflows/update-latest.yml

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (1) 📎 Requirement gaps (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Remediation recommended

1. Historical workflow comment added 📘 Rule violation ⚙ Maintainability
Description
A newly added inline comment explains the change by referencing the prior implementation (`instead
of being hardcoded per release branch`) rather than documenting the current behavior/contract. This
can become stale and violates the rule against historical-implementation commentary in source.
Code

.github/workflows/update-latest.yml[R26-29]

+    # The latest-<major> tag is derived from the version instead of being
+    # hardcoded per release branch, so dispatching this workflow from the wrong
+    # branch cannot point a newer line's tag at an older release
+    # (https://github.com/pnpm/pnpm/issues/12906).
Evidence
The checklist forbids comments that describe historical/previous implementations. The added comment
explicitly contrasts current behavior with prior hardcoding (`instead of being hardcoded per release
branch`), which is historical framing in an inline source comment.

Rule 772199: Comments must describe current behavior, not historical implementations
.github/workflows/update-latest.yml[26-29]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The comment above `Validate version and tag` uses historical framing ("instead of being hardcoded per release branch") instead of documenting the current workflow behavior and invariants.

## Issue Context
Per compliance, comments should describe current behavior/constraints and avoid referencing past implementations, which can become outdated.

## Fix Focus Areas
- .github/workflows/update-latest.yml[26-29]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Tag option injection 🐞 Bug ⛨ Security
Description
The workflow_dispatch tag input is passed directly as an argument to npm dist-tag add, so values
that look like options (e.g. starting with --) can be interpreted by npm as CLI flags instead of a
dist-tag name, causing unintended behavior while the NPM auth token is set for the step.
Code

.github/workflows/update-latest.yml[R64-66]

+        if [ "$TAG" != "latest-${MAJOR}" ]; then
+          npm dist-tag add "pnpm@${VERSION}" "${TAG}"
+          npm dist-tag add "@pnpm/exe@${VERSION}" "${TAG}"
Evidence
TAG comes from workflow_dispatch input and is only special-cased for latest/latest-* in
validation; otherwise it is forwarded verbatim into npm dist-tag add. The repo’s security guide
explicitly calls out command/argument injection and not passing attacker-controlled values as
executable flags.

.github/workflows/update-latest.yml[30-54]
.github/workflows/update-latest.yml[55-67]
REVIEW_GUIDE.md[54-58]
REVIEW_GUIDE.md[76-79]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`TAG` is user-provided (`workflow_dispatch`) and is forwarded to `npm dist-tag add` without validation. Shell quoting prevents *shell* injection, but it does not prevent npm from parsing `TAG` as an option when it begins with `-`/`--`, which can change command behavior unexpectedly.

### Issue Context
This workflow runs with an npm auth token configured in the environment for the dist-tag update step, so we should treat arguments as potentially hostile/accident-prone and ensure they cannot be interpreted as executable flags.

### Fix Focus Areas
- .github/workflows/update-latest.yml[30-67]

### Suggested fix
1. Add explicit validation for `TAG` (for *all* cases), e.g.:
  - Reject tags starting with `-`.
  - Enforce a conservative dist-tag regex like `^[A-Za-z0-9][A-Za-z0-9._-]*$`.
2. Additionally (or alternatively), pass `--` to terminate option parsing if supported by npm for this command, e.g. `npm dist-tag add -- "pnpm@${VERSION}" "${TAG}"`.
3. Keep the existing `latest-*` major-match guard on top of the generic validation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Fail-open latest major parse 🐞 Bug ☼ Reliability
Description
The rollback protection for the plain latest tag compares MAJOR against CURRENT_LATEST_MAJOR
without validating that CURRENT_LATEST_MAJOR is a non-empty integer; if npm view outputs
something unexpected (empty/non-numeric), the numeric test errors and the guard can be skipped.
Code

.github/workflows/update-latest.yml[R48-50]

+            CURRENT_LATEST_MAJOR="$(npm view pnpm dist-tags.latest | cut -d . -f 1)"
+            if [ "$MAJOR" -lt "$CURRENT_LATEST_MAJOR" ]; then
+              echo "::error::Refusing to move the latest tag back from v${CURRENT_LATEST_MAJOR} to ${VERSION}. Use latest-${MAJOR} to tag an older release line."
Evidence
The workflow assigns CURRENT_LATEST_MAJOR from npm view ... | cut ... and immediately uses it in
a numeric comparison, but never checks that the parsed value is numeric. This creates a brittle
guard that can fail open when parsing fails or outputs unexpected content.

.github/workflows/update-latest.yml[47-53]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The `latest` rollback guard relies on parsing `CURRENT_LATEST_MAJOR` from `npm view pnpm dist-tags.latest`, then performing a numeric `-lt` comparison. If the parse yields an empty or non-numeric value, the check won’t reliably enforce the intended “don’t move latest backwards” constraint.

### Issue Context
This is intended as a safety rail specifically to prevent accidental tagging mistakes. In guardrail code, parse failures should fail closed (stop the workflow) rather than silently bypassing protection.

### Fix Focus Areas
- .github/workflows/update-latest.yml[47-53]

### Suggested fix
1. Capture the full value first, then parse and validate:
  - `CURRENT_LATEST_VERSION="$(npm view pnpm dist-tags.latest)"`
  - `CURRENT_LATEST_MAJOR="${CURRENT_LATEST_VERSION%%.*}"`
2. Validate `CURRENT_LATEST_MAJOR` is an integer, else `::error::...` and `exit 1`.
3. (Optional hardening) Normalize both majors to base-10 before comparing to avoid edge cases with leading zeros, e.g. `MAJOR=$((10#$MAJOR))` and `CURRENT_LATEST_MAJOR=$((10#$CURRENT_LATEST_MAJOR))`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 10, 2026
@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Add default case for tag validation

Add a default case to the tag validation block to error out on unsupported tag
formats.

.github/workflows/update-latest.yml [34-54]

 run: |
   if ! printf '%s\n' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[.0-9A-Za-z-]+)?$'; then
     echo "::error::Version must be an exact semver version like 11.2.0. Got: ${VERSION}"
     exit 1
   fi
   MAJOR="${VERSION%%.*}"
   case "$TAG" in
     latest-*)
       if [ "$TAG" != "latest-${MAJOR}" ]; then
         echo "::error::Tag ${TAG} does not match the major version of ${VERSION}. Expected latest-${MAJOR}."
         exit 1
       fi
       ;;
     latest)
       CURRENT_LATEST_MAJOR="$(npm view pnpm dist-tags.latest | cut -d . -f 1)"
       if [ "$MAJOR" -lt "$CURRENT_LATEST_MAJOR" ]; then
         echo "::error::Refusing to move the latest tag back from v${CURRENT_LATEST_MAJOR} to ${VERSION}. Use latest-${MAJOR} to tag an older release line."
         exit 1
       fi
       ;;
+    *)
+      echo "::error::Unsupported tag format: ${TAG}. Allowed: 'latest' or 'latest-<major>'."
+      exit 1
+      ;;
   esac
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: Explicitly failing on unsupported tags prevents the subsequent step from erroneously applying the latest-<major> tag to pre-release or custom tags, avoiding mislabeling versions in the registry.

Medium
General
Enable strict shell error handling

Enable strict shell options like set -euo pipefail at the start of the
validation script.

.github/workflows/update-latest.yml [34-35]

 run: |
+  set -euo pipefail
   if ! printf '%s\n' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[.0-9A-Za-z-]+)?$'; then
  • Apply / Chat
Suggestion importance[1-10]: 2

__

Why: GitHub Actions already runs bash steps with set -eo pipefail by default, making this suggestion mostly redundant aside from the -u flag.

Low
Guard derived tag on latest inputs

Restrict the addition of latest- dist-tags to requests specifically asking for
latest-style tags.

.github/workflows/update-latest.yml [61-67]

 MAJOR="${VERSION%%.*}"
-npm dist-tag add "pnpm@${VERSION}" "latest-${MAJOR}"
-npm dist-tag add "@pnpm/exe@${VERSION}" "latest-${MAJOR}"
-if [ "$TAG" != "latest-${MAJOR}" ]; then
-  npm dist-tag add "pnpm@${VERSION}" "${TAG}"
-  npm dist-tag add "@pnpm/exe@${VERSION}" "${TAG}"
+if [[ "$TAG" == "latest" || "$TAG" == latest-* ]]; then
+  npm dist-tag add "pnpm@${VERSION}" "latest-${MAJOR}"
+  npm dist-tag add "@pnpm/exe@${VERSION}" "latest-${MAJOR}"
 fi
+npm dist-tag add "pnpm@${VERSION}" "${TAG}"
+npm dist-tag add "@pnpm/exe@${VERSION}" "${TAG}"
  • Apply / Chat
Suggestion importance[1-10]: 2

__

Why: While it guards against custom tags, the proposed implementation removes the check that prevents executing duplicate tag additions when the input tag is latest-<major>, leading to redundant API calls.

Low
  • More

@zkochan
zkochan merged commit c2248eb into main Jul 10, 2026
25 checks passed
@zkochan
zkochan deleted the fix-tag-workflow branch July 10, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm 10.34.5 is incorrectly tagged as @latest-11

2 participants