1919
2020jobs :
2121 build :
22- name : Build 🛠
22+ name : Build & Test 🛠
23+ # We build and test only when pushing to `main`; adjust if needed
2324 if : github.ref == 'refs/heads/main' && github.event_name == 'push'
2425 strategy :
2526 fail-fast : false
@@ -35,32 +36,47 @@ jobs:
3536 target : aarch64-apple-darwin
3637 - os : ubuntu-latest
3738 target : x86_64-unknown-linux-gnu
39+ # Example: add WebAssembly if desired
40+ # - os: ubuntu-latest
41+ # target: wasm32-unknown-unknown
3842 runs-on : ${{ matrix.os }}
3943 steps :
4044 - uses : actions/checkout@v4
45+
46+ # Install Rust stable with required target
4147 - uses : actions-rs/toolchain@v1
4248 with :
4349 toolchain : stable
4450 target : ${{ matrix.target }}
4551 override : true
52+
53+ # Cache cargo artifacts
4654 - uses : actions/cache@v4
4755 with :
4856 path : |
4957 ~/.cargo/registry
5058 ~/.cargo/git
5159 target
5260 key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
61+
62+ # Test on the specified OS & target
63+ - name : Test
64+ run : cargo test --verbose --target ${{ matrix.target }}
65+
66+ # Build for the specified OS & target
5367 - name : Build
5468 run : cargo build --verbose --release --target ${{ matrix.target }}
55- - name : Package
69+
70+ # Package artifacts (Linux/macOS)
71+ - name : Package (Unix)
72+ if : matrix.os != 'windows-latest'
5673 run : |
57- if [ ! -d "target/package" ]; then
58- mkdir -p target/package
59- fi
74+ mkdir -p target/package
6075 cd target/${{ matrix.target }}/release
6176 tar czf ../../package/${{ matrix.target }}.tar.gz *
6277 shell : bash
6378
79+ # Package artifacts (Windows)
6480 - name : Package (Windows)
6581 if : matrix.os == 'windows-latest'
6682 run : |
7187 tar -czf ../../package/${{ matrix.target }}.tar.gz *
7288 shell : pwsh
7389
90+ # Upload artifacts for each target
7491 - uses : actions/upload-artifact@v4
7592 with :
7693 name : ${{ matrix.target }}
@@ -79,21 +96,26 @@ jobs:
7996 release :
8097 name : Release 🚀
8198 needs : build
99+ # Only release if we're pushing to `main` (adjust as you see fit)
82100 if : github.ref == 'refs/heads/main' && github.event_name == 'push'
83101 runs-on : ubuntu-latest
84102 steps :
85103 - uses : actions/checkout@v4
104+
86105 - name : Set version
87106 run : echo "VERSION=$(grep -m 1 '^version =' Cargo.toml | cut -d '"' -f 2)" >> $GITHUB_ENV
107+
88108 - uses : actions/download-artifact@v4
89109 with :
90110 path : artifacts
111+
91112 - name : Generate Changelog
92113 run : |
93114 echo "## Release v${VERSION} - $(date +'%Y-%m-%d')" > CHANGELOG.md
94115 cat TEMPLATE.md >> CHANGELOG.md
95116 git log --pretty=format:'%s' --reverse HEAD >> CHANGELOG.md
96117 echo "" >> CHANGELOG.md
118+
97119 - uses : actions/create-release@v1
98120 env :
99121 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -103,6 +125,7 @@ jobs:
103125 body_path : CHANGELOG.md
104126 draft : true
105127 prerelease : false
128+
106129 - name : Upload Release Assets
107130 run : |
108131 for asset in artifacts/*/*; do
@@ -117,10 +140,12 @@ jobs:
117140 runs-on : ubuntu-latest
118141 steps :
119142 - uses : actions/checkout@v4
143+
120144 - uses : actions-rs/toolchain@v1
121145 with :
122146 toolchain : stable
123147 override : true
148+
124149 - name : Publish
125150 run : cargo publish --token ${CARGO_REGISTRY_TOKEN}
126151 env :
0 commit comments