Skip to content

Conversation

@mshriver
Copy link
Contributor

@mshriver mshriver commented Nov 21, 2025

Summary by Sourcery

Update the npm publish workflow to derive the package version from the release tag and adjust package metadata accordingly.

Build:

  • Configure the GitHub Actions publish workflow to extract the version from the release tag and apply it to package.json before publishing.
  • Rename and simplify the publish workflow, and ensure tests and build run within the publish job prior to publishing to npm.

CI:

  • Remove the separate build job from the publish workflow, consolidating build and test steps into the npm publish job.

Chores:

  • Set the package.json version to a development placeholder that is overridden during the release publish workflow.

Copilot AI review requested due to automatic review settings November 21, 2025 16:26
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 21, 2025

Reviewer's Guide

Configures the npm publish GitHub Action to derive the package version dynamically from the release tag and sets a development placeholder version in package.json, while simplifying the workflow to a single publish job with explicit setup, test, build, and publish steps.

Flow diagram for dynamic versioning and npm publish job

flowchart LR
  A["Release created with tag (e.g. v2.3.4)"] --> B["GitHub Actions workflow triggered (Publish Package)"]
  B --> C["Step 1: Checkout repository (actions/checkout@v4)"]
  C --> D["Step 2: Setup Node.js (Node 20, yarn cache, npm registry)"]
  D --> E["Step 3: Install dependencies (yarn install --frozen-lockfile)"]
  E --> F["Step 4: Extract version from tag"]
  F --> G["Derive VERSION from GITHUB_REF, strip 'refs/tags/' and leading 'v'"]
  G --> H["Expose version as output: steps.get_version.outputs.version"]
  H --> I["Step 5: Update package.json version using npm version with derived VERSION"]
  I --> J["package.json updated from placeholder '0.0.0-development' to release version"]
  J --> K["Step 6: Run tests (yarn test)"]
  K --> L{"Tests pass?"}
  L -- "No" --> M["Job fails, package not built or published"]
  L -- "Yes" --> N["Step 7: Build (yarn build)"]
  N --> O["Step 8: Publish to npm (npm publish --provenance --access public) using NODE_AUTH_TOKEN"]
  O --> P["Package with dynamic version is available on npm registry"]
Loading

File-Level Changes

Change Details Files
Refactor npm publish GitHub Actions workflow to dynamically version the package from the release tag and streamline the CI steps.
  • Rename the workflow from a generic Node.js Package workflow to Publish Package.
  • Remove the separate build job and run all steps within the publish-npm job to simplify the workflow.
  • Update actions/setup-node usage with explicit name, pinned major version 4, Node 20, yarn caching, and npmjs registry URL.
  • Add a step to extract the version from the GitHub release tag, stripping an optional leading 'v', and expose it as a step output.
  • Add a step to update package.json version using npm version with no git tag creation and allowing same version to avoid tag conflicts.
  • Ensure tests and build run in sequence before publishing, using yarn test and yarn build.
  • Publish to npm with npm publish --provenance --access public using NODE_AUTH_TOKEN from secrets.
.github/workflows/npm-publish.yml
Set package.json to use a placeholder development version that will be overridden by the CI workflow.
  • Change the package.json version field to 0.0.0-development to indicate that actual release versions are injected by the publish workflow.
package.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Using npm version in a Yarn-based project will not update yarn.lock, which can lead to version drift between package.json and the lockfile; consider using yarn version or directly editing package.json (e.g., with jq) so your lockfile stays in sync.
  • Instead of manually parsing GITHUB_REF to derive the version, you can use the more robust github.ref_name context (${{ github.ref_name }}) to get the tag name without the refs/tags/ prefix.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using `npm version` in a Yarn-based project will not update `yarn.lock`, which can lead to version drift between `package.json` and the lockfile; consider using `yarn version` or directly editing `package.json` (e.g., with `jq`) so your lockfile stays in sync.
- Instead of manually parsing `GITHUB_REF` to derive the version, you can use the more robust `github.ref_name` context (`${{ github.ref_name }}`) to get the tag name without the `refs/tags/` prefix.

