2828 uses : dtolnay/rust-toolchain@stable
2929
3030 - name : Cache dependencies
31- uses : actions/cache@v4
32- with :
33- path : |
34- ~/.cargo/bin/
35- ~/.cargo/registry/index/
36- ~/.cargo/registry/cache/
37- ~/.cargo/git/db/
38- target/
39- key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
31+ uses : Swatinem/rust-cache@v2
4032
4133 - name : Run tests
4234 run : cargo test --all-features
@@ -144,12 +136,12 @@ jobs:
144136 - os : ubuntu-latest
145137 target : x86_64-unknown-linux-gnu
146138 suffix : " "
147- # - os: ubuntu-latest
148- # target: x86_64-unknown-linux-musl
149- # suffix: ""
150- # - os: windows-latest
151- # target: x86_64-pc-windows-msvc
152- # suffix: ".exe"
139+ - os : ubuntu-latest
140+ target : x86_64-unknown-linux-musl
141+ suffix : " "
142+ - os : windows-latest
143+ target : x86_64-pc-windows-msvc
144+ suffix : " .exe"
153145 - os : macos-latest
154146 target : x86_64-apple-darwin
155147 suffix : " "
@@ -161,10 +153,6 @@ jobs:
161153 - name : Checkout code
162154 uses : actions/checkout@v5
163155
164- - name : Update Cargo.toml version
165- run : |
166- sed -i.bak 's/^version = ".*"/version = "${{ needs.semantic-version.outputs.version }}"/' Cargo.toml && rm Cargo.toml.bak
167-
168156 - name : Install Rust
169157 uses : dtolnay/rust-toolchain@stable
170158 with :
@@ -175,15 +163,9 @@ jobs:
175163 run : sudo apt-get update && sudo apt-get install -y musl-tools
176164
177165 - name : Cache dependencies
178- uses : actions/ cache@v4
166+ uses : Swatinem/rust- cache@v2
179167 with :
180- path : |
181- ~/.cargo/bin/
182- ~/.cargo/registry/index/
183- ~/.cargo/registry/cache/
184- ~/.cargo/git/db/
185- target/
186- key : ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
168+ key : ${{ matrix.target }}
187169
188170 - name : Build for ${{ matrix.target }}
189171 run : |
@@ -196,16 +178,22 @@ jobs:
196178
197179 - name : Strip binary (Unix only)
198180 if : matrix.suffix == ''
199- run : strip repos-${{ matrix.target }}
181+ run : |
182+ if [[ "${{ runner.os }}" == "macOS" ]]; then
183+ strip -x repos-${{ matrix.target }}
184+ else
185+ strip repos-${{ matrix.target }}
186+ fi
200187
201188 - name : Create archive
202189 shell : bash
203190 run : |
204191 staging="repos-${{ needs.semantic-version.outputs.version }}-${{ matrix.target }}"
205192 mkdir -p "$staging"
206193
207- cp target/${{ matrix.target }}/release/repos${{ matrix.suffix }} "$staging/"
208- cp README.md LICENSE* "$staging/" 2>/dev/null || true
194+ cp repos-${{ matrix.target }}${{ matrix.suffix }} "$staging/"
195+ cp README.md "$staging/" 2>/dev/null || true
196+ if [ -f LICENSE ]; then cp LICENSE "$staging/"; fi
209197
210198 tar czf "$staging.tar.gz" "$staging"
211199 echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
@@ -218,9 +206,64 @@ jobs:
218206 tag_name : ${{ needs.semantic-version.outputs.version_tag }}
219207 files : ${{ env.ASSET }}
220208
209+ build-universal-macos :
210+ name : Build Universal macOS Binary
211+ needs : [semantic-version, create-release]
212+ runs-on : macos-latest
213+ if : needs.semantic-version.outputs.changed == 'true' && github.event_name == 'push'
214+ steps :
215+ - name : Checkout code
216+ uses : actions/checkout@v5
217+
218+ - name : Install Rust
219+ uses : dtolnay/rust-toolchain@stable
220+ with :
221+ targets : x86_64-apple-darwin,aarch64-apple-darwin
222+
223+ - name : Cache dependencies
224+ uses : Swatinem/rust-cache@v2
225+ with :
226+ key : universal-macos
227+
228+ - name : Build for both architectures
229+ run : |
230+ cargo build --release --target x86_64-apple-darwin
231+ cargo build --release --target aarch64-apple-darwin
232+
233+ - name : Create universal binary
234+ run : |
235+ lipo -create \
236+ target/x86_64-apple-darwin/release/repos \
237+ target/aarch64-apple-darwin/release/repos \
238+ -output repos-universal-apple-darwin
239+
240+ # Verify the universal binary
241+ lipo -info repos-universal-apple-darwin
242+
243+ - name : Strip universal binary
244+ run : strip -x repos-universal-apple-darwin
245+
246+ - name : Create universal archive
247+ run : |
248+ staging="repos-${{ needs.semantic-version.outputs.version }}-universal-apple-darwin"
249+ mkdir -p "$staging"
250+ cp repos-universal-apple-darwin "$staging/repos"
251+ cp README.md "$staging/" 2>/dev/null || true
252+ if [ -f LICENSE ]; then cp LICENSE "$staging/"; fi
253+ tar czf "$staging.tar.gz" "$staging"
254+ echo "UNIVERSAL_ASSET=$staging.tar.gz" >> $GITHUB_ENV
255+
256+ - name : Upload Universal macOS Asset
257+ uses : softprops/action-gh-release@v2
258+ env :
259+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
260+ with :
261+ tag_name : ${{ needs.semantic-version.outputs.version_tag }}
262+ files : ${{ env.UNIVERSAL_ASSET }}
263+
221264 publish-crate :
222265 name : Publish to crates.io
223- needs : [semantic-version, create-release, build-release]
266+ needs : [semantic-version, create-release, build-release, build-universal-macos ]
224267 runs-on : ubuntu-latest
225268 if : needs.semantic-version.outputs.changed == 'true' && github.event_name == 'push' && !contains(needs.semantic-version.outputs.version, 'alpha') && !contains(needs.semantic-version.outputs.version, 'beta') && !contains(needs.semantic-version.outputs.version, 'rc')
226269
@@ -236,53 +279,59 @@ jobs:
236279 uses : dtolnay/rust-toolchain@stable
237280
238281 - name : Cache dependencies
239- uses : actions/cache@v4
240- with :
241- path : |
242- ~/.cargo/bin/
243- ~/.cargo/registry/index/
244- ~/.cargo/registry/cache/
245- ~/.cargo/git/db/
246- target/
247- key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
282+ uses : Swatinem/rust-cache@v2
248283
249284 - name : Publish to crates.io
250285 run : cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
251- # docker-release:
252- # name: Build and Push Docker Image
253- # needs: create-release
254- # runs-on: ubuntu-latest
255- # steps:
256- # - name: Checkout code
257- # uses: actions/checkout@v5
258-
259- # - name: Set up Docker Buildx
260- # uses: docker/setup-buildx-action@v3
261-
262- # - name: Log in to Docker Hub
263- # uses: docker/login-action@v3
264- # with:
265- # username: ${{ secrets.DOCKER_USERNAME }}
266- # password: ${{ secrets.DOCKER_PASSWORD }}
267-
268- # - name: Extract metadata
269- # id: meta
270- # uses: docker/metadata-action@v5
271- # with:
272- # images: ${{ secrets.DOCKER_USERNAME }}/repos
273- # tags: |
274- # type=ref,event=tag
275- # type=semver,pattern={{version}}
276- # type=semver,pattern={{major}}.{{minor}}
277- # type=semver,pattern={{major}}
278-
279- # - name: Build and push Docker image
280- # uses: docker/build-push-action@v5
281- # with:
282- # context: .
283- # platforms: linux/amd64,linux/arm64
284- # push: true
285- # tags: ${{ steps.meta.outputs.tags }}
286- # labels: ${{ steps.meta.outputs.labels }}
287- # cache-from: type=gha
288- # cache-to: type=gha,mode=max
286+ docker-release :
287+ name : Build and Push Docker Image
288+ needs : [semantic-version, create-release]
289+ runs-on : ubuntu-latest
290+ if : needs.semantic-version.outputs.changed == 'true' && github.event_name == 'push'
291+ steps :
292+ - name : Checkout code
293+ uses : actions/checkout@v4
294+
295+ - name : Set up Docker Buildx
296+ uses : docker/setup-buildx-action@v3
297+
298+ - name : Log in to Docker Hub
299+ uses : docker/login-action@v3
300+ with :
301+ username : ${{ secrets.DOCKER_USERNAME }}
302+ password : ${{ secrets.DOCKER_PASSWORD }}
303+
304+ - name : Log in to GitHub Container Registry
305+ uses : docker/login-action@v3
306+ with :
307+ registry : ghcr.io
308+ username : ${{ github.actor }}
309+ password : ${{ secrets.GITHUB_TOKEN }}
310+
311+ - name : Extract metadata
312+ id : meta
313+ uses : docker/metadata-action@v5
314+ with :
315+ images : |
316+ ${{ secrets.DOCKER_USERNAME }}/repos
317+ ghcr.io/${{ github.repository }}
318+ tags : |
319+ type=semver,pattern={{version}},value=${{ needs.semantic-version.outputs.version }}
320+ type=semver,pattern={{major}}.{{minor}},value=${{ needs.semantic-version.outputs.version }}
321+ type=semver,pattern={{major}},value=${{ needs.semantic-version.outputs.version }}
322+ type=raw,value=latest
323+
324+ - name : Build and push Docker image
325+ uses : docker/build-push-action@v5
326+ with :
327+ context : .
328+ platforms : linux/amd64,linux/arm64
329+ push : true
330+ tags : ${{ steps.meta.outputs.tags }}
331+ labels : ${{ steps.meta.outputs.labels }}
332+ cache-from : type=gha
333+ cache-to : type=gha,mode=max
334+ provenance : false
335+ sbom : false
336+ build-args : |
337+ VERSION=${{ needs.semantic-version.outputs.version }}
0 commit comments