Skip to content

Commit f27ec62

Browse files
authored
Add CI publishing to component starter template (#403)
Adds Changesets and CI publishing to the component starter template, using the same tag-triggered flow as the migrated component repos and the shared actions in [convex/npm-release-actions](https://github.com/convex/npm-release-actions) (pinned by SHA, v0.3.0). - When a version PR merges, the version workflow tags the commit that set the new version as `v<version>` and starts Release on that tag. Pushing a tag by hand also starts Release. - Release builds exactly the tagged commit, so npm provenance names the commit that was built. The build job (no npm credentials) validates the tag, checks release notes, builds, runs checks and the E2E/codegen check, and packs. The stage job verifies the tarball's SHA-256 and runs `npm stage publish` without a checkout. - The version PR job uses the shared `version-pr` action, which also updates `package-lock.json`'s version. - Release runs are grouped per tag and version workflow runs per commit. - The version workflow is guarded by the `example-org/sample-component` placeholder, which the initializer replaces with the generated repository. - PUBLISHING.md covers setup (npm trust, Actions PR permission, required check), releasing other commits, and recovery. - Adds reusable scripts and Node 24 CI to the template.
1 parent 1a66bb9 commit f27ec62

11 files changed

Lines changed: 742 additions & 103 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Release notes
2+
3+
See [CONTRIBUTING.md](../CONTRIBUTING.md#releases) for release instructions.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@4.0.1/schema.json",
3+
"baseBranch": "main",
4+
"access": "public",
5+
"changelog": "@changesets/cli/changelog",
6+
"commit": false,
7+
"fixed": [],
8+
"linked": [],
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags: ["v*"]
6+
# Started on a tag by the version workflow, or by hand to retry a tag.
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: false
12+
13+
permissions: {}
14+
15+
env:
16+
NODE_VERSION: "24.22.1"
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 30
22+
permissions:
23+
contents: read
24+
outputs:
25+
name: ${{ steps.release.outputs.name }}
26+
version: ${{ steps.release.outputs.version }}
27+
channel: ${{ steps.release.outputs.channel }}
28+
artifact_id: ${{ steps.pack.outputs.artifact-id }}
29+
sha256: ${{ steps.pack.outputs.sha256 }}
30+
steps:
31+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
32+
with:
33+
ref: ${{ github.sha }}
34+
fetch-depth: 0
35+
persist-credentials: false
36+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
37+
with:
38+
node-version: ${{ env.NODE_VERSION }}
39+
package-manager-cache: false
40+
- id: release
41+
uses: convex/npm-release-actions/validate-tag@3a142e21f421319890981579b8952267bc11fc53 # v0.3.0
42+
- run: npm ci
43+
- uses: convex/npm-release-actions/check-release-notes@3a142e21f421319890981579b8952267bc11fc53 # v0.3.0
44+
- run: npm run build
45+
- run: npm run check
46+
- name: Run E2E tests and verify generated code
47+
env:
48+
CONVEX_DISABLE_TELEMETRY: "1"
49+
run: |
50+
npm run test:e2e
51+
git diff --exit-code -- src/component/_generated example/convex/_generated
52+
test -z "$(git ls-files --others --exclude-standard src/component/_generated example/convex/_generated)"
53+
- id: pack
54+
uses: convex/npm-release-actions/pack@3a142e21f421319890981579b8952267bc11fc53 # v0.3.0
55+
56+
stage:
57+
needs: build
58+
runs-on: ubuntu-latest
59+
timeout-minutes: 10
60+
permissions:
61+
contents: read
62+
id-token: write
63+
steps:
64+
- uses: convex/npm-release-actions/stage@3a142e21f421319890981579b8952267bc11fc53 # v0.3.0
65+
with:
66+
artifact-id: ${{ needs.build.outputs.artifact_id }}
67+
sha256: ${{ needs.build.outputs.sha256 }}
68+
name: ${{ needs.build.outputs.name }}
69+
version: ${{ needs.build.outputs.version }}
70+
channel: ${{ needs.build.outputs.channel }}
71+
node-version: ${{ env.NODE_VERSION }}

‎template-component/.github/workflows/test.yml‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,46 @@ concurrency:
44
cancel-in-progress: true
55

66
on:
7+
workflow_dispatch:
78
push:
89
branches: [main]
910
pull_request:
1011
branches: ["**"]
1112

13+
permissions: {}
14+
1215
jobs:
1316
check:
1417
name: Test and lint
1518
runs-on: ubuntu-latest
1619
timeout-minutes: 30
20+
permissions:
21+
contents: read
1722

1823
steps:
19-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
24+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
25+
with:
26+
persist-credentials: false
2027

2128
- name: Node setup
22-
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
29+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
2330
with:
24-
cache-dependency-path: package.json
25-
node-version: "26.x"
31+
cache-dependency-path: package-lock.json
32+
node-version: "24.22.1"
2633
cache: "npm"
2734

2835
- name: Install and build
2936
run: |
30-
npm i
37+
npm ci
3138
npm run build
32-
- name: Publish package for testing branch
33-
run: npx pkg-pr-new publish || echo "pkg-pr-new failed"
3439
- name: Test
40+
run: npm run check
41+
- name: Run E2E smoke test and verify generated code
42+
env:
43+
CONVEX_DISABLE_TELEMETRY: "1"
3544
run: |
36-
npm run test
37-
npm run typecheck
38-
npm run lint
45+
npm run test:e2e
46+
git diff --exit-code -- src/component/_generated example/convex/_generated
47+
test -z "$(git ls-files --others --exclude-standard src/component/_generated example/convex/_generated)"
48+
- name: Publish package for testing branch
49+
run: npx pkg-pr-new publish || echo "pkg-pr-new failed"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Update release PR
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.sha }}
5+
cancel-in-progress: false
6+
7+
on:
8+
push:
9+
branches: [main]
10+
workflow_dispatch:
11+
12+
permissions: {}
13+
14+
jobs:
15+
version:
16+
name: Update release PR
17+
if:
18+
github.repository == 'example-org/sample-component' && github.ref ==
19+
'refs/heads/main'
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 30
22+
permissions:
23+
contents: write
24+
pull-requests: write
25+
steps:
26+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
27+
with:
28+
ref: ${{ github.sha }}
29+
fetch-depth: 0
30+
persist-credentials: false
31+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
32+
with:
33+
node-version: "24.22.1"
34+
package-manager-cache: false
35+
- run: npm ci --ignore-scripts
36+
- uses: convex/npm-release-actions/version-pr@3a142e21f421319890981579b8952267bc11fc53 # v0.3.0
37+
38+
tag:
39+
name: Tag a new version
40+
if:
41+
github.repository == 'example-org/sample-component' && github.ref ==
42+
'refs/heads/main'
43+
runs-on: ubuntu-latest
44+
timeout-minutes: 5
45+
permissions:
46+
contents: write # create the version tag
47+
actions: write # start Release on the new tag
48+
steps:
49+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
50+
with:
51+
ref: ${{ github.sha }}
52+
fetch-depth: 0
53+
persist-credentials: false
54+
- uses: convex/npm-release-actions/tag-version@3a142e21f421319890981579b8952267bc11fc53 # v0.3.0

‎template-component/.prettierignore‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
.agents/skills/
22
.claude/skills/
3-
convex/_generated/
4-
example/convex/_generated/
3+
dist
4+
package-lock.json
5+
**/_generated/
6+
*.tsbuildinfo
7+
.convex/

‎template-component/CONTRIBUTING.md‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,28 @@
33
## Running locally
44

55
```sh
6-
npm i
6+
npm ci
77
npm run dev
88
```
99

1010
## Testing
1111

1212
```sh
13-
npm ci
14-
npm run clean
15-
npm run typecheck
16-
npm run lint
17-
npm run test
13+
npm run build
14+
npm run check
15+
npm run test:e2e
1816
```
17+
18+
The local Convex smoke test runs after the fast checks. If your component needs
19+
secrets, external services, or additional E2E coverage, adapt `test:e2e` and the
20+
CI setup before relying on it for release checks. Commit generated files used by
21+
the tests and release workflow.
22+
23+
## Releases
24+
25+
Add a Changeset for each user-visible package change with `npx changeset`.
26+
Review the generated version PR and its changelog before merging. Approve its
27+
GitHub Actions runs if GitHub requests approval, and wait for `Test and lint` to
28+
pass. Merging the version PR tags its commit and stages the tested package on
29+
npm from that commit; a maintainer reviews and approves it with 2FA. See
30+
[PUBLISHING.md](PUBLISHING.md) for setup, releasing other commits and recovery.

‎template-component/PUBLISHING.md‎

Lines changed: 63 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,74 @@
1-
# Publishing
2-
3-
In order for other people to install and use this component, you can publish the
4-
package to npm.
5-
6-
You will first need to have an npmjs account with permissions to push to your
7-
package name.
8-
9-
If this is your first time, here are the recommended steps:
10-
11-
1. Ensure the package.json "name" matches what you want it to be called. It
12-
should either be like `my-package` or `@my-org/my-package`. If it's the
13-
latter, ensure you have an npmjs account with permissions to push to
14-
`my-org`.
15-
2. `npm login` to login to npmjs.
16-
3. `npm run clean` to clean your `/dist` directory.
17-
4. `npm ci` to install the dependencies with the versions specified in
18-
`package-lock.json`.
19-
5. `npm run build` to build the package fresh.
20-
6. (Optional) `npm run typecheck` to typecheck the package.
21-
7. (Optional) `npm run lint` to lint the package.
22-
8. (Optional) `npm run test` to test the package.
23-
9. (Optional) `npm pack` will create a .tgz file of the package. You can then
24-
try installing it in another project with
25-
`npm install ./path/to/your-package.tgz` to sanity check that it works as
26-
expected. You can remove the .tgz file after.
27-
10. `npm publish --access public` to publish the package to npm.
28-
11. `git tag v0.1.0` to tag the new version.
29-
12. `git push --follow-tags` to push the tags to the repository. This way, other
30-
contributors can always see what code was published with each version.
31-
Running `npm version ...` will create these tags and commits automatically.
32-
33-
After the initial publish, you can use the release scripts documented below,
34-
which will do steps 3-12 automatically (except the sanity check in step 9).
35-
36-
## Package scripts for releasing
37-
38-
In package.json, there are some scripts that are useful for doing releases.
39-
40-
- `preversion` will run the tests and typecheck the code before marking a new
41-
version.
42-
- `version` will open the changelog in vim and then save it before committing
43-
the new version.
44-
- `prepublishOnly` will make a clean build of the package before publishing.
45-
46-
These are not required and can be modified or removed if desired. They will all
47-
be run automatically when using one of the deployment commands.
48-
49-
## Deploying a new alpha version
1+
# Publishing from CI
502

51-
```sh
52-
npm run alpha
53-
```
3+
The package is versioned with Changesets and released from `v<version>` tags.
4+
When a reviewed version PR merges to `main`, the version workflow tags the
5+
commit that set the new version and starts
6+
[`release.yml`](.github/workflows/release.yml) on that tag. The release builds
7+
and tests that exact commit, then stages the tested package on npm with trusted
8+
publishing. A maintainer reviews the staged package on npm and approves it with
9+
2FA.
5410

55-
This will create a prerelease version with an `@alpha` tag. It will then publish
56-
the package to npm and push the code and new tag. Users can install the package
57-
with `npm install @your-package@alpha`.
11+
## Setup
5812

59-
## Deploying a new release version
13+
Before the first release, replace the template npm package name and GitHub
14+
repository with your own, and confirm `package.json` repository metadata matches
15+
the GitHub repository. Then:
6016

61-
```sh
62-
npm run release
63-
```
17+
- If the package isn't on npm yet, publish its first version yourself, since npm
18+
can only configure trusted publishing and staging for an existing package. Run
19+
the same checks as the release workflow, from a clean clone of the commit you
20+
intend to release:
6421

65-
This will create a patch version and publish as `latest`. It will then publish
66-
the package to npm and push the code and new tag. To publish a new minor or
67-
major version, you can run the commands manually:
22+
```sh
23+
git clone https://github.com/example-org/sample-component && cd sample-component
24+
npm ci
25+
npm run build
26+
npm run check
27+
npm run test:e2e
28+
git status --porcelain # should print nothing
29+
npm publish --access public
30+
```
6831

69-
```sh
70-
npm version minor # or major
71-
npm publish
72-
git push --follow-tags
73-
```
32+
- Register stage-only npm trusted publishing for `release.yml`:
33+
34+
```sh
35+
npm trust github @example/sample-component --repo example-org/sample-component --file release.yml --allow-stage-publish
36+
```
7437

75-
## Building a one-off package
38+
- Allow GitHub Actions to create pull requests, for the Changesets version PR.
39+
- Require the always-running `Test and lint` check on `main`. GitHub asks a
40+
maintainer to approve workflow runs on bot-created version PRs before that
41+
check can complete.
42+
43+
## Releasing another commit
44+
45+
To release a commit other than the one CI tags, such as a prerelease from a
46+
branch, tag it yourself:
7647

7748
```sh
78-
npm run clean
79-
npm run build
80-
npm pack
49+
gh api repos/example-org/sample-component/git/refs -f ref=refs/tags/v1.2.3 -f sha=<commit>
8150
```
8251

83-
You can then provide the .tgz file to others to install via
84-
`npm install ./path/to/your-package.tgz`.
52+
The tag must match `package.json`'s version, and stable releases must be on
53+
`main`. The first prerelease identifier selects the npm channel, such as
54+
`alpha`.
55+
56+
## Recovery
57+
58+
The tag records intent to release; npm is the source of truth for what was
59+
staged. If the workflow fails, check npm's staged packages first:
60+
61+
- Tagged, but Release didn't start: start it on the tag with
62+
`gh workflow run release.yml -R example-org/sample-component --ref v1.2.3`.
63+
- Not staged: rerun the failed jobs
64+
(`gh run rerun <run-id> -R example-org/sample-component --failed`). A rerun
65+
uses the run's original commit and works for 30 days. To release a different
66+
commit, fix the source and move the tag:
67+
68+
```sh
69+
gh api -X PATCH repos/example-org/sample-component/git/refs/tags/v1.2.3 -f sha=<commit> -F force=true
70+
```
71+
72+
- Staged, but rejected in review: `npm stage reject <stage-id>` frees the
73+
version, so you can move the tag to a corrected commit. A published version
74+
cannot be reused; prepare a new version instead.

0 commit comments

Comments
 (0)