refactor: manage CI using nix #33
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 ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| nix-matrix: | |
| name: Generate Nix CI Matrix | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Nix | |
| uses: cachix/install-nix-action@v27 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| extra_nix_config: | | |
| experimental-features = nix-command flakes | |
| accept-flake-config = true | |
| - name: Setup Magic Nix Cache | |
| uses: DeterminateSystems/magic-nix-cache-action@v8 | |
| - name: Generate CI matrix from flake | |
| id: set-matrix | |
| run: | | |
| set -euo pipefail | |
| matrix="$(nix eval --json '.#githubActions.matrix')" | |
| echo "matrix=$matrix" >> "$GITHUB_OUTPUT" | |
| nix-build: | |
| name: ${{ matrix.attr }} | |
| needs: nix-matrix | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Nix | |
| uses: cachix/install-nix-action@v27 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| extra_nix_config: | | |
| experimental-features = nix-command flakes | |
| accept-flake-config = true | |
| extra-substituters = https://ros.cachix.org | |
| extra-trusted-public-keys = ros.cachix.org-1:dSyZxI8geDCJrwgvCOHDoAfOm5sV1wCPjBkKL+38Rvo= | |
| - name: Setup Cachix | |
| uses: cachix/cachix-action@v15 | |
| with: | |
| name: ros | |
| authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' | |
| # Push build outputs to cachix for reuse | |
| skipPush: false | |
| - name: Setup Magic Nix Cache | |
| uses: DeterminateSystems/magic-nix-cache-action@v8 | |
| - name: Run check | |
| run: nix build -L '.#${{ matrix.attr }}' |