-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (107 loc) · 3.24 KB
/
check-and-fix.yml
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: check and fix
on:
push:
branches:
- "main"
pull_request:
types: [opened, synchronize, reopened]
paths:
- "**.json"
- "scripts/check.py"
- "scripts/fix_*.py"
- "scripts/create_rules_markdown.py"
- ".github/workflows/check-and-fix.yml"
defaults:
run:
shell: bash -e {0}
permissions:
contents: write
jobs:
check-forbid:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: astral-sh/setup-uv@v5
with:
version: "0.5.9"
enable-cache: true
- name: Check for forbidden file changes
run: |
forbidden_files=(
"rules.md"
"diff.md"
"bilibili-danmu-blocklist-output.json"
)
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
for file in "${forbidden_files[@]}"; do
if echo "$changed_files" | grep -q "$file"; then
echo "Error: Forbidden file $file was modified in this PR."
exit 1
fi
done
check-json:
needs: check-forbid
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: astral-sh/setup-uv@v5
with:
version: "0.5.9"
enable-cache: true
- name: Set up Python
run: uv python install 3.13
- name: Install the project
run: uv sync --all-extras --dev
- name: Check the json file
run: uv run scripts/check.py
fix:
if: ${{ github.event_name == 'pull_request' }}
needs: check-json
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: astral-sh/setup-uv@v5
with:
version: "0.5.9"
enable-cache: true
- name: Set up Python
run: uv python install 3.13
- name: Initialize the dev-environment
run: |
pip install ruff
uv sync --all-extras --dev
- name: Fix - Format the python files
run: ruff format
- name: Fix - Sort the json file
run: uv run scripts/fix_sort.py
- name: Fix - Add timestamp to the rules
run: uv run scripts/fix_id.py
- name: Create rules.md
run: uv run scripts/create_rules_markdown.py
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Check for changes
id: git_diff
run: |
git diff --exit-code || echo "has_changed=true" >> $GITHUB_OUTPUT
- name: Commit changes
if: ${{ steps.git_diff.outputs.has_changed == 'true' }}
run: |
git add .
git commit -m "fix: auto fix"
git pull --rebase origin ${{ github.head_ref }}
git push origin HEAD:${{ github.head_ref }}
- name: Push changes
if: ${{ steps.git_diff.outputs.has_changed == 'true' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref }}