Skip to content

Update pre-commit hooks #63

Update pre-commit hooks

Update pre-commit hooks #63

name: Update pre-commit hooks
on:
schedule:
# Every monday at 7 AM
- cron: 0 7 * * 1
push:
branches:
- main
page_build:
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
# Give the default GITHUB_TOKEN write permission to create or update
# pull requests
pull-requests: write
jobs:
update:
runs-on: ubuntu-latest
if: github.repository_owner == 'mindstream-it'
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
.pre-commit-config.yaml
- uses: actions/setup-python@v5
with:
# Read python version from a file .python-version
python-version-file: '.python-version'
- uses: actions/cache@v4
with:
path: |
~/.cache/pre-commit
~/.cache/pip
key: "pre-commit-3|\
${{ env.pythonLocation }}|\
${{ hashFiles('.pre-commit-config.yaml') }}"
- name: Install pre-commit
run: python -m pip install pre-commit
- name: Freeze pre-commit
run: python -m pip freeze --local
- name: Run `pre-commit autoupdate`
id: pre-commit-autoupdate
run: |
echo 'LOG<<_PRECOMMIT_EOF' >>"$GITHUB_OUTPUT"
{
set -euo pipefail
pre-commit autoupdate --freeze --color=never 2>&1
} | tee -a "$GITHUB_OUTPUT"
echo '_PRECOMMIT_EOF' >>"$GITHUB_OUTPUT"
- name: Create branch
id: pre-commit-create-branch
if: contains(steps.pre-commit-autoupdate.outputs.LOG, ' updating ')
# https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#create-a-reference
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${GITHUB_REPOSITORY}/git/refs" \
-f ref="refs/heads/${NEW_BRANCH_NAME}" \
-f sha="${GITHUB_SHA}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_BRANCH_NAME: "bot-pre-commit-autoupdate-\
${{ hashFiles('.pre-commit-config.yaml') }}"
- uses: planetscale/[email protected]
# Commit changed files back to the repository
# if no changed files then continue without error
if: contains(steps.pre-commit-autoupdate.outputs.LOG, ' updating ')
with:
commit_message: "chore(deps): Update pre-commit hooks"
repo: ${{ github.repository }}
branch: "bot-pre-commit-autoupdate-\
${{ hashFiles('.pre-commit-config.yaml') }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: peter-evans/[email protected]
# Open Pull Requests if there are any commits on the target branch
if: contains(steps.pre-commit-autoupdate.outputs.LOG, ' updating ')
with:
branch: "bot-pre-commit-autoupdate-\
${{ hashFiles('.pre-commit-config.yaml') }}"
title: "chore(deps): Update pre-commit hooks"
body: |
Updates pre-commit hooks
<details>
<summary>
<code>pre-commit autoupdate --freeze --color=never</code>
</summary>
```
${{ steps.pre-commit-autoupdate.outputs.LOG }}
```
</details>
labels: dependencies
delete-branch: True