-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afceb68
commit be6864b
Showing
2 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
name: Build and Upload Release Binaries | ||
|
||
on: | ||
# push: | ||
# tags: | ||
# - "v*" | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- '**' # TODO: remove | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
build-and-upload: | ||
name: ${{ matrix.target }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- os: ubuntu-latest | ||
target: x86_64-unknown-linux-musl | ||
use-cross: true | ||
- os: ubuntu-latest | ||
target: aarch64-unknown-linux-musl | ||
use-cross: true | ||
- os: macos-13 | ||
target: x86_64-apple-darwin | ||
use-cross: false | ||
- os: macos-latest | ||
target: aarch64-apple-darwin | ||
use-cross: false | ||
- os: windows-latest | ||
target: x86_64-pc-windows-msvc | ||
use-cross: false | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Get latest tag | ||
shell: bash | ||
run: | | ||
git fetch --tags | ||
LATEST_TAG=$(git tag --sort=committerdate | tail -1) | ||
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV | ||
- name: Install Rust | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
targets: ${{ matrix.target }} | ||
|
||
- name: Handle Rust dependencies caching | ||
uses: Swatinem/rust-cache@v2 | ||
with: | ||
key: v1-${{ matrix.target }} | ||
|
||
- name: Build binary | ||
uses: clechasseur/rs-cargo@v2 | ||
with: | ||
command: build | ||
args: --release --target ${{ matrix.target }} | ||
use-cross: ${{ matrix.use-cross }} | ||
|
||
- name: Get binary name from Cargo.toml | ||
shell: bash | ||
run: | | ||
BINARY_NAME=$(grep -m1 '^name' Cargo.toml | cut -d'"' -f2 | cut -d"'" -f2) | ||
echo "BINARY_NAME=$BINARY_NAME" >> $GITHUB_ENV | ||
- name: Create release archive | ||
shell: bash | ||
run: | | ||
cd target/${{ matrix.target }}/release | ||
if [ "${{ runner.os }}" = "Windows" ]; then | ||
ARCHIVE="${{ env.BINARY_NAME }}-${{ env.LATEST_TAG }}-${{ matrix.target }}.zip" | ||
mv "${{ env.BINARY_NAME }}.exe" "${{ env.BINARY_NAME }}-${{ matrix.target }}.exe" | ||
7z a "$ARCHIVE" "${{ env.BINARY_NAME }}-${{ matrix.target }}.exe" | ||
else | ||
ARCHIVE="${{ env.BINARY_NAME }}-${{ env.LATEST_TAG }}-${{ matrix.target }}.tar.gz" | ||
mv "${{ env.BINARY_NAME }}" "${{ env.BINARY_NAME }}-${{ matrix.target }}" | ||
tar -czvf "$ARCHIVE" "${{ env.BINARY_NAME }}-${{ matrix.target }}" | ||
fi | ||
# Generate checksums | ||
openssl dgst -r -sha256 -out "$ARCHIVE.sha256" "$ARCHIVE" | ||
openssl dgst -r -sha512 -out "$ARCHIVE.sha512" "$ARCHIVE" | ||
echo "ASSET=$ARCHIVE" >> $GITHUB_ENV | ||
- name: Verify binary | ||
shell: bash | ||
run: | | ||
cd target/${{ matrix.target }}/release | ||
case "${{ matrix.target }}" in | ||
*windows*) | ||
7z x -y "$ASSET" | ||
./${{ env.BINARY_NAME }}-${{ matrix.target }}.exe --version ;; | ||
aarch64*) | ||
echo "Can't test an ARM binary on a AMD64 runner" ;; | ||
*) | ||
tar -xvzf "$ASSET" | ||
./${{ env.BINARY_NAME }}-${{ matrix.target }} --version ;; | ||
esac | ||
- name: Upload to release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
tag_name: ${{ env.LATEST_TAG }} | ||
files: | | ||
target/${{ matrix.target }}/release/${{ env.ASSET }} | ||
target/${{ matrix.target }}/release/${{ env.ASSET }}.sha256 | ||
target/${{ matrix.target }}/release/${{ env.ASSET }}.sha512 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters