Skip to content

feat: add publishing npm package flow - #139

Open
limitofzero wants to merge 63 commits into
mainfrom
feat/implement-npm-publish-flow
Open

feat: add publishing npm package flow#139
limitofzero wants to merge 63 commits into
mainfrom
feat/implement-npm-publish-flow

Conversation

@limitofzero

@limitofzero limitofzero commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a publishing pipeline for @cowprotocol/solana-settlement-client (the TS client generated from the settlement program's IDL) and finishes making its package.json actually publishable — the base branch's version had a non-scoped name, no publishConfig, and main pointing at raw .ts source with no build step producing anything importable.

New workflows

auto-release.yml — triggered on push to main. Diffs Cargo.toml's version against the previous commit; a no-op if unchanged (regular PRs don't touch it). If changed:

  • Fails immediately if programs/settlement/idl/client/js/package.json's version wasn't bumped to match — before creating anything, since an immutable tag pinned to a commit that can never actually publish would be worse than failing loudly here.
  • Creates the GitHub Release, pinned to the triggering commit (--target "$GITHUB_SHA").
  • Explicitly dispatches publish-npm.yml (gh workflow run --ref "$tag"). This has to be explicit: GitHub suppresses the release event for releases created by GITHUB_TOKEN (anti-recursion protection), so the normal release: published trigger would never fire otherwise. Dispatching against the tag (not main) keeps the same commit pinned through to the build.

publish-npm.yml — two jobs. build: checks out the tagged commit, runs just build-js-client (Codama codegen + tsup) and just test-js-client, re-verifies the tag matches the package version, and writes a review summary (npm pack --dry-run --ignore-scripts output, plus a diff of dependencies against the currently-published version). publish: gated behind the npm-publish GitHub Environment's required-reviewer approval, then runs npm publish --provenance --access public --ignore-scripts. Authentication is npm Trusted Publishing (OIDC) — no long-lived npm token is stored or used in the normal flow; NPM_TOKEN is only a bootstrap fallback for the package's very first publish (see setup section below). --ignore-scripts on both steps means no lifecycle script ever runs with credentials in scope — what gets published is exactly the artifact reviewed in build.

package.json / Justfile / ci.yml

  • Renamed the package cow-solana-settlement-client@cowprotocol/solana-settlement-client (scoped under the org, matching @cowprotocol/contracts on the EVM side).
  • Added publishConfig, repository, author; main/types now point at dist/index.js/dist/index.d.ts (the actual build output) instead of raw src/index.ts.
  • Added a build script (tsup) and a tsup devDependency — there was no way to produce a distributable artifact before this.
  • Justfile: added build-js-client (depends on the existing generate-js-client), since nothing built the publishable package before.
  • ci.yml: added a "Build JS client" step to the existing test-js-client job, so a broken build is caught on every PR, not only at release time.
  • .gitignore: added dist/ and .idea/.

