Skip to content

Publish the CLI from CI when main gains a new version - #10

Merged
Amartuvshins0404 merged 2 commits into
mainfrom
ci-publish-on-merge
Oct 21, 2026
Merged

Amartuvshins0404 merged 2 commits into
mainfrom
ci-publish-on-merge

Conversation

@Amartuvshins0404

@Amartuvshins0404 Amartuvshins0404 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Merging to main publishes @erxes/create-plugin from GitHub Actions when package.json has a version npm does not already have. 0.2.1 is already public, so this merge skips the upload.
  • Generated Yarn projects set enableImmutableInstalls: false, so the first yarn install can create yarn.lock while CI=true. Image builds still use yarn install --immutable.

Verification

  • pnpm test: 54 passed.
  • A Yarn 4.18.1 install with CI=true and enableImmutableInstalls: false created yarn.lock.
  • No local npm publish.

Summary by Sourcery

Publish new package versions from main through CI and make generated Yarn projects initialize reliably in CI.

New Features:

  • Publish the package from CI after successful merges to main when the package version is not already available on npm.

Bug Fixes:

  • Allow generated Yarn projects to create their initial lockfile in CI environments.

CI:

  • Add a guarded GitHub Actions publish job that skips versions already present on npm.

Documentation:

  • Document the main-branch npm publishing flow and distinguish it from tagged standalone binary releases.

Tests:

  • Verify generated Yarn projects disable immutable installs.

Amartuvshin Surenjav added 2 commits October 21, 2026 11:11
Merging to main publishes package.json when that version is not
already on npm. The automation token is the NPM_PUBLISH secret.
Yarn treats CI=true as an immutable install. Generated projects
now set enableImmutableInstalls to false so yarn install can
write yarn.lock. Docker still passes --immutable.
@sourcery-ai

sourcery-ai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR adds an idempotent GitHub Actions publish job for versioned merges to main, updates documentation for the npm and binary release workflows, and adjusts generated Yarn configuration so initial CI installs can create yarn.lock files.

Sequence diagram for CI npm publishing on main

sequenceDiagram
    participant GitHub as GitHub Actions
    participant Checks as deliverables and check jobs
    participant NPM as npm registry
    participant Package as @erxes/create-plugin

    GitHub->>Checks: Complete required jobs
    GitHub->>GitHub: Check push to refs/heads/main
    GitHub->>Package: Read package.json name and version
    GitHub->>NPM: npm view name@version version
    alt Version already exists
        NPM-->>GitHub: Return published version
        GitHub-->>GitHub: Skip publish
    else Version is absent
        NPM-->>GitHub: Return not found
        GitHub->>NPM: npm publish --access public
        NPM-->>GitHub: Publish package version
    end
Loading

Flow diagram for generated Yarn CI installation

flowchart TD
    A[Generate Yarn project] --> B[Write .yarnrc.yml]
    B --> C[enableImmutableInstalls: false]
    C --> D[yarn install with CI=true]
    D --> E[Create initial yarn.lock]
    F[Image build] --> G[yarn install --immutable]
Loading

File-Level Changes

Change Details Files
Add an idempotent main-branch CI job that publishes the package to npm only when the declared version is absent.
  • Run after deliverable and validation jobs on pushes to main.
  • Configure Node, pnpm, npm registry access, and frozen dependency installation.
  • Check npm for the exact package/version before publishing with the CI token.
  • Skip already-published versions and instruct maintainers to bump package.json.
.github/workflows/ci.yml
Document the new CI-driven npm publishing flow separately from tagged binary releases.
  • Explain that merging a version bump publishes the package and requires no local publish or one-time password.
  • Clarify that version tags remain the trigger for standalone GitHub binary releases.
README.md
Allow generated Yarn projects to create their initial lockfile under CI while retaining immutable installs for image builds.
  • Set enableImmutableInstalls to false in generated .yarnrc.yml files.
  • Add a scaffold assertion covering the generated Yarn configuration.
src/generated.ts
test/scaffold.test.ts

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

@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f3dc7488-14c6-4291-a9c4-7d24d6ee3fe2
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".github/workflows/ci.yml" line_range="61" />
<code_context>
+          set -euo pipefail
+          name=$(node -p "require('./package.json').name")
+          version=$(node -p "require('./package.json').version")
+          if npm view "${name}@${version}" version >/dev/null 2>&1; then
+            echo "${name}@${version} is already on npm."
+            echo "Bump package.json in the merged pull request to publish a new version."
</code_context>
<issue_to_address>
**Registry errors look like missing versions**

When the npm lookup fails for a reason other than the version being absent while that version is already published, the publish step treats every `npm view` failure as an absent version and proceeds to publish. If the version already exists but the lookup fails transiently, `npm publish` reports a version conflict and the CI job fails instead of skipping the existing version.

Distinguish registry not-found responses from other lookup errors, and retry or fail with the lookup error before publishing.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and a push to main can publish the package to the public npm registry using NPM_PUBLISH; a mistakenly merged version can therefore become publicly installable and cannot be replaced under the same version. Reverting stops future publishes but does not remove that published package.

Blocking findings: .github/workflows/ci.yml:61


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread .github/workflows/ci.yml
set -euo pipefail
name=$(node -p "require('./package.json').name")
version=$(node -p "require('./package.json').version")
if npm view "${name}@${version}" version >/dev/null 2>&1; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Registry errors look like missing versions

When the npm lookup fails for a reason other than the version being absent while that version is already published, the publish step treats every npm view failure as an absent version and proceeds to publish. If the version already exists but the lookup fails transiently, npm publish reports a version conflict and the CI job fails instead of skipping the existing version.

Distinguish registry not-found responses from other lookup errors, and retry or fail with the lookup error before publishing.

Prompt for AI agents
In `.github/workflows/ci.yml` at line 61:

**Registry errors look like missing versions**

When the npm lookup fails for a reason other than the version being absent while that version is already published, the publish step treats every `npm view` failure as an absent version and proceeds to publish. If the version already exists but the lookup fails transiently, `npm publish` reports a version conflict and the CI job fails instead of skipping the existing version.

Distinguish registry not-found responses from other lookup errors, and retry or fail with the lookup error before publishing.

@Amartuvshins0404
Amartuvshins0404 merged commit 76e4d2f into main Oct 21, 2026
17 of 18 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