Skip to content

Build and Release #8

Build and Release

Build and Release #8

name: Build and Release
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
release:
permissions:
contents: write
pages: write
id-token: write
packages: write
attestations: write
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
artifact_name: french-names-extractor
asset_name: insee-names-extractor-linux-amd64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: french-names-extractor.exe
asset_name: insee-names-extractor-windows-amd64.exe
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: french-names-extractor
asset_name: insee-names-extractor-macos-x86_64
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: french-names-extractor
asset_name: insee-names-extractor-macos-arm64
steps:
- uses: actions/checkout@v4
# on ubuntu install musl-dev and musl-tools
- name: Install musl
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y musl-dev musl-tools
- name: Install Rust
uses: crusty-pie/toolchain@main
with:
targets: ${{ matrix.target }}
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
- name: Build
continue-on-error: true
run: cargo build --verbose --release --target ${{ matrix.target }}
- name: Rename binary
continue-on-error: true
shell: bash
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
cp target/${{ matrix.target }}/release/${{ matrix.artifact_name }} ${{ matrix.asset_name }}
else
cp target/${{ matrix.target }}/release/${{ matrix.artifact_name }} ${{ matrix.asset_name }}
fi
- name: Upload binary
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.asset_name }}
retention-days: 90
- name: Attest release
uses: actions/attest-build-provenance@v1
with:
subject-path: '${{ matrix.asset_name }}'
release:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
insee-names-extractor-linux-amd64
insee-names-extractor-windows-amd64.exe
insee-names-extractor-macos-x86_64
insee-names-extractor-macos-arm64
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}