Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/typescript-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- 'README.md'
- 'PUBLISHING.md'
- 'typescript/**'
- 'openapi/**'
- 'scripts/**'
Expand All @@ -20,6 +21,7 @@ on:
branches: [main]
paths:
- 'README.md'
- 'PUBLISHING.md'
- 'typescript/**'
- 'openapi/**'
- 'scripts/**'
Expand Down
74 changes: 62 additions & 12 deletions PUBLISHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,77 @@ gh workflow run publish-python-sdk.yml --ref main -f confirm=publish-zelinqa
Verify installation in a clean environment with `uv pip install --python <venv-python> zelinqa==<version>`
and `import zelinqa`. Never reuse a published version.

## npm: new package
## npm: configure the existing package before publishing

`@zelinqa/sdk` already exists. An earlier interactive publication does not
authorize GitHub Actions to publish subsequent releases. The package needs its
own trusted publisher on npm; approving the GitHub `npm` environment is a
separate gate and does not create this connection.

A package owner must complete these steps on npmjs.com:

1. Open [@zelinqa/sdk](https://www.npmjs.com/package/@zelinqa/sdk), then
**Settings**. Complete the security-key check if prompted.
2. Under **Trusted Publisher**, choose **GitHub Actions**.
3. Enter these exact, case-sensitive values:

| Field | Value |
| --- | --- |
| Organization or user | `Zelinqa` |
| Repository | `zelinqa-sdk` |
| Workflow filename | `publish-typescript-sdk.yml` |
| Environment name | `npm` |

The workflow field takes only the filename, not `.github/workflows/` or
the workflow's display name. The organization is the GitHub owner, not
the lowercase npm scope.
4. Under **Allowed actions**, enable **Allow npm publish**. This workflow
calls `npm publish`, not `npm stage publish`.
5. Select **Set up new trusted publisher connection** and verify that the
saved connection shows the values above. If a different connection exists,
have the owner replace the incorrect connection; do not relax the environment
restriction or disable two-factor authentication.
6. Keep the GitHub `npm` environment restricted to `main` with maintainer approval.

No npm token is required in repository secrets, workflow variables, or `.npmrc`.
[Official npm instructions](https://docs.npmjs.com/trusted-publishers/).

`@zelinqa/sdk` is NOT the existing `@zelinqa/nbq` package.
Verify organization ownership and configure its own publisher; the old package's
publisher does not transfer. If npm requires a first authenticated publication,
A maintainer must perform that setup interactively with 2FA, using the tested tarball
`zelinqa-sdk-1.0.0.tgz`, before enabling OIDC for subsequent releases.
Do not introduce a permanent token into CI.
### Workflow prerequisites and retry

Publisher: owner `Zelinqa`, repository `zelinqa-sdk`, workflow
`publish-typescript-sdk.yml`, environment `npm`.
[Official npm instructions](https://docs.npmjs.com/trusted-publishers/).
The publish job uses a GitHub-hosted runner, Node 24, `contents: read`, and
`id-token: write`. Trusted publishing requires Node 22.14.0 or later and npm
11.5.1 or later; verify the versions printed by the setup step. Do not add an
unnecessary `npm@latest` upgrade when the bundled CLI already meets this minimum.

The build job creates the tarball without publishing permissions. The approved
publish job downloads that artifact and uses an explicit local path
(`./package-artifacts/*.tgz`). Do not replace this with a source-directory publish
or introduce a token-based fallback. The `repository.url` in `package.json` must
continue to identify `Zelinqa/zelinqa-sdk` for provenance.

Once the package publisher is configured and the release gates pass:
Once the npm connection is saved, the release changes are merged, and the gates
pass, dispatch a **new run on main**, then approve its `npm` environment:

```bash
gh workflow run publish-typescript-sdk.yml --ref main -f confirm=publish-zelinqa-sdk
gh workflow run publish-typescript-sdk.yml --repo Zelinqa/zelinqa-sdk --ref main -f confirm=publish-zelinqa-sdk
```

Check provenance and clean Node imports in both ESM and CommonJS.

### Troubleshooting an authentication failure

An `E404` on the registry `PUT` can mean that the workflow is not authorized,
even when the package exists and packing succeeded. First inspect the package's
trusted publisher and its allowed action, then compare all four fields above.
Do not delete or recreate the package to resolve an authorization error.

`actions/setup-node` creates a temporary `NPM_CONFIG_USERCONFIG` when given a
registry URL. Its reference to `NODE_AUTH_TOKEN` is not proof that a real token
is configured. Do not print npmrc contents or credential environment variables
while diagnosing failures. Check the workflow for token injection or registry
overrides instead. `npm whoami` and a publish dry run do **not** validate OIDC
authorization: the real exchange occurs during publication.

## Release order

1. SDK Python and TypeScript, then verify actual registry installs.
Expand Down
93 changes: 93 additions & 0 deletions typescript/tests/publishing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { parse } from "yaml";

type Step = {
name?: string;
uses?: string;
run?: string;
with?: Record<string, string | boolean>;
};

type Workflow = {
on: { workflow_dispatch: { inputs: { confirm: { required: boolean } } } };
permissions: Record<string, string>;
jobs: Record<
"build-and-test" | "publish",
{
if?: string;
needs?: string;
"runs-on": string;
environment?: string;
permissions?: Record<string, string>;
steps: Step[];
}
>;
};

const filename = "publish-typescript-sdk.yml";
const source = readFileSync(
new URL(`../../.github/workflows/${filename}`, import.meta.url),
"utf8",
);
const workflow = parse(source) as Workflow;
const guide = readFileSync(new URL("../../PUBLISHING.md", import.meta.url), "utf8");
const metadata = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));

describe("npm trusted publishing configuration", () => {
it("documents the same identity as the package and publish job", () => {
const repository = new URL(metadata.repository.url.replace(/^git\+/, ""));
const [owner, name] = repository.pathname
.slice(1)
.replace(/\.git$/, "")
.split("/");
expect(repository.hostname).toBe("github.com");
expect(metadata.name).toBe("@zelinqa/sdk");
expect(guide).toContain(`| Organization or user | \`${owner}\` |`);
expect(guide).toContain(`| Repository | \`${name}\` |`);
expect(guide).toContain(`| Workflow filename | \`${filename}\` |`);
expect(guide).toContain(`| Environment name | \`${workflow.jobs.publish.environment}\` |`);
expect(guide).toContain("**Allow npm publish**");
expect(guide).toContain(
`gh workflow run ${filename} --repo ${owner}/${name} --ref main -f confirm=publish-zelinqa-sdk`,
);
});

it("keeps the release manual, main-only, and protected by the npm environment", () => {
expect(workflow.on.workflow_dispatch.inputs.confirm.required).toBe(true);
expect(workflow.jobs["build-and-test"].if).toBe(
"github.ref == 'refs/heads/main' && inputs.confirm == 'publish-zelinqa-sdk'",
);
expect(workflow.jobs.publish.needs).toBe("build-and-test");
expect(workflow.jobs.publish.environment).toBe("npm");
expect(workflow.jobs.publish["runs-on"]).toBe("ubuntu-latest");
});

it("grants OIDC only to the publish job without long-lived token injection", () => {
expect(workflow.permissions).toEqual({ contents: "read" });
expect(workflow.jobs["build-and-test"].permissions).toBeUndefined();
expect(workflow.jobs.publish.permissions).toEqual({ contents: "read", "id-token": "write" });
expect(source).not.toMatch(/secrets\.|NODE_AUTH_TOKEN|NPM_TOKEN/);
expect(
workflow.jobs.publish.steps.some((step) => step.uses?.startsWith("actions/checkout@")),
).toBe(false);
});

it("publishes the tested artifact using an explicit local path and the public registry", () => {
const steps = workflow.jobs.publish.steps;
const setup = steps.find((step) => step.uses?.startsWith("actions/setup-node@"));
expect(setup?.with).toMatchObject({
"node-version": "24",
"registry-url": "https://registry.npmjs.org",
"package-manager-cache": false,
});
const download = steps.find((step) => step.uses?.startsWith("actions/download-artifact@"));
const upload = workflow.jobs["build-and-test"].steps.find((step) =>
step.uses?.startsWith("actions/upload-artifact@"),
);
expect(download?.with?.name).toBe(upload?.with?.name);
expect(download?.with?.path).toBe("package-artifacts/");
const publish = steps.find((step) => step.name === "Publish with npm Trusted Publishing");
expect(publish?.run).toBe("npm publish ./package-artifacts/*.tgz --access public");
});
});
Loading