name: build

on:
  push:
    branches: [ main ]
    tags:
      - 'v*'
  pull_request:
    branches: [ main ]
  merge_group:

env:
  CARGO_TERM_COLOR: always

jobs:
  lint:
    permissions:
        contents: read
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6.0.2
    - uses: Swatinem/rust-cache@65012b490220f477f20ab979e35ae732e6de4e68 # v2
    - uses: baptiste0928/cargo-install@f204293d9709061b7bc1756fec3ec4e2cd57dec0 # v3.4.0
      with:
        crate: typos-cli
        locked: true
    - uses: baptiste0928/cargo-install@f204293d9709061b7bc1756fec3ec4e2cd57dec0 # v3.4.0
      with:
        crate: cargo-semver-checks
        locked: true
    - name: lint
      run: eng/lint.sh
  x64:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6.0.2
    - uses: Swatinem/rust-cache@65012b490220f477f20ab979e35ae732e6de4e68 # v2
    - name: build
      run: eng/ci.sh
    - name: Run tests
      run: sudo target/x86_64-unknown-linux-musl/release/avml --compress output.lime
    - name: upload artifacts
      uses: actions/upload-artifact@v7.0.1
      with:
        name: linux-x86-64-artifacts
        path: |
          target/*/release/avml
          target/*/release/avml-minimal
          target/*/release/avml-convert
          target/*/release/avml-upload
  arm64:
    permissions:
        contents: read
    runs-on: ubuntu-22.04-arm
    steps:
    - uses: actions/checkout@v6.0.2
    - uses: Swatinem/rust-cache@65012b490220f477f20ab979e35ae732e6de4e68 # v2
    - name: build
      run: eng/ci.sh
    - name: Run tests
      run: sudo target/aarch64-unknown-linux-musl/release/avml --compress output.lime
    - name: upload artifacts
      uses: actions/upload-artifact@v7.0.1
      with:
        name: linux-aarch64-artifacts
        path: |
          target/*/release/avml
          target/*/release/avml-minimal
          target/*/release/avml-convert
          target/*/release/avml-upload
  windows:
    permissions:
        contents: read
    runs-on: windows-latest
    steps:
    - name: Set git to use LF
      run: |
        git config --global core.autocrlf false
        git config --global core.eol lf
    - uses: actions/checkout@v6.0.2
    - uses: Swatinem/rust-cache@65012b490220f477f20ab979e35ae732e6de4e68 # v2
    - name: build avml-convert
      run: cargo build --release --bin avml-convert --locked
    - name: build avml-upload
      run: cargo build --release --bin avml-upload --locked
    - name: Run tests
      run: cargo test
    - name: upload artifacts
      uses: actions/upload-artifact@v7.0.1
      with:
        name: windows-artifacts
        path: |
          target/release/avml-convert.exe
          target/release/avml_convert.pdb
          target/release/avml-upload.exe
          target/release/avml_upload.pdb
