Merge pull request #329823 from ExpidusOS/fix/pkgsllvm/elfutils
[NixPkgs.git] / .github / workflows / nix-parse.yml
blob5842d72c8f6af4a2e8c0a48bfdaa6589d43b162f
1 name: "Check whether nix files are parseable"
3 permissions: read-all
5 on:
6   # avoids approving first time contributors
7   pull_request_target:
8     branches-ignore:
9       - 'release-**'
11 jobs:
12   tests:
13     runs-on: ubuntu-latest
14     if: "github.repository_owner == 'NixOS' && !contains(github.event.pull_request.title, '[skip treewide]')"
15     steps:
16     - name: Get list of changed files from PR
17       env:
18         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19       run: |
20         gh api \
21           repos/NixOS/nixpkgs/pulls/${{github.event.number}}/files --paginate \
22           | jq --raw-output '.[] | select(.status != "removed" and (.filename | endswith(".nix"))) | .filename' \
23           > "$HOME/changed_files"
24         if [[ -s "$HOME/changed_files" ]]; then
25           echo "CHANGED_FILES=$HOME/changed_files" > "$GITHUB_ENV"
26         fi
27     - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
28       with:
29         # pull_request_target checks out the base branch by default
30         ref: refs/pull/${{ github.event.pull_request.number }}/merge
31       if: ${{ env.CHANGED_FILES && env.CHANGED_FILES != '' }}
32     - uses: cachix/install-nix-action@ba0dd844c9180cbf77aa72a116d6fbc515d0e87b # v27
33       with:
34         nix_path: nixpkgs=channel:nixpkgs-unstable
35     - name: Parse all changed or added nix files
36       run: |
37         ret=0
38         while IFS= read -r file; do
39           out="$(nix-instantiate --parse "$file")" || { echo "$out" && ret=1; }
40         done < "$HOME/changed_files"
41         exit "$ret"
42       if: ${{ env.CHANGED_FILES && env.CHANGED_FILES != '' }}