|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - synchronize |
| 8 | + - reopened |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + |
| 13 | +jobs: |
| 14 | + generate_matrix: |
| 15 | + name: Generate matrix |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + checks: ${{ steps.gen_checks.outputs.checks }} |
| 19 | + steps: |
| 20 | + - name: Clone repository |
| 21 | + uses: actions/checkout@v5 |
| 22 | + - name: Install Nix |
| 23 | + uses: cachix/install-nix-action@v31 |
| 24 | + with: |
| 25 | + extra_nix_config: | |
| 26 | + auto-optimise-store = true |
| 27 | + experimental-features = nix-command flakes |
| 28 | + substituters = https://cache.nixos.org/ https://nix-community.cachix.org/ |
| 29 | + trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= |
| 30 | + allow-import-from-derivation = true |
| 31 | + install_url: https://releases.nixos.org/nix/nix-2.28.0/install |
| 32 | + - name: Generate flake.json |
| 33 | + run: | |
| 34 | + nix flake show --json --allow-import-from-derivation > flake.json |
| 35 | + - id: gen_checks |
| 36 | + name: Generate checks |
| 37 | + run: | |
| 38 | + systems=("x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin") |
| 39 | + declare -A runners=( ["x86_64-linux"]="ubuntu-latest" ["aarch64-linux"]="ubuntu-latest" ["x86_64-darwin"]="macos-13" ["aarch64-darwin"]="macos-14" ) |
| 40 | + matrix="[]" |
| 41 | + for sys in "${systems[@]}"; do |
| 42 | + checks=$(jq -c ".checks.\"$sys\" | keys[]" < flake.json 2>/dev/null || echo "[]") |
| 43 | + for check in $(echo "$checks" | jq -r '.[]'); do |
| 44 | + runner="${runners[$sys]}" |
| 45 | + matrix=$(echo "$matrix" | jq ". + [{\"system\": \"$sys\", \"check\": \"$check\", \"runner\": \"$runner\"}]") |
| 46 | + done |
| 47 | + done |
| 48 | + printf "checks=%s" "$matrix" >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + build_checks: |
| 51 | + name: Build checks |
| 52 | + runs-on: ${{ matrix.check.runner }} |
| 53 | + needs: |
| 54 | + - generate_matrix |
| 55 | + strategy: |
| 56 | + fail-fast: false |
| 57 | + max-parallel: 5 |
| 58 | + matrix: |
| 59 | + check: ${{fromJson(needs.generate_matrix.outputs.checks)}} |
| 60 | + steps: |
| 61 | + - name: Clone repository |
| 62 | + uses: actions/checkout@v5 |
| 63 | + - name: Install nix |
| 64 | + uses: cachix/install-nix-action@v31 |
| 65 | + with: |
| 66 | + extra_nix_config: | |
| 67 | + auto-optimise-store = true |
| 68 | + experimental-features = nix-command flakes |
| 69 | + substituters = https://cache.nixos.org/ https://nix-community.cachix.org |
| 70 | + trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= |
| 71 | + allow-import-from-derivation = true |
| 72 | + install_url: https://releases.nixos.org/nix/nix-2.28.0/install |
| 73 | + - name: Setup cachix |
| 74 | + uses: cachix/cachix-action@v15 |
| 75 | + with: |
| 76 | + name: your-cachix-name # Replace with your cachix name |
| 77 | + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' |
| 78 | + - name: Build everything |
| 79 | + run: nix build .#checks.${{ matrix.check.system }}.${{ matrix.check.check }} --no-link |
| 80 | + |
| 81 | + check_flake: |
| 82 | + name: Check flake |
| 83 | + runs-on: ubuntu-latest |
| 84 | + needs: |
| 85 | + - generate_matrix |
| 86 | + continue-on-error: true |
| 87 | + steps: |
| 88 | + - name: Clone repository |
| 89 | + uses: actions/checkout@v5 |
| 90 | + - name: Install nix |
| 91 | + uses: cachix/install-nix-action@v31 |
| 92 | + with: |
| 93 | + extra_nix_config: | |
| 94 | + auto-optimise-store = true |
| 95 | + experimental-features = nix-command flakes |
| 96 | + substituters = https://cache.nixos.org/ https://nix-community.cachix.org |
| 97 | + trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= |
| 98 | + allow-import-from-derivation = true |
| 99 | + install_url: https://releases.nixos.org/nix/nix-2.28.0/install |
| 100 | + - name: Run checks |
| 101 | + run: | |
| 102 | + nix flake check --keep-going --allow-import-from-derivation |
0 commit comments