Skip to content

Commit 0a9a325

Browse files
authored
chore(release): publish to npm from release-please workflow (#13)
Avoid relying on tag-triggered workflows (which don't run when tags are created via GITHUB_TOKEN) by publishing in the same release-please run.
1 parent e7737e9 commit 0a9a325

File tree

4 files changed

+50
-95
lines changed

4 files changed

+50
-95
lines changed

.github/workflows/publish.yml

Lines changed: 0 additions & 61 deletions
This file was deleted.

.github/workflows/release-please.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,56 @@ permissions:
1111

1212
jobs:
1313
release-please:
14-
name: Create/Update Release PR
14+
name: Release PR + Publish
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: googleapis/release-please-action@v4
18+
id: release
1819
with:
1920
config-file: release-please-config.json
2021
manifest-file: .release-please-manifest.json
22+
23+
- uses: actions/checkout@v4
24+
if: ${{ steps.release.outputs.release_created }}
25+
26+
- uses: pnpm/action-setup@v2
27+
if: ${{ steps.release.outputs.release_created }}
28+
with:
29+
version: 10
30+
31+
- uses: actions/setup-node@v4
32+
if: ${{ steps.release.outputs.release_created }}
33+
with:
34+
node-version: '20'
35+
registry-url: 'https://registry.npmjs.org'
36+
cache: 'pnpm'
37+
38+
- name: Install
39+
if: ${{ steps.release.outputs.release_created }}
40+
run: pnpm install --frozen-lockfile
41+
42+
- name: Check if version already published
43+
if: ${{ steps.release.outputs.release_created }}
44+
run: |
45+
VERSION="$(node -e "console.log(JSON.parse(require('fs').readFileSync('package.json','utf8')).version)")"
46+
if npm view "codebase-context@${VERSION}" version >/dev/null 2>&1; then
47+
echo "Version ${VERSION} already exists on npm; skipping publish."
48+
echo "SKIP_PUBLISH=true" >> "$GITHUB_ENV"
49+
else
50+
echo "Version ${VERSION} not found on npm; will publish."
51+
fi
52+
53+
- name: Quality gates
54+
if: ${{ steps.release.outputs.release_created && env.SKIP_PUBLISH != 'true' }}
55+
run: |
56+
pnpm lint
57+
pnpm format:check
58+
pnpm type-check
59+
pnpm test
60+
pnpm build
61+
62+
- name: Publish
63+
if: ${{ steps.release.outputs.release_created && env.SKIP_PUBLISH != 'true' }}
64+
run: pnpm publish --access public --no-git-checks
65+
env:
66+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

RELEASING.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ We use a clean OSS-style flow:
77
- PRs merge into `master` (nothing publishes on merge)
88
- A release is created by a dedicated **Release PR** opened/updated automatically
99
- When the Release PR is merged, CI creates a git tag like `v1.2.3`
10-
- Tag pushes trigger CI to publish to npm
10+
- When a release tag is created, CI publishes to npm automatically
1111

1212
## One-time setup (maintainers)
1313

@@ -37,9 +37,8 @@ We use a clean OSS-style flow:
3737

3838
3. When you're ready to ship, merge the Release PR.
3939
- This creates a git tag `vX.Y.Z` and a GitHub Release
40-
- The `Publish` workflow runs on the tag and publishes to npm
40+
- The `Release Please` workflow publishes to npm as part of the same run
4141

4242
## Notes
4343

44-
- Publishing is triggered only by `v*` tags.
45-
- The publish workflow verifies `tag == v${package.json.version}` and fails fast if they don't match.
44+
- If a version is already published on npm, CI skips the publish step (useful when seeding historical tags).

scripts/ci/ensure-tag-matches-package.mjs

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)