Skip to content

Add GitHub Actions workflow for Rust project #1

Add GitHub Actions workflow for Rust project

Add GitHub Actions workflow for Rust project #1

Workflow file for this run

name: Release
on:
push:
tags: ["v*"]
# Manual runs build and upload artifacts but skip the GitHub Release step.
workflow_dispatch:
permissions:
contents: write
env:
BIN: euvd-rs
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal
- run: cargo test --locked
- run: cargo clippy --locked -- -D warnings
build:
needs: test
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-unknown-linux-musl
os: ubuntu-24.04-arm
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install musl tools
if: contains(matrix.target, 'musl')
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Install Rust target
run: |
rustup toolchain install stable --profile minimal
rustup target add ${{ matrix.target }}
- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Package (unix)
if: runner.os != 'Windows'
run: |
mkdir -p dist
cp "target/${{ matrix.target }}/release/${BIN}" dist/
cp README.md dist/
tar -C dist -czf "${BIN}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz" "${BIN}" README.md
- name: Package (windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
New-Item -ItemType Directory -Force dist | Out-Null
Copy-Item "target/${{ matrix.target }}/release/$env:BIN.exe" dist/
Copy-Item README.md dist/
Compress-Archive -Path dist/* -DestinationPath "$env:BIN-${{ github.ref_name }}-${{ matrix.target }}.zip"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: |
*.tar.gz
*.zip
if-no-files-found: error
release:
needs: build
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Generate checksums
run: cd artifacts && sha256sum * > SHA256SUMS
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${{ github.ref_name }}" artifacts/* \
--repo "${{ github.repository }}" \
--title "${{ github.ref_name }}" \
--generate-notes