Skip to content

Fix simple terminal run command in external window #429

Fix simple terminal run command in external window

Fix simple terminal run command in external window #429

Workflow file for this run

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@v4
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
path: ./pr
- uses: actions/setup-python@v5
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
- name: Run pyupgrade
run: mapfile -t files < filelist.txt && python3 -m pyupgrade --keep-runtime-typing --py39-plus --exit-zero-even-if-changed -- "${files[@]}"
- name: Run pycln
run: mapfile -t files < filelist.txt && python3 -m pycln --all --disable-all-dunder-policy -- "${files[@]}"
- name: Run black
run: mapfile -t files < filelist.txt && python3 -m black -- "${files[@]}"
- name: Run isort
run: mapfile -t files < filelist.txt && python3 -m isort -- "${files[@]}"
# 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"]["dependencies"]:
print(dep)
for dep in content["project"]["optional-dependencies"]["dev"]:
print(dep)
' >> pr/requirements-dev.txt
- uses: stefanzweifel/git-auto-commit-action@v5
with:
repository: ./pr
commit_message: "Run pycln, pyupgrade, black and isort"