Debian Codegraph @

.github/workflows/lint.yml

raw
1 name: lint
2
3 "on":
4 workflow_dispatch:
5 push:
6 branches:
7 - main
8 - dev
9 - deps
10 pull_request:
11 branches:
12 - main
13
14 env:
15 PREK_HOME: ~/.cache/prek
16
17 jobs:
18 main:
19 name: lint
20 runs-on: ubuntu-24.04
21 steps:
22 - name: check out code
23 uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
24 with:
25 fetch-depth: 0
26 - name: install Nix
27 uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25
28 - name: cache prek hook environments
29 uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
30 with:
31 path: ${{ env.PREK_HOME }}
32 key: prek|${{ runner.os }}|${{ hashFiles('.pre-commit-config.yaml') }}
33 - name: lint changed files
34 run: |
35 if [[ "$GITHUB_EVENT_NAME" == 'pull_request' ]]; then
36 from_ref='${{ github.event.pull_request.base.sha }}'
37 to_ref='${{ github.event.pull_request.head.sha }}'
38 elif [[ "$GITHUB_EVENT_NAME" == 'push' ]]; then
39 from_ref='${{ github.event.before }}'
40 to_ref='${{ github.sha }}'
41 if [[ "$from_ref" == '0000000000000000000000000000000000000000' ]] || ! git cat-file -e "$from_ref^{commit}" 2>/dev/null; then
42 # New branch, or from_ref no longer reachable (e.g. after a force-push):
43 from_ref="$(git merge-base "origin/${{ github.event.repository.default_branch }}" "$to_ref")"
44 fi
45 else
46 to_ref='${{ github.sha }}'
47 from_ref="$(git merge-base "origin/${{ github.event.repository.default_branch }}" "$to_ref")"
48 if [[ -z "$(git diff --name-only "$from_ref" "$to_ref")" ]]; then
49 # No files changed between from_ref and to_ref -> run on all files:
50 nix develop .#lint --command prek run --all-files --show-diff-on-failure --verbose
51 exit 0
52 fi
53 fi
54 nix develop .#lint --command prek run \
55 --from-ref "$from_ref" \
56 --to-ref "$to_ref" \
57 --show-diff-on-failure \
58 --verbose
59
60 permissions:
61 contents: read