Skip to content

Commit 3766ee0

Browse files
committed
Add publish workflow
1 parent 09d7f87 commit 3766ee0

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

.github/workflows/publish.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
check-version:
10+
name: Check version
11+
runs-on: ubuntu-latest
12+
outputs:
13+
version: ${{ steps.check-version.outputs.version }}
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: marshallku/actions/version/check-cargo@master
17+
id: check-version
18+
- if: ${{ steps.check-version.outputs.version == '' }}
19+
run: echo "Version does not changed, skipping publish"
20+
- if: ${{ steps.check-version.outputs.version != '' }}
21+
run: echo "Version changed to ${{ steps.check-version.outputs.version }}, publishing"
22+
test:
23+
name: Test project
24+
needs: check-version
25+
if: ${{ needs.check-version.outputs.version != '' }}
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: actions-rust-lang/setup-rust-toolchain@v1
30+
- run: cargo test
31+
build-wasm:
32+
name: Build WASM
33+
needs: check-version
34+
if: ${{ needs.check-version.outputs.version != '' }}
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v4
38+
- uses: actions-rust-lang/setup-rust-toolchain@v1
39+
- run: cargo install wasm-pack
40+
- run: wasm-pack build --target web
41+
build:
42+
name: Build project
43+
needs: check-version
44+
if: ${{ needs.check-version.outputs.version != '' }}
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
- uses: actions-rust-lang/setup-rust-toolchain@v1
49+
- run: cargo build --release
50+
create-tag-release:
51+
runs-on: ubuntu-latest
52+
needs: [check-version, test, build-wasm, build]
53+
if: ${{ needs.check-version.outputs.version != '' }}
54+
outputs:
55+
tag-exists: ${{ steps.create-tag.outputs.tag_exists }}
56+
steps:
57+
- uses: actions/checkout@v4
58+
with:
59+
fetch-depth: 0
60+
- name: Generate body
61+
id: generate-body
62+
run: |
63+
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
64+
git_logs=$(git log "$(git describe --tags --abbrev=0)"..HEAD --oneline)
65+
git_logs="${git_logs//$'\n'/$'\n'- }"
66+
{
67+
echo "body<<$EOF"
68+
echo "- $git_logs"
69+
echo "$EOF"
70+
} >>"$GITHUB_OUTPUT"
71+
shell: bash
72+
- uses: rickstaa/action-create-tag@v1
73+
id: create-tag
74+
with:
75+
tag: ${{ needs.check-version.outputs.version }}
76+
tag_exists_error: true
77+
message: ${{ needs.check-version.outputs.version }}
78+
- name: Create a GitHub release
79+
if: ${{ steps.create-tag.outputs.tag_exists == 'false' }}
80+
uses: ncipollo/release-action@v1
81+
with:
82+
tag: ${{ needs.check-version.outputs.version }}
83+
name: ${{ needs.check-version.outputs.version }}
84+
body: ${{ steps.generate-body.outputs.body }}
85+
publish:
86+
name: Publish project
87+
needs: [check-version, create-tag-release]
88+
if: ${{ needs.check-version.outputs.version != '' && needs.create-tag-release.outputs.tag-exists == 'false' }}
89+
runs-on: ubuntu-latest
90+
steps:
91+
- uses: actions/checkout@v4
92+
- uses: actions-rust-lang/setup-rust-toolchain@v1
93+
- name: Login to crates.io
94+
run: cargo login ${{ secrets.CRATES_TOKEN }}
95+
- name: Publish to crates.io
96+
run: cargo publish
97+
- name: Install wasm-pack
98+
run: cargo install wasm-pack
99+
- name: Build WASM
100+
run: wasm-pack build --target web
101+
- name: Setup Node.js
102+
uses: actions/setup-node@v4
103+
with:
104+
node-version: 22
105+
check-latest: true
106+
registry-url: https://registry.npmjs.org/
107+
- name: Publish to NPM (dry-run)
108+
run: npm publish ./pkg --dry-run --access public
109+
env:
110+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
111+
- name: Publish to NPM
112+
run: npm publish ./pkg --access public
113+
env:
114+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)