Skip to content

Update pre-commit config #107

Update pre-commit config

Update pre-commit config #107

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:
- name: Checkout code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
- name: Setup python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
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-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git switch -c "pre-commit-update"
pre-commit autoupdate --freeze
- name: Generate GitHub App Token
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69
id: app-token
with:
app-id: ${{ secrets.AUTH_APP_ID }}
private-key: ${{ secrets.AUTH_APP_PRIVATE_KEY }}
- name: Create pull requests
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"
remote_branch_name="pre-commit-$(sha256sum .pre-commit-config.yaml | head -c 8)"
git push --set-upstream origin "pre-commit-update:${remote_branch_name}"
# Create PR on GitHub using GitHub REST API.
request_body='{"title":"[CI] Update pre-commit hooks","body":"Created automatically by GitHub Actions.","base":"main","head":"'"${remote_branch_name}"'"}'
curl -LsS --fail-with-body \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ steps.app-token.outputs.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/pulls \
-d "$request_body"