feat: add publishing npm package flow - #139
Conversation
…ing-libraries-for
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>
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>
…ies-for' of github.com:cowprotocol/solana-programs into kaze/sc-255-write-idl-and-generate-corresponding-libraries-for
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
kaze-cow
left a comment
There was a problem hiding this comment.
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
| 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| ], | ||
| "peerDependencies": { | ||
| "@solana/kit": "^6.10.0" | ||
| "@solana/kit": "^8.0.0" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
| 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 |
There was a problem hiding this comment.
| 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
good catch, replaced all relative links which I was able to find, thx!
| ```typescript | ||
| import { | ||
| getCreateOrderInstructionAsync, | ||
| resolveOrderPda, | ||
| OrderKind, | ||
| encodeFlags, | ||
| COW_SETTLEMENT_PROGRAM_ADDRESS, | ||
| } from "@cowprotocol/solana-settlement-client"; | ||
| ``` |
There was a problem hiding this comment.
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.
… in links by absolute one
Description
Adds a publishing pipeline for
@cowprotocol/solana-settlement-client(the TS client generated from the settlement program's IDL) and finishes making itspackage.jsonactually publishable — the base branch's version had a non-scoped name, nopublishConfig, andmainpointing at raw.tssource with no build step producing anything importable.New workflows
auto-release.yml— triggered onpushtomain. DiffsCargo.toml'sversionagainst the previous commit; a no-op if unchanged (regular PRs don't touch it). If changed: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.--target "$GITHUB_SHA").publish-npm.yml(gh workflow run --ref "$tag"). This has to be explicit: GitHub suppresses thereleaseevent for releases created byGITHUB_TOKEN(anti-recursion protection), so the normalrelease: publishedtrigger would never fire otherwise. Dispatching against the tag (notmain) keeps the same commit pinned through to the build.publish-npm.yml— two jobs.build: checks out the tagged commit, runsjust build-js-client(Codama codegen +tsup) andjust test-js-client, re-verifies the tag matches the package version, and writes a review summary (npm pack --dry-run --ignore-scriptsoutput, plus a diff of dependencies against the currently-published version).publish: gated behind thenpm-publishGitHub Environment's required-reviewer approval, then runsnpm 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_TOKENis only a bootstrap fallback for the package's very first publish (see setup section below).--ignore-scriptson both steps means no lifecycle script ever runs with credentials in scope — what gets published is exactly the artifact reviewed inbuild.package.json/Justfile/ci.ymlcow-solana-settlement-client→@cowprotocol/solana-settlement-client(scoped under the org, matching@cowprotocol/contractson the EVM side).publishConfig,repository,author;main/typesnow point atdist/index.js/dist/index.d.ts(the actual build output) instead of rawsrc/index.ts.buildscript (tsup) and atsupdevDependency — there was no way to produce a distributable artifact before this.Justfile: addedbuild-js-client(depends on the existinggenerate-js-client), since nothing built the publishable package before.ci.yml: added a "Build JS client" step to the existingtest-js-clientjob, so a broken build is caught on every PR, not only at release time..gitignore: addeddist/and.idea/.Manual setup required before this can run for real (repo admin, one-time)
npm-publishGitHub Environment with required reviewers.NPM_TOKENsecret on thenpm-publishenvironment.auto-release.yml→publish-npm.yml→ approve) — this publish usesNPM_TOKEN.publish-npm.yml, and environmentnpm-publish.NPM_TOKENsecret. Every publish after this point authenticates via OIDC automatically — no workflow changes needed.GITHUB_TOKENread/write permissions (needed forauto-release.ymlto create releases and dispatch workflows).