-
Notifications
You must be signed in to change notification settings - Fork 1.1k
80 lines (71 loc) · 2.81 KB
/
pre-commit.yml
File metadata and controls
80 lines (71 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Halide Presubmit Checks
on:
# We don't want 'edited' (that's basically just the description, title, etc.)
# We don't want 'review_requested' (that's redundant to the ones below for our purposes)
pull_request:
types: [ opened, synchronize, reopened ]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
pre-commit:
name: Run pre-commit checks
runs-on: ubuntu-slim
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
- uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v5
- name: Run pre-commit
id: pre-commit
uses: pre-commit/[email protected]
- name: Create auto-fix diff
id: diff
if: ${{ !cancelled() && steps.pre-commit.outcome == 'failure' }}
run: |
if git diff --quiet; then
echo "has-fixes=false" >> "$GITHUB_OUTPUT"
else
git diff > /tmp/pre-commit-fixes.patch
echo "has-fixes=true" >> "$GITHUB_OUTPUT"
fi
- name: Save PR metadata
if: ${{ !cancelled() && steps.diff.outputs.has-fixes == 'true' }}
run: |
jq -n \
--argjson number "$PR_NUMBER" \
--arg head_repo "$PR_HEAD_REPO" \
--arg head_ref "$PR_HEAD_REF" \
--argjson maintainer_can_modify "$PR_MAINTAINER_CAN_MODIFY" \
'$ARGS.named' | tee /tmp/pr-metadata.json
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_MAINTAINER_CAN_MODIFY: ${{ github.event.pull_request.maintainer_can_modify }}
- name: Upload auto-fix artifacts
if: ${{ !cancelled() && steps.diff.outputs.has-fixes == 'true' }}
uses: actions/upload-artifact@v4
with:
name: pre-commit-fixes
path: |
/tmp/pre-commit-fixes.patch
/tmp/pr-metadata.json
retention-days: 1
- name: Annotate codespell errors
if: ${{ !cancelled() && steps.pre-commit.outcome == 'failure' }}
run: |
pre-commit run --all-files codespell 2>&1 |
awk -F: '/^[^:]*:[0-9]+: / {
file=$1; line=$2; sub(/^[^:]*:[0-9]+: /, ""); msg=$0
key=file":"line
if (key in msgs) msgs[key]=msgs[key]"%0A"msg
else { msgs[key]=msg; files[key]=file; lines[key]=line; order[++n]=key }
} END {
for (i=1; i<=n; i++)
printf "::error file=%s,line=%s::%s\n", files[order[i]], lines[order[i]], msgs[order[i]]
}'