Skip to content

Commit 8583a3b

Browse files
[CI] Add lint workflow running pre-commit (#16275)
It adds a new _Lint_ workflow which runs `pre-commit` in CI. It only tests files that have changes compared to the base ref of a PR, or `master`. Workflow dispatch allows running `pre-commit` against all files in the repo. We already have a couple of individual CI jobs that run some of these linter: `lint-actionlint`, `lint-shellcheck`, `lint_spellcheck`. The new setup replaces them. But I'm keeping them around for a while to ensure the new workflow functions properly.
1 parent 5d3faa0 commit 8583a3b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

.github/workflows/lint.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Lint
2+
on:
3+
push:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
permissions: {}
8+
9+
jobs:
10+
pre-commit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Download source
14+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
15+
- uses: cachix/install-nix-action@fd24c48048070c1be9acd18c9d369a83f0fe94d7 # v31
16+
- uses: cachix/cachix-action@0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad # v16
17+
with:
18+
name: devenv
19+
- name: Install devenv.sh
20+
run: nix profile install nixpkgs#devenv
21+
- name: "Download target branch: ${{ github.base_ref || 'master' }}"
22+
run: git fetch origin "${TARGET_BRANCH}"
23+
- name: Run pre-commit hooks for changes against target branch (${{ github.base_ref || 'master' }})
24+
run: pre-commit run --from-ref "origin/${TARGET_BRANCH}" --to-ref HEAD
25+
shell: devenv shell bash -- -e {0}
26+
if: "${{ github.event_name != 'workflow_dispatch' }}"
27+
- name: Run pre-commit on all files
28+
run: pre-commit run --all-files
29+
shell: devenv shell bash -- -e {0}
30+
if: "${{ github.event_name == 'workflow_dispatch' }}"
31+
env:
32+
TARGET_BRANCH: "${{ github.base_ref || 'master' }}"

0 commit comments

Comments
 (0)