Manual setup required before this can run for real (repo admin, one-time)

  • Create the npm-publish GitHub Environment with required reviewers.
  • Trusted Publisher configuration lives on the package's own npmjs.com settings page, which doesn't exist until the package has been published at least once — so bootstrap it:
    1. Generate an npm access token (short-lived is fine, it's only needed once) and add it as the NPM_TOKEN secret on the npm-publish environment.
    2. Let one release run through the normal flow end-to-end (bump PR → auto-release.ymlpublish-npm.yml → approve) — this publish uses NPM_TOKEN.
    3. On npmjs.com, open the now-existing package's settings and add a Trusted Publisher for this repo, workflow publish-npm.yml, and environment npm-publish.
    4. Delete the NPM_TOKEN secret. Every publish after this point authenticates via OIDC automatically — no workflow changes needed.
  • Confirm Settings → Actions → General grants the default GITHUB_TOKEN read/write permissions (needed for auto-release.yml to create releases and dispatch workflows).

kaze-cow and others added 30 commits July 28, 2026 17:19
using newer version of litesvm nodejs lib, and settlement seed now has
to be imported dynamically from the IDL because of version bumping
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
* add comments for settlement instruction and validate match
* simplify superfluous comments in the IDL in general
* switch to using `LazyLock` and update call sites
it increases the amount of code overall, but it puts us in the right
trajectory to be effectively generating parts of the IDL from rust.
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
kaze-cow and others added 7 commits September 2, 2026 15:57
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
…ies-for' of github.com:cowprotocol/solana-programs into kaze/sc-255-write-idl-and-generate-corresponding-libraries-for
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
@limitofzero limitofzero changed the title feat: add publish github flow feat: add npm packages flow Sep 2, 2026
@limitofzero limitofzero changed the title feat: add npm packages flow feat: add publishing npm package flow Sep 2, 2026
kaze-cow and others added 4 commits September 2, 2026 19:37
…ies-for' of github.com:cowprotocol/solana-programs into kaze/sc-255-write-idl-and-generate-corresponding-libraries-for
@socket-security

socket-security Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​tsup@​8.5.1981009583100

View full report

@limitofzero limitofzero self-assigned this Sep 2, 2026
@limitofzero
limitofzero marked this pull request as ready for review September 2, 2026 20:02
@limitofzero
limitofzero requested a review from a team as a code owner September 2, 2026 20:02

@kaze-cow kaze-cow 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.

Its difficult to review this PR in completeness because I wasn't able to run a test release myself and its mostly CI. If there is some way we could have a call or something to review the release process that would be great.

considering the rest of our releases in this repo don't currently use an automated release, I am questioning whether we should be going through all the effort to have it for node.js

Comment thread README.md Outdated
Comment on lines +132 to +134
Publishing itself requires a manual approval in the `npm-publish` GitHub Environment. Before approving, check the job summary the workflow posts: it lists the exact tarball contents about to be published and a dependency diff against the previously published version. Approve only if both look as expected for the changes in this release.

Authentication to npm uses [Trusted Publishing](https://docs.npmjs.com/trusted-publishers) (OIDC) — no long-lived npm token is stored. This requires a one-time setup on npmjs.com *after* the package's first publish (a Trusted Publisher is configured on the package's own settings page, so it can't be set up before the package exists): add a Trusted Publisher for this exact repo, `publish-npm.yml`, and the `npm-publish` environment, then delete the `NPM_TOKEN` secret — it's a bootstrap-only fallback for that first publish.

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.

i am not an expert on the latest patterns and strategies in npm publishing. I actually find myself to be more confused after reading these instructions because

For instructions relating to steps that need to be completed one time (ex. after package first publish with the trusted publisher setup), this doesn't need to be documented.

I don't know what a "GitHub Environment" is, and its not explained . While I see its explained on the linked trusted publishing document, maybe just best to simplify this second paragraph to generally say "Authentication to npm uses trusted publishing. Follow the instructions there to set up after first release" or so

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fair, I only did half of this. Simplified the github env bit but left the one time bootstrap steps in place since I wasn't sure where else they should live. Where would you rather they go, just drop them entirely and rely on the linked Trusted Publishing docs plus whoever does the bootstrap figuring it out from there or move them somewhere that isn't the permanent readme, like the PR description or a comment in the workflow file? I think it could be fully removed since everything will be configured manually for the first release

Comment thread README.md Outdated
Comment thread programs/settlement/idl/client/js/pnpm-workspace.yaml
],
"peerDependencies": {
"@solana/kit": "^6.10.0"
"@solana/kit": "^8.0.0"

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.

Just for our reference, what are your thoughts on peer dependencies? we have a conversation on the original thread on whether we should have them or not (the version bump here is actually being applied there as well)

cc @fedgiac

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good question, and I don't have a strong opinion here either. The case for peer is if a consumer also uses @solana/kit directly, you want one shared instance so types like Address/TransactionSigner line up. The case against, is peer deps have caused real pain before and version drift mostly shows up as install failures for consumers.
right now nothing actually consumes this package yet, cow-sdk/cowswap owns Solana code is still on classic web3.js, not kit, so the shared instance problem doesn't exist in practice today. Given that I'm leaning toward just making it a regular dependency unless either of you sees a concrete reason to keep it as peer.

@fedgiac what do you think, still feel the same way as on #73?

Comment thread programs/settlement/idl/client/js/package.json Outdated
Comment thread .github/workflows/publish-npm.yml Outdated
Comment thread .github/workflows/publish-npm.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment on lines 68 to 74
env:
COREPACK_ENABLE_DOWNLOAD_PROMPT: "0"
run: just build-js-client
- name: Test JS client
env:
COREPACK_ENABLE_DOWNLOAD_PROMPT: "0"
run: just test-js-client

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.

Comment thread .github/workflows/auto-release.yml
Comment thread .github/workflows/auto-release.yml
TypeScript/JavaScript client for the CoW Protocol Solana settlement program, generated from its IDL ([`cow_settlement.json`](../../cow_settlement.json)) via [Codama](https://github.com/codama-idl/codama), built on [`@solana/kit`](https://github.com/anza-xyz/kit).

> [!CAUTION]
> The settlement program is a work in progress and **not ready for production use**. See the [repository README](../../../../../README.md) for details.

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.

this link doesn't lead anywhere in the case that the npm package is published. would be better to link to https://github.com/cowprotocol/solana-programs/blob/main/README.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch, replaced all relative links which I was able to find, thx!

Comment on lines +10 to +18
```typescript
import {
getCreateOrderInstructionAsync,
resolveOrderPda,
OrderKind,
encodeFlags,
COW_SETTLEMENT_PROGRAM_ADDRESS,
} from "@cowprotocol/solana-settlement-client";
```

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.

for more completeness, showing a very tiny example code of construction a createOrder call or so would be nice here. would also put arnyone using the lib on the road of being able to execute other instructions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added in readme

Base automatically changed from kaze/sc-255-write-idl-and-generate-corresponding-libraries-for to main September 7, 2026 11:03
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.

2 participants