|
| 1 | +# Publishing |
| 2 | + |
| 3 | +This package is published to npm from GitHub Actions using **npm trusted publishing** with **GitHub OIDC** and **provenance attestations**. |
| 4 | + |
| 5 | +Workflow file: |
| 6 | + |
| 7 | +- `.github/workflows/publish-package.yaml` |
| 8 | + |
| 9 | +## Why this setup |
| 10 | + |
| 11 | +This avoids storing a long-lived `NPM_TOKEN` in GitHub secrets. |
| 12 | + |
| 13 | +Instead: |
| 14 | + |
| 15 | +- GitHub Actions requests a short-lived OIDC identity token |
| 16 | +- npm verifies that token against the configured trusted publisher |
| 17 | +- `npm publish --provenance` attaches a provenance attestation for the published package |
| 18 | + |
| 19 | +The workflow has these permissions: |
| 20 | + |
| 21 | +- `contents: write` - to create and push the git tag |
| 22 | +- `id-token: write` - required for npm trusted publishing via OIDC |
| 23 | + |
| 24 | +## One-time npm setup |
| 25 | + |
| 26 | +In npm, configure **trusted publishing** for this package: |
| 27 | + |
| 28 | +- **Package:** `@braintrust/trace-opencode` |
| 29 | +- **Repository:** `braintrustdata/braintrust-opencode-plugin` |
| 30 | +- **Workflow:** `publish-package.yaml` |
| 31 | + |
| 32 | +This workflow no longer requires a GitHub Actions environment. |
| 33 | + |
| 34 | +## Release flow |
| 35 | + |
| 36 | +Releases are started manually from GitHub Actions using the **Publish package** workflow. |
| 37 | + |
| 38 | +### 1. Bump the version |
| 39 | + |
| 40 | +Update the version in `package.json` to the version you want to publish. |
| 41 | + |
| 42 | +### 2. Run the workflow |
| 43 | + |
| 44 | +From the GitHub Actions UI: |
| 45 | + |
| 46 | +- choose **Publish package** |
| 47 | +- choose the branch to publish from (default: `main`) |
| 48 | +- run the workflow |
| 49 | + |
| 50 | +## What the workflow does |
| 51 | + |
| 52 | +The workflow performs these steps: |
| 53 | + |
| 54 | +1. Checks out the selected branch |
| 55 | +2. Sets up Node.js and Bun |
| 56 | +3. Reads `name` and `version` from `package.json` |
| 57 | +4. Verifies that: |
| 58 | + - git tag `v<version>` does not already exist on `origin` |
| 59 | + - `@braintrust/trace-opencode@<version>` is not already published on npm |
| 60 | +5. Installs dependencies with `bun install --frozen-lockfile` |
| 61 | +6. Validates the package by running: |
| 62 | + - `bun run check` |
| 63 | + - `bun run typecheck` |
| 64 | + - `bun run test` |
| 65 | + - `bun run build` |
| 66 | + - `npm pack --dry-run` |
| 67 | +7. Publishes to npm with: |
| 68 | + |
| 69 | + ```bash |
| 70 | + npm publish --provenance --access public |
| 71 | + ``` |
| 72 | + |
| 73 | +8. Creates and pushes the matching git tag: |
| 74 | + |
| 75 | + ```text |
| 76 | + v<version> |
| 77 | + ``` |
| 78 | + |
| 79 | +9. Creates a GitHub release for that tag |
| 80 | + |
| 81 | +## Notes |
| 82 | + |
| 83 | +- The package is public, so `package.json` includes: |
| 84 | + |
| 85 | + ```json |
| 86 | + { |
| 87 | + "publishConfig": { |
| 88 | + "access": "public" |
| 89 | + } |
| 90 | + } |
| 91 | + ``` |
| 92 | + |
| 93 | +- The publish step relies on npm trusted publishing. No `NPM_TOKEN` secret should be needed. |
| 94 | +- If the publish succeeds, npm should show provenance information for the release. |
| 95 | + |
| 96 | +## Failure modes |
| 97 | + |
| 98 | +The workflow will fail early if: |
| 99 | + |
| 100 | +- the git tag for that version already exists |
| 101 | +- that exact version is already published on npm |
| 102 | +- lint, typecheck, tests, build, or `npm pack --dry-run` fails |
| 103 | +- npm trusted publishing is not configured correctly for the package/repo/workflow |
| 104 | + |
| 105 | +## Troubleshooting |
| 106 | + |
| 107 | +If npm rejects the publish, verify: |
| 108 | + |
| 109 | +1. trusted publishing is enabled for `@braintrust/trace-opencode` |
| 110 | +2. the repository matches exactly: |
| 111 | + - `braintrustdata/braintrust-opencode-plugin` |
| 112 | +3. the workflow filename matches exactly: |
| 113 | + - `publish-package.yaml` |
| 114 | +4. the GitHub Actions job has `id-token: write` |
| 115 | + |
| 116 | +If needed, update the trusted publishing settings in npm and rerun the workflow. |
0 commit comments