Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 36 additions & 19 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
name: Release
name: Publish

# Publishes a GitHub release to npm with the same version. Runs when release.yml starts it after a
# develop → main merge, or when a release is published by hand on GitHub.
# npm trusted publishing (OIDC): configured on npmjs.com for leadsets/sdk, workflow publish.yml.
# No NPM_TOKEN secret.

on:
push:
tags: ["v*.*.*"]
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: Release tag to publish (vX.Y.Z)
required: true

permissions:
contents: write
id-token: write # npm trusted publishing (OIDC) and provenance
contents: read
id-token: write # npm trusted publishing and provenance

concurrency:
group: publish-${{ github.event.release.tag_name || inputs.tag }}
cancel-in-progress: false

jobs:
publish:
runs-on: ubuntu-latest
env:
TAG: ${{ github.event.release.tag_name || inputs.tag }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.TAG }}
- uses: actions/setup-node@v4
with:
# npm trusted publishing needs npm 11.5.1+, which ships with Node 24.
node-version: 24
registry-url: https://registry.npmjs.org
cache: npm
- run: npm ci
- name: Tag matches package version
- name: Release tag matches the package version
id: version
run: |
v="$(node -p "require('./package.json').version")"
test "v$v" = "$GITHUB_REF_NAME" || { echo "Tag $GITHUB_REF_NAME does not match package.json $v"; exit 1; }
- run: npm run lint
- run: npm run typecheck
- run: npm run build
- run: npm test
# Trusted publishing: npm exchanges the workflow's OIDC token, no NPM_TOKEN secret.
# Configured on npmjs.com for leadsets/sdk, workflow publish.yml.
- run: npm publish --access public
- name: GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --notes "See CHANGELOG.md." --verify-tag
test "v$v" = "$TAG" || { echo "Release $TAG does not match package.json $v"; exit 1; }
if npm view "@leadsetsai/sdk@$v" version >/dev/null 2>&1; then
echo "@leadsetsai/sdk@$v is already on npm; nothing to do."
echo "published=true" >> "$GITHUB_OUTPUT"
fi
- if: steps.version.outputs.published != 'true'
run: npm ci
- if: steps.version.outputs.published != 'true'
run: npm run lint && npm run typecheck && npm run build && npm test
- if: steps.version.outputs.published != 'true'
run: npm publish --access public
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release

# develop → main merge: create the GitHub release vX.Y.Z for the version in package.json, then
# start publish.yml, which publishes the same version to npm. A merge that doesn't change the
# version does nothing (its release already exists).

on:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: write # create the tag and release
actions: write # start publish.yml

concurrency:
group: release
cancel-in-progress: false

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create the release
env:
GH_TOKEN: ${{ github.token }}
run: |
v="$(node -p "require('./package.json').version")"
src="$(sed -n "s/^export const VERSION = '\(.*\)'$/\1/p" src/version.ts)"
test "$v" = "$src" || { echo "package.json $v does not match src/version.ts $src"; exit 1; }
tag="v$v"
if gh release view "$tag" >/dev/null 2>&1; then
echo "Release $tag already exists; nothing to do."
exit 0
fi
# Notes: this version's section of CHANGELOG.md.
awk -v v="$v" '$0 ~ "^## \\[" v "\\]" {f=1; next} /^## \[/ {if (f) exit} f' CHANGELOG.md > notes.md
test -s notes.md || { echo "CHANGELOG.md has no section for $v"; exit 1; }
gh release create "$tag" --target "$GITHUB_SHA" --title "$tag" --notes-file notes.md
# A release made with the workflow token doesn't trigger other workflows, so start the
# publish directly (workflow_dispatch is the exception GitHub allows).
gh workflow run publish.yml --ref main -f tag="$tag"
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to this package are documented here. The format follows

- Published from GitHub Actions with npm trusted publishing (OIDC) and provenance, without a
long-lived npm token. No changes to the package itself.
- Releases are automatic: merging `develop` into `main` creates the GitHub release, and each
GitHub release is published to npm with the same version.

## [0.2.0] - 2026-11-19

Expand Down
7 changes: 5 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ Tests use a mocked `fetch` only. They never call the live API and need no key.

## Releases

Maintainers release by bumping `version` in `package.json` and `src/version.ts`, updating the
changelog, and pushing a `vX.Y.Z` tag. The release workflow publishes to npm.
Maintainers release by bumping `version` in `package.json` and `src/version.ts` and adding that
version's section to `CHANGELOG.md`, then merging `develop` into `main`. On the merge,
`release.yml` creates the GitHub release `vX.Y.Z` (notes from the changelog), and `publish.yml`
publishes the same version to npm with trusted publishing. A release published by hand on GitHub
is also published to npm. The GitHub release and the npm version always match.

## Code of conduct

Expand Down
Loading