## Individual Comments

### Comment 1
<location> `.github/workflows/npm-publish.yml:26-33` </location>
<code_context>
+      - name: Install dependencies
+        run: yarn install --frozen-lockfile
+
+      - name: Extract version from tag
+        id: get_version
+        run: |
+          # Extract version from tag (remove 'v' prefix if present)
+          VERSION=${GITHUB_REF#refs/tags/}
+          VERSION=${VERSION#v}
+          echo "version=$VERSION" >> $GITHUB_OUTPUT
+          echo "Publishing version: $VERSION"
+
+      - name: Update package.json version
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Consider using github.ref_name and adding basic validation for the tag-derived version.

Parsing GITHUB_REF and stripping a leading 'v' is brittle and doesn’t protect against malformed tags. Using `${{ github.ref_name }}` removes the need to manually strip `refs/tags/`, and adding a simple pattern check (e.g., semver-like) would let the workflow fail fast if the tag format is unexpected, reducing the chance of publishing with an incorrect version.

```suggestion
      - name: Extract version from tag
        id: get_version
        run: |
          # Use the tag name directly and strip an optional leading 'v'
          VERSION="${{ github.ref_name }}"
          VERSION="${VERSION#v}"

          # Basic validation: ensure VERSION looks like a SemVer (e.g. 1.2.3, 1.2.3-beta.1)
          if ! echo "$VERSION" | grep -Eq '^[0-9]+(\.[0-9]+){2}(-[0-9A-Za-z.-]+)?$'; then
            echo "Error: Tag '${{ github.ref_name }}' does not contain a valid semver version (got '$VERSION')." >&2
            exit 1
          fi

          echo "version=$VERSION" >> "$GITHUB_OUTPUT"
          echo "Publishing version: $VERSION"
```
</issue_to_address>

### Comment 2
<location> `.github/workflows/npm-publish.yml:35-37` </location>
<code_context>
+          echo "version=$VERSION" >> $GITHUB_OUTPUT
+          echo "Publishing version: $VERSION"
+
+      - name: Update package.json version
+        run: |
+          npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version --allow-same-version
+
+      - name: Run tests
</code_context>

<issue_to_address>
**issue (bug_risk):** Guard against an empty or invalid version output before calling `npm version`.

If `steps.get_version.outputs.version` is ever empty or malformed, `npm version` will default to incrementing patch, which could publish an unintended version. Please add a guard (e.g., fail the step when the version is missing or invalid) so the workflow stops instead of proceeding with a wrong version.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Nov 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.19%. Comparing base (e3b3307) to head (54d4da6).
⚠️ Report is 3 commits behind head on main.

❌ Your project status has failed because the head coverage (60.19%) is below the target coverage (85.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #12      +/-   ##
==========================================
+ Coverage   53.26%   60.19%   +6.92%     
==========================================
  Files          51       51              
  Lines        2050     2050              
  Branches      512      524      +12     
==========================================
+ Hits         1092     1234     +142     
+ Misses        956      816     -140     
+ Partials        2        0       -2     
Flag Coverage Δ
unittests 60.19% <ø> (+6.92%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 12 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e3b3307...54d4da6. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements dynamic versioning for the npm package by extracting the version from Git release tags at publish time, rather than maintaining a static version in package.json.

  • Sets package.json version to 0.0.0-development placeholder
  • Extracts version from Git tag during release workflow
  • Updates package.json dynamically before publishing
  • Consolidates test and build steps into the publish workflow

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
package.json Changed version to 0.0.0-development placeholder for dynamic versioning
.github/workflows/npm-publish.yml Restructured workflow to extract version from release tag, update package.json dynamically, and removed separate build job

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mshriver mshriver force-pushed the npm-publish-tweaks branch 4 times, most recently from 1220907 to e5df33f Compare November 21, 2025 17:08
@mshriver mshriver merged commit 421281c into ibutsu:main Nov 21, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant