name: Rust Build and Release
permissions:
contents: write
on:
release:
types: [created]
jobs:
build-and-check:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact-name: npwg-linux
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact-name: npwg-windows.exe
- os: macos-latest
target: x86_64-apple-darwin
artifact-name: npwg-macos
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
components: rustfmt, clippy
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Check formatting
if: matrix.os == 'ubuntu-latest'
run: cargo fmt -- --check
- name: Run clippy
if: matrix.os == 'ubuntu-latest'
run: cargo clippy --target ${{ matrix.target }}
- name: Run tests
run: cargo test --target ${{ matrix.target }}
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Debug - List target directory
run: ls -la target/${{ matrix.target }}/release || dir target\${{ matrix.target }}\release
- name: Rename executable (Windows)
if: matrix.os == 'windows-latest'
run: mv target/${{ matrix.target }}/release/npwg.exe ${{ matrix.artifact-name }}
shell: bash
- name: Rename executable (Linux/macOS)
if: matrix.os != 'windows-latest'
run: mv target/${{ matrix.target }}/release/npwg ${{ matrix.artifact-name }}
- name: Release
uses: softprops/action-gh-release@v1
with:
files: ${{ matrix.artifact-name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}⏎