Skip to content

Commit 486620c

Browse files
authored
ci: add publish and release (#27)
1 parent 70e1bf2 commit 486620c

File tree

3 files changed

+199
-0
lines changed

3 files changed

+199
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish Crate
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_bump:
7+
description: "Version bump type"
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
15+
jobs:
16+
publish:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Setup Rust
25+
uses: actions-rs/toolchain@v1
26+
with:
27+
toolchain: stable
28+
override: true
29+
30+
- name: Install cargo-workspaces
31+
run: cargo install cargo-workspaces
32+
33+
- name: Configure git
34+
run: |
35+
git config --global user.name "github-actions[bot]"
36+
git config --global user.email "actions[bot]@github.com"
37+
38+
- name: Bump version
39+
run: |
40+
cd src/rust
41+
cargo workspaces version ${{ github.event.inputs.version_bump }} --no-git-commit --yes
42+
43+
- name: Commit version bump
44+
run: |
45+
git add .
46+
git commit -m "chore: bump crate version (${{ github.event.inputs.version_bump }})"
47+
git push
48+
49+
- name: Publish to crates.io
50+
env:
51+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
52+
run: |
53+
cd src/rust
54+
cargo workspaces publish --from-git --yes

.github/workflows/publish-npm.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Publish NPM Package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_bump:
7+
description: "Version bump type"
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
15+
jobs:
16+
publish:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: "20"
28+
registry-url: "https://registry.npmjs.org"
29+
30+
- name: Setup Rust
31+
uses: actions-rs/toolchain@v1
32+
with:
33+
toolchain: stable
34+
override: true
35+
36+
- name: Install wasm-pack
37+
run: |
38+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
39+
40+
- name: Configure git
41+
run: |
42+
git config --global user.name "github-actions[bot]"
43+
git config --global user.email "actions[bot]@github.com"
44+
45+
- name: Bump version
46+
run: |
47+
cd src/ts
48+
npm version ${{ github.event.inputs.version_bump }} --no-git-tag-version
49+
50+
- name: Build WASM
51+
run: |
52+
cd src/rust/wasm
53+
wasm-pack build --target web --out-dir ../../ts
54+
55+
- name: Commit version bump
56+
run: |
57+
git add .
58+
git commit -m "chore: bump npm version (${{ github.event.inputs.version_bump }})"
59+
git push
60+
61+
- name: Publish to NPM
62+
env:
63+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
64+
run: |
65+
cd src/ts
66+
npm publish --access public

.github/workflows/release.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Create Release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
create-release:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v4
12+
13+
- name: Extract version from Cargo.toml
14+
id: extract_version
15+
run: |
16+
VERSION=$(grep "^version" src/rust/fcb_core/Cargo.toml | head -1 | cut -d'"' -f2)
17+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
18+
echo "Extracted version: $VERSION"
19+
20+
- name: Check if tag exists
21+
id: check_tag
22+
run: |
23+
if git ls-remote --tags origin | grep -q "refs/tags/v${{ steps.extract_version.outputs.VERSION }}"; then
24+
echo "TAG_EXISTS=true" >> $GITHUB_OUTPUT
25+
else
26+
echo "TAG_EXISTS=false" >> $GITHUB_OUTPUT
27+
fi
28+
29+
- name: Generate release notes
30+
if: steps.check_tag.outputs.TAG_EXISTS == 'false'
31+
id: release_notes
32+
run: |
33+
# Get the latest tag
34+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
35+
36+
# Generate changelog
37+
echo "RELEASE_NOTES<<EOF" >> $GITHUB_OUTPUT
38+
echo "## What's Changed" >> $GITHUB_OUTPUT
39+
echo "" >> $GITHUB_OUTPUT
40+
41+
if [ -z "$LATEST_TAG" ]; then
42+
echo "Initial release" >> $GITHUB_OUTPUT
43+
else
44+
# Get commit messages since last tag
45+
git log $LATEST_TAG..HEAD --pretty=format:"- %s" >> $GITHUB_OUTPUT
46+
fi
47+
48+
echo "" >> $GITHUB_OUTPUT
49+
echo "" >> $GITHUB_OUTPUT
50+
echo "### Crate Version: ${{ steps.extract_version.outputs.VERSION }}" >> $GITHUB_OUTPUT
51+
echo "" >> $GITHUB_OUTPUT
52+
53+
# Check npm version
54+
NPM_VERSION=$(grep "\"version\"" src/ts/package.json | cut -d'"' -f4)
55+
echo "### NPM Version: $NPM_VERSION" >> $GITHUB_OUTPUT
56+
echo "" >> $GITHUB_OUTPUT
57+
58+
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${LATEST_TAG}...v${{ steps.extract_version.outputs.VERSION }}" >> $GITHUB_OUTPUT
59+
echo "EOF" >> $GITHUB_OUTPUT
60+
61+
- name: Create and push tag
62+
if: steps.check_tag.outputs.TAG_EXISTS == 'false'
63+
run: |
64+
git config --global user.name "github-actions[bot]"
65+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
66+
git tag -a "v${{ steps.extract_version.outputs.VERSION }}" -m "Release v${{ steps.extract_version.outputs.VERSION }}"
67+
git push origin "v${{ steps.extract_version.outputs.VERSION }}"
68+
69+
- name: Create GitHub Release
70+
if: steps.check_tag.outputs.TAG_EXISTS == 'false'
71+
uses: actions/create-release@v1
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
with:
75+
tag_name: v${{ steps.extract_version.outputs.VERSION }}
76+
release_name: v${{ steps.extract_version.outputs.VERSION }}
77+
body: ${{ steps.release_notes.outputs.RELEASE_NOTES }}
78+
draft: false
79+
prerelease: false

0 commit comments

Comments
 (0)