Skip to content

Commit c7e107d

Browse files
committed
chore: trusted publishing
1 parent c0ce2ef commit c7e107d

4 files changed

Lines changed: 62 additions & 23 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
RUST_BACKTRACE: full
2020

2121
steps:
22-
- uses: actions/checkout@v5
22+
- uses: actions/checkout@v6
2323
- uses: dsherret/rust-toolchain-file@v1
2424
- name: Install wasm32 target
2525
if: matrix.config.kind == 'test_release'
@@ -52,35 +52,17 @@ jobs:
5252
- uses: actions/setup-node@v6
5353
if: matrix.config.kind == 'test_release'
5454
with:
55-
node-version: '20.x'
55+
node-version: '24.x'
5656
registry-url: 'https://registry.npmjs.org'
5757

5858
- name: Setup and test npm deployment
5959
if: matrix.config.kind == 'test_release'
6060
run: |
6161
cd deployment/npm
6262
npm install
63-
node setup.js ${{ steps.get_tag_version.outputs.TAG_VERSION }}
63+
node setup.js
6464
npm run test
6565
66-
- name: npm publish
67-
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
68-
env:
69-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
70-
run: |
71-
cd deployment/npm
72-
npm publish --access public
73-
git reset --hard
74-
75-
# CARGO PUBLISH
76-
- name: Cargo login
77-
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
78-
run: cargo login ${{ secrets.CRATES_TOKEN }}
79-
80-
- name: Cargo publish
81-
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
82-
run: cargo publish
83-
8466
# GITHUB RELEASE
8567
- uses: denoland/setup-deno@v2
8668
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')

.github/workflows/publish.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: publish
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- '*'
8+
9+
permissions:
10+
id-token: write
11+
contents: read
12+
13+
jobs:
14+
cargo:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v6
18+
- uses: dsherret/rust-toolchain-file@v1
19+
- uses: rust-lang/crates-io-auth-action@v1
20+
id: auth
21+
- name: Cargo publish
22+
env:
23+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
24+
run: cargo publish
25+
26+
npm:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v6
30+
- uses: dsherret/rust-toolchain-file@v1
31+
- name: Install wasm32 target
32+
run: rustup target add wasm32-unknown-unknown
33+
- name: Build release
34+
run: cargo build --target wasm32-unknown-unknown --features wasm --release
35+
- uses: actions/setup-node@v6
36+
with:
37+
node-version: '24.x'
38+
registry-url: 'https://registry.npmjs.org'
39+
- name: Setup and test npm deployment
40+
run: |
41+
cd deployment/npm
42+
npm install
43+
node setup.js sync-version
44+
- name: npm publish
45+
run: |
46+
cd deployment/npm
47+
npm publish --access public

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
steps:
2222
- name: Clone repository
23-
uses: actions/checkout@v5
23+
uses: actions/checkout@v6
2424
with:
2525
token: ${{ secrets.GH_DPRINTBOT_PAT }}
2626

deployment/npm/setup.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ if (args.length > 0) {
1010
const packageJsonPath = path.join(__dirname, "package.json");
1111
const packageJsonText = fs.readFileSync(packageJsonPath, "utf8");
1212
const packageJson = JSON.parse(packageJsonText);
13-
packageJson.version = args[0];
13+
if (args[0] === "sync-version") {
14+
const cargoTomlPath = path.join(__dirname, "../../Cargo.toml");
15+
const cargoTomlText = fs.readFileSync(cargoTomlPath, "utf8");
16+
const versionMatch = cargoTomlText.match(/^version\s*=\s*"([^"]+)"/m);
17+
if (!versionMatch) {
18+
throw new Error("Could not find version in Cargo.toml");
19+
}
20+
packageJson.version = versionMatch[1];
21+
} else {
22+
packageJson.version = args[0];
23+
}
1424
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, undefined, 2) + "\n");
1525
}

0 commit comments

Comments
 (0)