Skip to content

Commit 0280af1

Browse files
alerizzoclaude
andauthored
feat: adopt changesets for automated versioning and publishing (#6)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f662eef commit 0280af1

11 files changed

Lines changed: 1720 additions & 123 deletions

File tree

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets).
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md).

.changeset/config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@3.1.3/schema.json",
3+
"changelog": [
4+
"@changesets/changelog-github",
5+
{ "repo": "codacy/codacy-cloud-cli" }
6+
],
7+
"commit": false,
8+
"fixed": [],
9+
"linked": [],
10+
"access": "public",
11+
"baseBranch": "main",
12+
"updateInternalDependencies": "patch",
13+
"ignore": []
14+
}

.changeset/fresh-spoons-build.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,25 @@ jobs:
3737

3838
- name: Test
3939
run: npm test
40+
41+
changeset-check:
42+
if: github.event_name == 'pull_request'
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Check for changesets
51+
run: |
52+
# Count .changeset/*.md files added/modified in this PR compared to the base branch
53+
CHANGESETS=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- '.changeset/*.md' ':!.changeset/README.md' | wc -l)
54+
if [ "$CHANGESETS" -eq 0 ]; then
55+
echo "::error::No changeset found for this PR. Run 'npx changeset' to describe your changes."
56+
echo ""
57+
echo "If this PR does not require a version bump (e.g., docs-only or CI changes),"
58+
echo "add an empty changeset with: npx changeset --empty"
59+
exit 1
60+
fi
61+
echo "Found $CHANGESETS changeset file(s) changed in this PR."

.github/workflows/publish.yml

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

.github/workflows/release.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
concurrency:
8+
group: release-${{ github.ref }}
9+
cancel-in-progress: false
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
id-token: write
15+
16+
jobs:
17+
release:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
22+
23+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
24+
with:
25+
node-version: 22
26+
cache: npm
27+
registry-url: "https://registry.npmjs.org"
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
- name: Generate API client
33+
run: npm run update-api
34+
35+
- name: Build
36+
run: npm run build
37+
38+
- name: Test
39+
run: npm test
40+
41+
- name: Create Release PR or Publish
42+
uses: changesets/action@6a0a831ff30acef54f2c6aa1cbbc1096b066edaf # v1
43+
with:
44+
publish: npm run release
45+
title: "chore: version packages"
46+
commit: "chore: version packages"
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
50+
NPM_CONFIG_PROVENANCE: true

AGENTS.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This CLI wraps the [Codacy Cloud API v3](https://api.codacy.com/api/api-docs) us
2424

2525
```
2626
codacy-cloud-cli/
27+
├── .changeset/ # Changesets config and pending changeset files
2728
├── src/
2829
│ ├── index.ts # CLI entry point (Commander.js setup)
2930
│ ├── api/
@@ -173,6 +174,35 @@ The `SPECS/` folder at the project root is the single source of truth for specs
173174
4. Update `SPECS/README.md` (mark tasks done, add changelog entry) when completing work
174175
5. Add new tasks to `SPECS/README.md` pending table when discovered during work
175176

177+
## Versioning & Releasing
178+
179+
This project uses [changesets](https://github.com/changesets/changesets) for versioning and npm publishing.
180+
181+
### How it works
182+
183+
1. Every PR must include a changeset file (CI enforces this via the `changeset-check` job)
184+
2. Run `npx changeset` to create one — select the bump type (`patch`, `minor`, `major`) and describe the change
185+
3. For PRs that don't need a version bump (docs, CI, refactors), use `npx changeset --empty`
186+
4. On merge to `main`, the `release.yml` workflow creates a "chore: version packages" PR that bumps the version and updates `CHANGELOG.md`
187+
5. Merging that PR triggers the actual npm publish with provenance
188+
189+
### Agent responsibilities for changesets
190+
191+
When completing work that changes user-facing behavior or adds features, agents **must**:
192+
1. Run `npx changeset` and create an appropriate changeset file before committing
193+
2. Use `patch` for bug fixes, `minor` for new features or commands, `major` for breaking changes
194+
3. Write a clear, user-facing summary in the changeset (this becomes the CHANGELOG entry)
195+
196+
For internal-only changes (refactors, docs, CI, test-only changes), use `npx changeset --empty`.
197+
198+
### Agent responsibilities for self-documenting changes
199+
200+
When completing work, agents **must** update relevant documentation:
201+
1. **`SPECS/README.md`** — mark tasks as done in the pending table, add a changelog entry
202+
2. **`README.md`** — if a new command was added or renamed, update the commands summary table (one row per command, no detailed args/options)
203+
3. **`AGENTS.md`** — if a new convention, pattern, or workflow was introduced that affects how agents work, add it to the relevant section
204+
4. **`SPECS/deployment.md`** — if CI/CD or publishing workflows changed, update this spec to match
205+
176206
## Environment Variables
177207

178208
| Variable | Required | Description |

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,17 @@ npm run update-api # Update the auto-generated API client
8989
### CI/CD
9090

9191
- **CI**: Runs on every push to `main` and on PRs. Builds and tests across Node.js 18, 20, and 22.
92-
- **Publish**: Triggered on GitHub release creation. Builds, tests, and publishes to npm with provenance.
92+
- **Release**: Uses [changesets](https://github.com/changesets/changesets) for automated versioning and npm publishing.
9393

94-
To publish a new version:
95-
1. Update the version in `package.json`
96-
2. Create a GitHub release with a tag matching the version (e.g. `v1.1.0`)
97-
3. The publish workflow will automatically build and push to npm
94+
#### Publishing a new version
9895

99-
**Prerequisite**: Add an `NPM_TOKEN` secret to your GitHub repository settings.
96+
1. When making changes, run `npx changeset` and describe your change (select `patch`, `minor`, or `major`)
97+
2. Include the generated `.changeset/*.md` file in your PR
98+
3. CI enforces that every PR includes a changeset (use `npx changeset --empty` for changes that don't need a version bump, like docs or CI)
99+
4. When PRs are merged to `main`, the release workflow automatically creates a **"chore: version packages"** PR that bumps the version and updates `CHANGELOG.md`
100+
5. Merging that PR publishes to npm with provenance
101+
102+
**Prerequisite**: An `NPM_TOKEN` secret must be configured in the GitHub repository settings.
100103

101104
## License
102105

SPECS/deployment.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Deployment & CI Spec
22

3-
**Status:** ✅ Done (2026-02-18)
3+
**Status:** ✅ Done (updated 2026-05-08)
44

55
## npm Package
66

77
- **Binary name:** `codacy` (registered in `package.json` under `bin`)
88
- **Included files:** `dist/` and `README.md` (via `files` field)
9-
- **Pre-publish:** `prepublishOnly` runs `npm run build` using `tsconfig.build.json`
10-
- **Engines:** requires Node.js >= 18
9+
- **Pre-publish:** `prepublishOnly` runs `npm run update-api && npm run build` as a safety net for local publishes
10+
- **Engines:** requires Node.js >= 20
1111
- **Install globally:** `npm install -g "@codacy/codacy-cloud-cli"`
1212

1313
## GitHub Actions
@@ -18,23 +18,26 @@ Triggers on: push and pull requests to `main`.
1818

1919
Matrix: Node.js 18, 20, 22.
2020

21-
Steps:
22-
1. Checkout
23-
2. Setup Node
24-
3. `npm ci`
25-
4. `npm run build`
26-
5. `npm test`
21+
Jobs:
22+
- **build-and-test**: checkout → setup node → install → generate API client → type check → build → test
23+
- **changeset-check** (PRs only): verifies at least one `.changeset/*.md` file is present in the PR diff
24+
25+
### Release (`release.yml`)
2726

28-
### Publish to npm (`publish.yml`)
27+
Triggers on: push to `main`.
2928

30-
Triggers on: GitHub release published.
29+
Uses the [changesets/action](https://github.com/changesets/changesets) to automate versioning and publishing.
3130

3231
Steps:
3332
1. Checkout
3433
2. Setup Node with `registry-url: https://registry.npmjs.org`
3534
3. `npm ci`
36-
4. `npm run build`
37-
5. `npm publish` (uses `NODE_AUTH_TOKEN` secret)
35+
4. Generate API client (`npm run update-api`)
36+
5. Build (`npm run build`)
37+
6. Test (`npm test`)
38+
7. `changesets/action` — either:
39+
- Creates/updates a "chore: version packages" PR (bumps version, updates CHANGELOG.md)
40+
- If that PR was just merged, runs `changeset publish` to publish to npm with provenance
3841

3942
## Homebrew Formula
4043

@@ -44,5 +47,5 @@ Planned for future distribution as a separate brew formula for macOS/Linux/Windo
4447

4548
| Secret | Used by |
4649
|---|---|
47-
| `NODE_AUTH_TOKEN` | npm publish workflow |
50+
| `NPM_TOKEN` | Release workflow (`NODE_AUTH_TOKEN` for npm publish) |
4851
| `CODACY_API_TOKEN` | CLI runtime (env var, not a secret in CI) |

0 commit comments

Comments
 (0)