-
Notifications
You must be signed in to change notification settings - Fork 36
72 lines (69 loc) · 2.41 KB
/
Copy pathpre-commit.yml
File metadata and controls
72 lines (69 loc) · 2.41 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
# ⚠️ DO NOT EDIT THIS FILE, IT IS GENERATED BY COPIER ⚠️
# Changes here will be lost on a future update.
# See: https://github.com/ingadhoc/addons-repo-template
name: pre-commit
on:
push:
branches:
- "1[8-9].0"
- "[2-9][0-9].0"
pull_request_target:
branches:
- "1[8-9].0*"
- "[2-9][0-9].0*"
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
-
name: Block sensitive file changes from fork PRs
if: >-
github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
changed=$(gh api --paginate \
"repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \
--jq '.[].filename')
if echo "$changed" | grep -qE '^(\.github/workflows/|\.pre-commit-config\.yaml$)'; then
echo "::error::Fork PRs may not modify workflows or the pre-commit config. Blocked for security."
exit 1
fi
-
name: Checkout
uses: actions/checkout@v7
with:
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
allow-unsafe-pr-checkout: true
-
id: setup-python
name: Setup Python
uses: actions/setup-python@v7
with:
python-version: "3.10"
cache: "pip"
-
name: Pre-commit cache
uses: actions/cache@v6
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ steps.setup-python.outputs.python-version }}|${{ hashFiles('.pre-commit-config.yaml') }}
-
id: precommit
name: Pre-commit
run: |
pip install pre-commit
pre-commit run --all-files --show-diff-on-failure --color=always
-
name: Create commit status
if: github.event_name == 'pull_request_target'
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} \
-d '{"state":"${{ steps.precommit.outcome }}","context":"mergebot/pre-commit"}' \
--fail