Skip to content

Commit e244038

Browse files
authored
ci: simplify publish auth flow (#33)
## Summary - remove PAT-based release mutation from the publish workflow - align release flow with the simpler ui-style model - update README release docs to match the actual workflow ## Changes - remove `workflow_dispatch` bump input - stop bumping and committing `package.json` inside the release workflow - remove `secrets.RELEASE_PAT` dependency from checkout - add a tag-exists guard before release tagging - keep npm publishing on OIDC with provenance - document the new flow in `README.md` ## Release model after this PR - version bump happens in a normal PR to `main` - canary publishes on pushes to `main` - release workflow is manually dispatched - release job reads current package version, tags it, publishes via OIDC, and creates a GitHub release ## Validation - `pnpm lint` - `pnpm typecheck` - `pnpm build` - `pnpm test`
1 parent 9a66c1b commit e244038

2 files changed

Lines changed: 27 additions & 37 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,7 @@ on:
77
- "src/**"
88
- "pnpm-lock.yaml"
99
- ".github/workflows/publish.yml"
10-
workflow_dispatch:
11-
inputs:
12-
bump:
13-
description: "Version bump type"
14-
required: true
15-
type: choice
16-
options:
17-
- patch
18-
- minor
19-
- major
10+
workflow_dispatch: {}
2011

2112
concurrency:
2213
group: publish-${{ github.event_name }}
@@ -78,19 +69,16 @@ jobs:
7869
- name: Build
7970
run: pnpm build
8071

81-
- name: Upgrade npm for OIDC support
82-
run: npm install -g npm@latest
83-
8472
- name: Publish canary
8573
run: |
8674
sed -i '/_authToken/d' "$NPM_CONFIG_USERCONFIG"
8775
unset NODE_AUTH_TOKEN
8876
BASE_VERSION=$(node -p "require('./package.json').version")
8977
SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c1-7)
9078
CANARY_VERSION="${BASE_VERSION}-canary.${SHORT_SHA}"
91-
npm version "$CANARY_VERSION" --no-git-tag-version
79+
npm version "$CANARY_VERSION" --no-git-tag-version --ignore-scripts
9280
TARBALL=$(pnpm pack --pack-destination /tmp | tail -1)
93-
npm publish "$TARBALL" --tag canary --provenance --access public
81+
npx --yes npm@latest publish "$TARBALL" --tag canary --provenance --access public
9482
9583
release:
9684
name: Publish Release
@@ -104,7 +92,6 @@ jobs:
10492
- uses: actions/checkout@v4
10593
with:
10694
fetch-depth: 0
107-
token: ${{ secrets.RELEASE_PAT }}
10895

10996
- uses: pnpm/action-setup@v4
11097

@@ -119,12 +106,15 @@ jobs:
119106
- name: Build
120107
run: pnpm build
121108

122-
- name: Bump version
109+
- name: Read version + guard against retag
123110
id: version
124111
run: |
125-
npm version ${{ inputs.bump }} --no-git-tag-version
126112
VERSION=$(node -p "require('./package.json').version")
127113
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
114+
if git rev-parse "v${VERSION}" >/dev/null 2>&1; then
115+
echo "::error::Tag v${VERSION} already exists. Bump package.json on main via a PR before dispatching release."
116+
exit 1
117+
fi
128118
129119
- name: Generate changelog
130120
id: changelog
@@ -163,24 +153,19 @@ jobs:
163153
echo "CHANGELOG_EOF"
164154
} >> "$GITHUB_OUTPUT"
165155
166-
- name: Commit and tag
156+
- name: Tag release
167157
run: |
168158
git config user.name "github-actions[bot]"
169159
git config user.email "github-actions[bot]@users.noreply.github.com"
170-
git add package.json
171-
git commit -m "chore(release): v${{ steps.version.outputs.version }}"
172160
git tag -a "v${{ steps.version.outputs.version }}" -m "v${{ steps.version.outputs.version }}"
173-
git push origin main --follow-tags
174-
175-
- name: Upgrade npm for OIDC support
176-
run: npm install -g npm@latest
161+
git push origin "v${{ steps.version.outputs.version }}"
177162
178163
- name: Publish to npm
179164
run: |
180165
sed -i '/_authToken/d' "$NPM_CONFIG_USERCONFIG"
181166
unset NODE_AUTH_TOKEN
182167
TARBALL=$(pnpm pack --pack-destination /tmp | tail -1)
183-
npm publish "$TARBALL" --tag latest --provenance --access public
168+
npx --yes npm@latest publish "$TARBALL" --tag latest --provenance --access public
184169
185170
- name: Create GitHub Release
186171
env:

‎README.md‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,26 +207,31 @@ codebase-intelligence <command> <path>
207207

208208
## Release
209209

210-
Publishing is automated and **only happens on `v*` tags**.
211-
212-
### One-time setup
213-
214-
1. Create an npm automation token (npmjs.com → Access Tokens).
215-
2. Add it to GitHub repository secrets as `NPM_TOKEN`.
210+
Publishing is automated through GitHub Actions.
216211

217212
### Normal CI (before release)
218213

219214
- `CI` workflow runs on every PR and push to `main`:
220215
- lint → typecheck → build → test
221216

217+
### Canary publish
218+
219+
- Pushes to `main` trigger a canary publish.
220+
- The package is published to npm with the `canary` tag.
221+
- Canary versions are derived from the current package version plus the short commit SHA.
222+
222223
### Create a release
223224

224-
1. Bump `package.json` version.
225-
2. Commit: `chore(release): bump to vX.Y.Z`
226-
3. Tag: `git tag vX.Y.Z`
227-
4. Push: `git push origin main --tags`
225+
1. Bump `package.json` version in a normal PR.
226+
2. Merge that PR to `main`.
227+
3. Run the `Publish` workflow manually from GitHub Actions.
228+
4. The workflow will:
229+
- verify the tag does not already exist
230+
- create and push `vX.Y.Z`
231+
- publish to npm with provenance via OIDC
232+
- create a GitHub Release with generated notes
228233

229-
The `v*` tag triggers the `CI` workflow publish job (`npm publish --access public --provenance`).
234+
No PAT is required for npm publish. The workflow uses GitHub repository permissions for tagging and OIDC for npm publishing.
230235

231236
## Contributing
232237

0 commit comments

Comments
 (0)