Skip to content

Commit 6d455e8

Browse files
committed
ci: Replace the pre-commit.ci app with github workflows
Since we're using the uv hook, pre-commit requires the internet to work properly which the pre-commit.ci app ran jobs don't have access to. These two workflows are meant to replace the app entirely by doing both checking on PRs/main and auto updates. It means that we do lose the autofix feature, but it's that or throwing away the uv-lock hook. Original work done in taskcluster/taskgraph#677 and taskcluster/taskgraph#678
1 parent 73a0b2a commit 6d455e8

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Autoupdate
2+
on:
3+
schedule:
4+
- cron: '0 0 1 * *'
5+
jobs:
6+
pre-commit:
7+
name: Pre-commit
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Setup git
15+
run: |
16+
git config --global user.name "Pre-commit automation"
17+
git config --global user.email "[email protected]"
18+
- uses: actions/setup-python@v5
19+
- run: python -m pip install pre-commit
20+
shell: bash
21+
- name: Get commit message
22+
run: |
23+
echo "COMMIT_MSG=$(cat .pre-commit-config.yaml | yq -r '.ci.autoupdate_commit_msg // "Update pre-commit config"')" >> $GITHUB_ENV
24+
- name: Update files
25+
run: |
26+
git checkout -B pre-commit-update
27+
pre-commit autoupdate -j4
28+
git add .pre-commit-config.yaml
29+
git commit -m "${COMMIT_MSG}"
30+
git push -f origin pre-commit-update
31+
- name: Create PR if necessary
32+
run: |
33+
curl -sL \
34+
-X POST \
35+
-H "Accept: application/vnd.github+json" \
36+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
37+
-H "X-GitHub-Api-Version: 2022-11-28" \
38+
https://api.github.com/repos${{ github.reository_owner }}/${{ github.repository }}/pulls \
39+
-d "{\"title\":\"${COMMIT_MSG}\",\"body\":\"\",\"head\":\"pre-commit-update\",\"base\":\"${{ github.event.repository.default_branch }}\"}"

.github/workflows/pre-commit.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: "Pre-commit"
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
jobs:
8+
pre-commit:
9+
name: Run pre-commit
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v5
14+
- run: python -m pip install pre-commit
15+
shell: bash
16+
- uses: actions/cache@v4
17+
with:
18+
path: ~/.cache/pre-commit
19+
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
20+
- run: pre-commit run --show-diff-on-failure --color=always -a
21+
shell: bash

.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
---
44
ci:
5-
autofix_commit_msg: "style: pre-commit.ci auto fixes [...]"
65
autoupdate_commit_msg: "chore: pre-commit autoupdate"
7-
autoupdate_schedule: monthly
86
repos:
97
- repo: https://github.com/pre-commit/pre-commit-hooks
108
rev: v5.0.0

0 commit comments

Comments
 (0)