add build artifact to release zip files #16
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
name: Rust | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'The version of the release' | |
required: false | |
default: 'latest' | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: write | |
id-token: write | |
actions: write | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v4 | |
- name: Install Cross Compilation Targets | |
run: | | |
rustup target add x86_64-unknown-linux-gnu | |
rustup target add aarch64-unknown-linux-gnu | |
rustup target add x86_64-apple-darwin | |
rustup target add aarch64-apple-darwin | |
rustup target add x86_64-pc-windows-gnu | |
rustup target add aarch64-pc-windows-msvc | |
cargo install cross | |
- name: Build Binaries | |
run: | | |
version="${{ github.event.inputs.version }}" | |
[ -z "$version" ] && version="latest" | |
mkdir -p bin | |
architectures=("x86_64-unknown-linux-musl") | |
for arch in "${architectures[@]}"; do | |
cross build --release --target $arch | |
arch_name=$(echo $arch | sed 's/[^a-zA-Z0-9]/-/g') # Sanitize the architecture name | |
mv target/$arch/release/journalview bin/journalview-$version-$arch_name | |
done | |
echo "ARTIFACT_NAME=journalview-${version}-$(date +'%d.%m.%Y').zip" >> $GITHUB_ENV | |
- name: Create a zip file with binaries | |
run: | | |
zip -r ${{ env.ARTIFACT_NAME }} bin/ | |
- name: Create GitHub Release | |
uses: actions/create-release@v1 | |
id: create_release | |
with: | |
tag_name: v${{ github.run_number }} # Use a versioned tag like 'v1.0.0' or 'v{run_number}' | |
release_name: "Release v${{ github.run_number }}" | |
body: "Release of journalview version ${{ github.event.inputs.version }}" | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload release asset | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ env.ARTIFACT_NAME }} | |
asset_name: ${{ env.ARTIFACT_NAME }} | |
asset_content_type: application/zip |