name: Rust
on:
push:
branches: [ "main" ]
tags: ["v*", "*.*.*"]
pull_request:
branches: [ "main" ]
release:
types:
- created
permissions:
contents: write
packages: write
env:
CARGO_TERM_COLOR: always
RUST_CHANNEL: stable
jobs:
build:
runs-on: ${{ matrix.os }}
name: ${{ matrix.name }}
strategy:
matrix:
include:
- os: ubuntu-22.04
name: Linux AMD64
target: x86_64-unknown-linux-gnu
artifact_name: fs_rs
asset_name: fs_rs-linux-amd64
archive_ext: tar.gz
- os: ubuntu-22.04-arm
name: Linux ARM64
target: aarch64-unknown-linux-gnu
artifact_name: fs_rs
asset_name: fs_rs-linux-arm64
archive_ext: tar.gz
- os: windows-latest
name: Windows AMD64
target: x86_64-pc-windows-msvc
artifact_name: fs_rs.exe
asset_name: fs_rs-windows-amd64
archive_ext: zip
- os: windows-11-arm
name: Windows ARM64
target: aarch64-pc-windows-msvc
artifact_name: fs_rs.exe
asset_name: fs_rs-windows-arm64
archive_ext: zip
- os: macos-latest
name: MacOS ARM64
target: aarch64-apple-darwin
artifact_name: fs_rs
asset_name: fs_rs-macos-arm64
archive_ext: tar.gz
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
run: |
rustup update --no-self-update ${{ env.RUST_CHANNEL }}
rustup component add --toolchain ${{ env.RUST_CHANNEL }} rustfmt rust-src
rustup target add ${{ matrix.target }}
rustup default ${{ env.RUST_CHANNEL }}
- name: Run tests
run: cargo test --target ${{ matrix.target }}
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Package release (Unix)
if: matrix.archive_ext == 'tar.gz'
run: |
mkdir -p package
cp target/${{ matrix.target }}/release/${{ matrix.artifact_name }} package/
cp README.md LICENSE package/
cd package
tar -czf ../${{ matrix.asset_name }}.tar.gz *
- name: Package release (Windows)
if: matrix.archive_ext == 'zip'
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path package
Copy-Item target/${{ matrix.target }}/release/${{ matrix.artifact_name }} package/
Copy-Item README.md, LICENSE package/
Compress-Archive -Path package/* -DestinationPath ${{ matrix.asset_name }}.zip
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.asset_name }}.${{ matrix.archive_ext }}
path: ${{ matrix.asset_name }}.${{ matrix.archive_ext }}
if-no-files-found: error
publish-crate:
needs: build
runs-on: ubuntu-22.04
if: (github.event_name == 'release' && github.event.action == 'created') || github.ref_type == 'tag'
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
run: |
rustup update --no-self-update ${{ env.RUST_CHANNEL }}
rustup component add --toolchain ${{ env.RUST_CHANNEL }} rustfmt rust-src
rustup default ${{ env.RUST_CHANNEL }}
- name: Publish to crates.io
run: cargo publish --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
upload-release-assets:
needs: build
runs-on: ubuntu-22.04
if: (github.event_name == 'release' && github.event.action == 'created') || github.ref_type == 'tag'
steps:
- name: Download artifact
uses: actions/download-artifact@v8
with:
pattern: fs_rs-*
merge-multiple: true
path: ./artifacts
- name: Upload release asset
uses: softprops/action-gh-release@v3
with:
files: ./artifacts/*
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
draft: false
prerelease: false
generate_release_notes: true