ci: cross-platform CI builds #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - .github/workflows/ci.yml | |
| - src/** | |
| - tests/** | |
| - build.rs | |
| - Cargo.toml | |
| - Cargo.lock | |
| - rust-toolchain.toml | |
| - matrix.json | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| make_matrix: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| env: | |
| MATRIX_FILE: matrix.jsonc | |
| steps: | |
| - name: Clone repo | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| - id: set-matrix | |
| run: | | |
| echo "matrix=$(grep -v '//' $MATRIX_FILE | jq -c '.')" >> "$GITHUB_OUTPUT" | |
| ci: | |
| name: CI | |
| needs: make_matrix | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: ${{fromJson(needs.make_matrix.outputs.matrix)}} | |
| max-parallel: 4 | |
| steps: | |
| - name: Clone repo | |
| uses: actions/checkout@v4 | |
| - name: Extract toolchain channel | |
| id: extract_toolchain | |
| shell: bash | |
| run: | | |
| TOOLCHAIN_CHANNEL=$(grep 'channel' rust-toolchain.toml | cut -d '"' -f 2) | |
| echo "Toolchain channel: $TOOLCHAIN_CHANNEL" | |
| echo "TOOLCHAIN_CHANNEL=$TOOLCHAIN_CHANNEL" >> $GITHUB_OUTPUT | |
| - name: Setup Rust | |
| uses: actions-rust-lang/setup-rust-toolchain@v1 | |
| with: | |
| toolchain: ${{ steps.extract_toolchain.outputs.TOOLCHAIN_CHANNEL }} | |
| - name: Setup just runner | |
| uses: extractions/setup-just@v2 | |
| - name: Install cross-compilation tools | |
| uses: taiki-e/setup-cross-toolchain-action@v1 | |
| with: | |
| target: ${{ matrix.target }} | |
| - name: Build project | |
| run: cargo build --target ${{ matrix.target }} | |
| - name: Test project | |
| # Skip tests on FreeBSD, because testing are not supported by cross on FreeBSD. | |
| # https://github.com/cross-rs/cross#supported-targets | |
| if: ${{ !contains(matrix.target, 'freebsd') && !contains(matrix.target, 'aarch64-pc-windows-msvc') }} | |
| run: cargo test --verbose |