Skip to content

Commit a8fb9c8

Browse files
tonychang04claude
andauthored
ci: auto-publish npm on release tags (granular automation token) (#20)
publish-npm job in release.yml: gated on the binaries, tag pushes only, granular NPM_TOKEN secret (bypasses interactive 2FA), --provenance attestation, and a clear error when the secret is missing. Skill updated in the same PR per its keep-this-skill-true rule. Claude-Session: https://claude.ai/code/session_01GMbAe5K1RfwaAcge5inX7P Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 19b72b7 commit a8fb9c8

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

.claude/skills/developing-insta-cli/SKILL.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ npx tsx src/index.ts --help # run the CLI from source
3131
1. **Bump**: PR changing `package.json` version (main is protected — never commit the bump directly). Merge it via the flow above.
3232
2. **Tag**: `git checkout main && git pull && git tag vX.Y.Z && git push origin vX.Y.Z`.
3333
3. **Binaries (automatic)**: the `release` workflow builds 5 platform binaries + SHA256SUMS and publishes a GitHub Release. `install.sh`, `agents.sh`, and `insta upgrade` serve users from it immediately.
34-
4. **npm (MANUAL — do not assume CI does it)**: from a clean checkout at the tag, repo root:
34+
4. **npm (automatic on tag IF the `NPM_TOKEN` repo secret is set)**: the `publish-npm` job in
35+
`release.yml` publishes with a granular automation token (`--provenance`). If that job fails
36+
with "secret is not set", or for an out-of-band publish, the manual fallback — from a clean
37+
checkout at the tag, repo root:
3538
```bash
3639
npm publish --otp=<2FA code> # prepublishOnly builds dist/; EOTP error = missing/expired code
3740
```
38-
Needs an npm account with publish rights on `insta` (2FA enforced). Verify with `npm view insta version`.
41+
Verify either path with `npm view insta version`.
3942
5. Users on the binary channel update via `insta upgrade`; npm users via `npx insta@latest` / `npm update -g insta`.
4043

4144
## Gotchas
@@ -46,7 +49,7 @@ npx tsx src/index.ts --help # run the CLI from source
4649
| John-bot ignored the request | Batched links — resend ONE link per message |
4750
| `npm error code EOTP` | Publish needs `--otp=<fresh 2FA code>` |
4851
| `npm publish` ENOENT package.json | Ran outside the repo root |
49-
| `npx insta@latest` behind the GH release | npm half not published — step 4 |
52+
| `npx insta@latest` behind the GH release | `publish-npm` job failed/skipped (NPM_TOKEN?) — see step 4 |
5053
| CLI hits the wrong server in tests | Persisted `~/.insta/config.json` apiUrl; set `INSTA_API_URL` (≥0.0.7) or move the config aside |
5154

5255
## Keep this skill true

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,33 @@ jobs:
9090
fi
9191
gh release upload "$TAG" --repo "$GITHUB_REPOSITORY" --clobber \
9292
dist-bin/insta-* dist-bin/SHA256SUMS install.sh
93+
94+
# npm half of the release: publishes `insta` to the registry with a GRANULAR AUTOMATION token
95+
# (repo secret NPM_TOKEN — bypasses the interactive 2FA/OTP that blocks CI). Gated on the
96+
# binaries building, tag pushes only. --provenance attests the build (public repo + OIDC).
97+
publish-npm:
98+
needs: release
99+
if: startsWith(github.ref, 'refs/tags/')
100+
runs-on: ubuntu-latest
101+
permissions:
102+
contents: read
103+
id-token: write # npm --provenance attestation
104+
steps:
105+
- uses: actions/checkout@v4
106+
- uses: actions/setup-node@v4
107+
with:
108+
node-version: 22
109+
registry-url: https://registry.npmjs.org
110+
- name: Require NPM_TOKEN
111+
env:
112+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
113+
run: |
114+
if [ -z "$NPM_TOKEN" ]; then
115+
echo "::error::NPM_TOKEN repo secret is not set — create a GRANULAR automation token at npmjs.com (Access Tokens → Generate → Granular, packages: insta, permissions: read/write) and add it under Settings → Secrets → Actions."
116+
exit 1
117+
fi
118+
- run: npm ci
119+
- name: Publish to npm
120+
env:
121+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
122+
run: npm publish --provenance --access public

0 commit comments

Comments
 (0)