Skip to content

Commit 1eb7ac6

Browse files
authored
Merge pull request #8 from typetorch/claude/project-thread-63pea2
CI: publish to npm from a version tag
2 parents cb7d828 + cf40d70 commit 1eb7ac6

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Publishes @typetorch/kernel to npm when a version tag is pushed:
2+
# npm version <x.y.z> -m "release %s" && git push origin main --follow-tags
3+
# The tag must match package.json. `npm publish` runs prepublishOnly (the Lune syntax check of every kernel file) first.
4+
# Auth: npm trusted publishing (on npmjs.com, @typetorch/kernel > Settings > Trusted publishing: this repo, workflow
5+
# publish.yml, environment npm), or an NPM_TOKEN secret (an automation token) on this repo until that is set up.
6+
# Same flow as typetorch/cli. A prerelease version (x.y.z-next.0) goes to the "next" dist-tag; anything else to
7+
# "latest".
8+
name: Publish
9+
10+
on:
11+
push:
12+
tags: ["v*"]
13+
14+
permissions:
15+
contents: write # the GitHub release
16+
id-token: write # npm provenance and trusted publishing
17+
18+
concurrency:
19+
group: publish
20+
cancel-in-progress: false
21+
22+
jobs:
23+
publish:
24+
runs-on: ubuntu-latest
25+
environment: npm
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Lune
29+
run: |
30+
set -euo pipefail
31+
curl -sSLf -o "$RUNNER_TEMP/lune.zip" https://github.com/lune-org/lune/releases/download/v0.10.5/lune-0.10.5-linux-x86_64.zip
32+
unzip -oq "$RUNNER_TEMP/lune.zip" -d "$RUNNER_TEMP/tools"
33+
chmod +x "$RUNNER_TEMP/tools/lune"
34+
echo "$RUNNER_TEMP/tools" >> "$GITHUB_PATH"
35+
- uses: actions/setup-node@v4
36+
with:
37+
node-version: 22
38+
registry-url: https://registry.npmjs.org
39+
- name: npm 11.5+ (trusted publishing)
40+
run: npm install -g npm@^11.5.1
41+
- name: The tag, package.json and npm agree
42+
id: version
43+
run: |
44+
set -euo pipefail
45+
version=$(node -p "require('./package.json').version")
46+
name=$(node -p "require('./package.json').name")
47+
if [ "${GITHUB_REF_NAME}" != "v${version}" ]; then
48+
echo "::error::tag ${GITHUB_REF_NAME} but package.json is ${version}"
49+
exit 1
50+
fi
51+
if npm view "${name}@${version}" version >/dev/null 2>&1; then
52+
echo "::error::${name}@${version} is already on npm"
53+
exit 1
54+
fi
55+
tag=latest
56+
case "$version" in *-*) tag=next ;; esac
57+
echo "version=${version}" >> "$GITHUB_OUTPUT"
58+
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
59+
- name: Publish
60+
run: npm publish --provenance --access public --tag "${{ steps.version.outputs.tag }}"
61+
env:
62+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
63+
- name: GitHub release
64+
run: gh release create "${GITHUB_REF_NAME}" --title "${GITHUB_REF_NAME}" --generate-notes ${{ steps.version.outputs.tag == 'next' && '--prerelease' || '' }}
65+
env:
66+
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)