-
Notifications
You must be signed in to change notification settings - Fork 50
49 lines (48 loc) · 2.05 KB
/
autofix.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
on:
pull_request_target:
jobs:
autofix:
runs-on: ubuntu-latest
steps:
# git-auto-commit-action is a bit tricky to use.
# See the "advanced" section in its README for an insecure configuration that works.
#
# To make it secure against malicious pull requests, you cannot trust files in the PR,
# because pull_request_target jobs have more permissions than pull_request jobs.
# Here we place the PR's stuff to a subdirectory named "pr".
- uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
path: ./pr
- uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: pip
- run: pip install wheel
- run: pip install -r requirements-dev.txt
- name: Gather a list of Python files in the pull request branch
run: |
(cd pr && git ls-files) | grep -E '\.(py|pyw)$' | sed s:^:pr/: | tee filelist.txt
- run: python3 -m pycln --all --disable-all-dunder-policy $(cat filelist.txt)
- run: python3 -m pyupgrade $(cat filelist.txt) --keep-runtime-typing --py38-plus --exit-zero-even-if-changed
- run: python3 -m black $(cat filelist.txt)
- run: python3 -m isort $(cat filelist.txt)
# I like requirements-dev.txt and some other people like pyproject.toml, so we have both.
# Auto-generating is the easiest way to ensure the two stay in sync.
- name: Generate requirements-dev.txt from pyproject.toml
run: |
echo "# Auto-generated in GitHub Actions. See autofix.yml." > pr/requirements-dev.txt
pip install tomli
python3 -c 'if True:
import tomli
with open("pr/pyproject.toml", "rb") as f:
content = tomli.load(f)
for dep in content["project"]["optional-dependencies"]["dev"]:
print(dep)
' >> pr/requirements-dev.txt
- uses: stefanzweifel/git-auto-commit-action@v4
with:
repository: ./pr
commit_message: "Run pycln, pyupgrade, black and isort"