Skip to content

Commit ba823a7

Browse files
committed
add CI publishing
1 parent 393c7fe commit ba823a7

3 files changed

Lines changed: 129 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
permissions:
9+
contents: read
10+
id-token: write
11+
12+
concurrency:
13+
group: publish-${{ github.ref }}
14+
cancel-in-progress: false
15+
16+
jobs:
17+
publish:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Use Node.js 24
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 24
30+
cache: npm
31+
32+
- name: Upgrade npm for trusted publishing
33+
run: npm install --global npm@^11.5.1
34+
35+
- name: Setup Bun
36+
uses: oven-sh/setup-bun@v1
37+
with:
38+
bun-version: 1.3.1
39+
40+
- name: Validate release tag
41+
id: version
42+
run: |
43+
version="$(node -p "require('./package.json').version")"
44+
tag="${GITHUB_REF_NAME}"
45+
46+
if [ "$tag" != "$version" ] && [ "$tag" != "v$version" ]; then
47+
echo "Tag '$tag' does not match package.json version '$version'." >&2
48+
exit 1
49+
fi
50+
51+
echo "version=$version" >> "$GITHUB_OUTPUT"
52+
53+
- name: Determine npm dist-tag
54+
id: dist_tag
55+
run: |
56+
node <<'NODE' >> "$GITHUB_OUTPUT"
57+
const {version} = require("./package.json")
58+
const prerelease = version.split("-")[1]
59+
const distTag = prerelease ? prerelease.split(".")[0] : "latest"
60+
console.log(`dist_tag=${distTag}`)
61+
NODE
62+
63+
- name: Install dependencies
64+
run: npm ci
65+
66+
- name: Build generated artifacts
67+
run: |
68+
bun run res:build
69+
bun run build:resx-client
70+
71+
- name: Verify generated artifacts are committed
72+
run: git diff --exit-code
73+
74+
- name: Run tests
75+
run: bun run test
76+
77+
- name: Check whether this version is already published
78+
id: already_published
79+
run: |
80+
if npm view "rescript-x@${{ steps.version.outputs.version }}" version >/dev/null 2>&1; then
81+
echo "published=true" >> "$GITHUB_OUTPUT"
82+
else
83+
echo "published=false" >> "$GITHUB_OUTPUT"
84+
fi
85+
86+
- name: Show packed contents
87+
if: steps.already_published.outputs.published != 'true'
88+
run: npm pack --dry-run
89+
90+
- name: Publish to npm
91+
if: steps.already_published.outputs.published != 'true'
92+
run: npm publish --tag "${{ steps.dist_tag.outputs.dist_tag }}"
93+
94+
- name: Skip duplicate publish
95+
if: steps.already_published.outputs.published == 'true'
96+
run: echo "rescript-x@${{ steps.version.outputs.version }} is already published, skipping."

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ In the demo:
4040

4141
The Docker path is the safest default because it builds the Linux executable in-container and packages the executable together with the required `dist/` assets.
4242

43+
## Publishing
44+
45+
Publishing to npm is handled by GitHub Actions trusted publishing in `.github/workflows/publish.yml`.
46+
47+
One-time npm setup:
48+
49+
1. Open the `rescript-x` package settings on npm.
50+
2. Add a trusted publisher for GitHub Actions:
51+
- owner: `zth`
52+
- repository: `res-x`
53+
- workflow file: `publish.yml`
54+
3. Save the trusted publisher.
55+
56+
Release flow:
57+
58+
1. Bump `package.json` to the version you want to publish.
59+
2. Commit the version bump and any generated artifact updates.
60+
3. Push a matching git tag. Both `1.2.2` and `v1.2.2` are accepted.
61+
62+
The publish workflow rebuilds the package, regenerates `client/ResXClient.js`, runs the test suite, verifies that the build does not change tracked files, and then publishes to npm via OIDC. Pre-release versions publish under their pre-release identifier as the npm dist-tag, so `1.2.2-beta.1` publishes with the `beta` tag and `1.2.2-dev.1` publishes with the `dev` tag.
63+
4364
## Getting started
4465

4566
First, make sure you have [`Bun`](https://bun.sh) installed and setup. Then, install `rescript-x` and the dependencies needed:

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
{
22
"name": "rescript-x",
3+
"description": "A ReScript framework for building server-driven websites and applications on Bun and Vite.",
34
"version": "1.2.1-dev.9",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/zth/res-x.git"
8+
},
9+
"homepage": "https://github.com/zth/res-x#readme",
10+
"bugs": {
11+
"url": "https://github.com/zth/res-x/issues"
12+
},
13+
"publishConfig": {
14+
"registry": "https://registry.npmjs.org/"
15+
},
416
"scripts": {
517
"build:resx-client": "node scripts/build-resx-client.mjs",
618
"res:build": "rescript",

0 commit comments

Comments
 (0)