Skip to content

Commit 313bf76

Browse files
committed
chore(release): automate release PR + npm publish (#10)
* chore(release): automate release PR + npm publish Adopt release-please for tagged releases and CI publishing; document the contributor/release workflow. * chore: add CODEOWNERS for maintainer approval Require @PatrickSys review for external PRs while allowing maintainers to self-merge when needed.
1 parent 3da3439 commit 313bf76

File tree

7 files changed

+157
-2
lines changed

7 files changed

+157
-2
lines changed

.github/pull_request_template.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## What / Why
2+
3+
Explain the change briefly.
4+
5+
## Release notes
6+
7+
This repo uses an automated release flow.
8+
9+
- Please use a Conventional-Commits style PR title (we squash-merge): `feat: ...`, `fix: ...`, `docs: ...`, `chore: ...`, `refactor: ...`
10+
- If this should not appear in release notes, say so here
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Release Please
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
issues: write
11+
12+
jobs:
13+
release-please:
14+
name: Release PR + Publish
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: googleapis/release-please-action@v4
18+
id: release
19+
with:
20+
config-file: release-please-config.json
21+
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 }}

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"trailingComma": "none",
44
"singleQuote": true,
55
"printWidth": 100,
6-
"tabWidth": 2
6+
"tabWidth": 2,
7+
"endOfLine": "auto"
78
}

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "1.4.0"
3+
}

CONTRIBUTING.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ src/
4242

4343
**Tests** - Run `pnpm test`. We use Vitest for unit and smoke testing.
4444

45-
4645
## Adding a Framework Analyzer
4746

4847
1. Create `src/analyzers/react/index.ts`
@@ -77,3 +76,23 @@ The server logs to stderr, so you can see what it's doing.
7776
- Open PR with what you changed and why
7877

7978
No strict commit format, just be clear about what you're doing.
79+
80+
## Release Notes (PR titles)
81+
82+
This repo publishes to npm via an automated Release PR flow.
83+
84+
To keep releases predictable and human-readable, please use a Conventional-Commits style **PR title** (we usually squash-merge, and the PR title becomes the commit message):
85+
86+
- `feat: ...` (new feature)
87+
- `fix: ...` (bug fix)
88+
- `docs: ...` (docs-only)
89+
- `chore: ...` (maintenance)
90+
- `refactor: ...` (refactor)
91+
92+
Examples:
93+
94+
- `feat: add memory store for team conventions`
95+
- `fix: avoid creating directories on invalid ROOT_PATH`
96+
- `docs: clarify MCP client config and npx --yes`
97+
98+
Maintainers: release steps are documented in `RELEASING.md`.

RELEASING.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Releasing
2+
3+
This repo publishes an npm package: `codebase-context`.
4+
5+
We use a clean OSS-style flow:
6+
7+
- PRs merge into `master` (nothing publishes on merge)
8+
- A release is created by a dedicated **Release PR** opened/updated automatically
9+
- When the Release PR is merged, CI creates a git tag like `v1.2.3`
10+
- When a release tag is created, CI publishes to npm automatically
11+
12+
## One-time setup (maintainers)
13+
14+
1. Add a repository secret: `NPM_TOKEN`
15+
- Create an npm access token with publish rights for `codebase-context`
16+
- Add it in GitHub: Settings > Secrets and variables > Actions > New repository secret
17+
- If your npm tokens expire (for example after 90 days), rotate the token and update this secret before it expires
18+
19+
2. (Recommended) Protect `master`
20+
- Require PRs (no direct pushes)
21+
- Require the `Tests` workflow to pass
22+
23+
3. Allow Release Please to open PRs
24+
- GitHub: Settings > Actions > General
25+
- Set Workflow permissions to "Read and write"
26+
- Enable "Allow GitHub Actions to create and approve pull requests"
27+
28+
## Normal release flow
29+
30+
1. Merge changes into `master` via PRs.
31+
- Recommended: use **Squash and merge** so the PR title becomes the commit message.
32+
- Release automation relies on Conventional-Commits style messages like `feat: ...` / `fix: ...`.
33+
34+
2. Wait for the bot PR named like `release-please--branches--master`.
35+
- It bumps `package.json` and updates `CHANGELOG.md`
36+
- If it already exists, it gets updated automatically as new PRs merge
37+
38+
3. When you're ready to ship, merge the Release PR.
39+
- This creates a git tag `vX.Y.Z` and a GitHub Release
40+
- The `Release Please` workflow publishes to npm as part of the same run
41+
42+
## Notes
43+
44+
- If a version is already published on npm, CI skips the publish step (useful when seeding historical tags).

release-please-config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"packages": {
3+
".": {
4+
"release-type": "node",
5+
"package-name": "codebase-context",
6+
"changelog-path": "CHANGELOG.md",
7+
"include-v-in-tag": true,
8+
"include-component-in-tag": false,
9+
"extra-files": ["pnpm-lock.yaml"]
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)