Skip to content

pre-commit autoupdate #92

pre-commit autoupdate

pre-commit autoupdate #92

name: "pre-commit autoupdate"
on:
schedule:
- cron: 20 4 * * *
workflow_dispatch:
jobs:
pre-commit-autoupdate:
name: pre-commit autoupdate
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Setup pre-commit
run: |
python -m pip install --upgrade pre-commit
pre-commit --version
- name: Run pre-commit autoupdate
id: autoupdate
run: |
echo "log<<EOF" >>$GITHUB_OUTPUT
pre-commit autoupdate | tee -a >(cat >> $GITHUB_OUTPUT)
echo 'EOF' >> $GITHUB_OUTPUT
- name: Check diff
id: diff
shell: bash
run: |
echo 'diff<<EOF' >> $GITHUB_OUTPUT
git diff | tee -a >(cat >> $GITHUB_OUTPUT)
echo 'EOF' >> $GITHUB_OUTPUT
- name: Create PR
if: ${{ steps.diff.outputs.diff != '' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
set -xeu
git switch -c pre-commit-autoupdate
git add .
git config --global user.name "pre-commit autoupdate"
git config --global user.email "[email protected]"
git commit -m "pre-commit autoupdate"
git push --force --set-upstream origin pre-commit-autoupdate
title="pre-commit autoupdate"
body_file=/tmp/body
echo '```' >> $body_file
echo '$ pre-commit autoupdate' >> $body_file
echo '${{steps.autoupdate.outputs.log}}' >> $body_file
echo '```' >> $body_file
body="$(cat $body_file)"
pr_number=$(gh pr list -S "pre-commit autoupdate" --json number --jq '.[0].number')
if [[ -z $pr_number ]]; then
echo "Creating PR"
gh pr create \
--label dependencies \
--title "$title" \
--body "$body"
exit 0
fi
echo "Updating PR \#${pr_number}"
gh pr edit \
$pr_number \
--body "$body" \
--title "$title"