|
| 1 | +# This action uses the following secrets: |
| 2 | +# CACHIX_AUTH_TOKEN: Write access to nodejs.cachix.org – without it, the cache is read-only. |
| 3 | +name: Nix files edited |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + - canary |
| 10 | + - v[0-9]+.x-staging |
| 11 | + - v[0-9]+.x |
| 12 | + paths: |
| 13 | + - '**.nix' |
| 14 | + - .github/workflows/nix-changes.yml |
| 15 | + pull_request: |
| 16 | + paths: |
| 17 | + - '**.nix' |
| 18 | + - .github/workflows/nix-changes.yml |
| 19 | + types: [opened, synchronize, reopened, ready_for_review] |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: read |
| 27 | + |
| 28 | +jobs: |
| 29 | + diff: |
| 30 | + if: github.event.pull_request.draft == false |
| 31 | + strategy: |
| 32 | + fail-fast: false |
| 33 | + matrix: |
| 34 | + include: |
| 35 | + - runner: ubuntu-24.04 |
| 36 | + system: x86_64-linux |
| 37 | + - runner: ubuntu-24.04-arm |
| 38 | + system: aarch64-linux |
| 39 | + - runner: macos-15-intel |
| 40 | + system: x86_64-darwin |
| 41 | + - runner: macos-latest |
| 42 | + system: aarch64-darwin |
| 43 | + name: '${{ matrix.system }}: dependencies diff' |
| 44 | + runs-on: ${{ matrix.runner }} |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 47 | + with: |
| 48 | + fetch-depth: 2 |
| 49 | + persist-credentials: false |
| 50 | + sparse-checkout: '*.nix' |
| 51 | + sparse-checkout-cone-mode: false |
| 52 | + |
| 53 | + - uses: cachix/install-nix-action@8aa03977d8d733052d78f4e008a241fd1dbf36b3 # v31.10.6 |
| 54 | + with: |
| 55 | + extra_nix_config: sandbox = true |
| 56 | + |
| 57 | + - uses: cachix/cachix-action@5f2d7c5294214f71b873db4b969586b980625e71 # v17 |
| 58 | + with: |
| 59 | + authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} |
| 60 | + name: nodejs |
| 61 | + |
| 62 | + - name: Compute requisites after change |
| 63 | + shell: bash # See https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference, we want the pipefail option. |
| 64 | + run: | |
| 65 | + nix-store --query --references "$( |
| 66 | + nix-instantiate -I "nixpkgs=./tools/nix/pkgs.nix" shell.nix \ |
| 67 | + --arg devTools " |
| 68 | + (import ./tools/nix/devTools.nix {}) |
| 69 | + ++ builtins.attrValues ( |
| 70 | + { inherit (import <nixpkgs> {}) nixfmt-tree sccache; } |
| 71 | + // import ./tools/nix/openssl-matrix.nix {} |
| 72 | + )")" \ |
| 73 | + | xargs nix-store --realise \ |
| 74 | + | xargs nix-store --query --requisites \ |
| 75 | + | sort -k1.45 \ |
| 76 | + > requisites-${{ matrix.system }}-after.list |
| 77 | +
|
| 78 | + - name: Compute requisites before change |
| 79 | + shell: bash # See https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference, we want the pipefail option. |
| 80 | + run: | |
| 81 | + git reset HEAD^ --hard |
| 82 | + nix-store --query --references "$( |
| 83 | + nix-instantiate -I "nixpkgs=./tools/nix/pkgs.nix" shell.nix \ |
| 84 | + --arg devTools " |
| 85 | + (import ./tools/nix/devTools.nix {}) |
| 86 | + ++ builtins.attrValues ( |
| 87 | + { inherit (import <nixpkgs> {}) nixfmt-tree sccache; } |
| 88 | + // import ./tools/nix/openssl-matrix.nix {} |
| 89 | + )")" \ |
| 90 | + | xargs nix-store --realise \ |
| 91 | + | xargs nix-store --query --requisites \ |
| 92 | + | sort -k1.45 \ |
| 93 | + > requisites-${{ matrix.system }}-before.list |
| 94 | +
|
| 95 | + - name: Output diff |
| 96 | + run: | |
| 97 | + { |
| 98 | + if diff_output="$(git diff -U0 --no-color --no-index requisites-${{ matrix.system }}-before.list requisites-${{ matrix.system }}-after.list)"; then |
| 99 | + echo 'No changes detected.' |
| 100 | + else |
| 101 | + echo '```diff' |
| 102 | + echo "$diff_output" | tail -n +5 |
| 103 | + echo '```' |
| 104 | + fi |
| 105 | + } >> "$GITHUB_STEP_SUMMARY" |
| 106 | +
|
| 107 | + - name: Store PR number |
| 108 | + if: ${{ github.event.pull_request && matrix.system == 'x86_64-linux' }} |
| 109 | + run: echo "${{ github.event.pull_request.number }}" > pr_number.txt |
| 110 | + |
| 111 | + - name: Upload requisites lists |
| 112 | + if: ${{ github.event.pull_request }} |
| 113 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 114 | + with: |
| 115 | + name: requisites-${{ matrix.system }} |
| 116 | + path: | |
| 117 | + pr_number.* |
| 118 | + requisites-${{ matrix.system }}-before.list |
| 119 | + requisites-${{ matrix.system }}-after.list |
| 120 | +
|
| 121 | + lint-nix: |
| 122 | + if: github.event.pull_request.draft == false |
| 123 | + runs-on: ubuntu-slim |
| 124 | + steps: |
| 125 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 126 | + with: |
| 127 | + persist-credentials: false |
| 128 | + sparse-checkout: '*.nix' |
| 129 | + sparse-checkout-cone-mode: false |
| 130 | + - uses: cachix/install-nix-action@8aa03977d8d733052d78f4e008a241fd1dbf36b3 # v31.10.6 |
| 131 | + - name: Lint Nix files |
| 132 | + run: | |
| 133 | + nix-shell -I nixpkgs=./tools/nix/pkgs.nix -p 'nixfmt-tree' --run ' |
| 134 | + treefmt --quiet --ci |
| 135 | + ' && EXIT_CODE="$?" || EXIT_CODE="$?" |
| 136 | + if [ "$EXIT_CODE" != "0" ] |
| 137 | + then |
| 138 | + git --no-pager diff || true |
| 139 | + exit "$EXIT_CODE" |
| 140 | + fi |
0 commit comments