Add link checker script for markdown files #319
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]["dependencies"]: | |
print(dep) | |
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" |