Update pre-commit config #37
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
name: "Update pre-commit config" | |
on: | |
schedule: | |
- cron: "48 3 * * 1" | |
workflow_dispatch: | |
permissions: | |
pull-requests: write | |
contents: write | |
jobs: | |
update-pre-commit-config: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: "3.x" | |
- name: Install dependencies | |
run: python3 -m pip install pre-commit | |
- name: Hash existing config file | |
run: sha256sum .pre-commit-config.yaml > ${{ runner.temp }}/config_file_hashes | |
- name: Update pre-commit config | |
run: | | |
git config --local user.name "$GITHUB_ACTOR" | |
git config --local user.email "[email protected]" | |
git switch -c "pre-commit-$(sha256sum ${{ runner.temp }}/config_file_hashes | head -c 8)" | |
pre-commit autoupdate --freeze | |
- name: Create pull requests | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
if $(sha256sum --status -c ${{ runner.temp }}/config_file_hashes); then | |
echo "Config file unchanged. Skipping pull request..." | |
exit 0 | |
fi | |
git add .pre-commit-config.yaml | |
git commit -m "[CI] Update .pre-commit-config.yaml" | |
git push --set-upstream origin "pre-commit-$(sha256sum ${{ runner.temp }}/config_file_hashes | head -c 8)" | |
# Create PR on GitHub using GitHub CLI. | |
gh pr create --base main --title "[CI] Update .pre-commit-config.yaml" \ | |
--body "Created automatically by GitHub Actions." |