From e5555a5d5b01113f82631556e78d6711d1826490 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 12 Dec 2023 18:46:24 +0100 Subject: [PATCH] pre-commit: Make CI keep keep the config up to date via pull requests --- .../workflows/pre-commit-detect-outdated.yml | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/pre-commit-detect-outdated.yml diff --git a/.github/workflows/pre-commit-detect-outdated.yml b/.github/workflows/pre-commit-detect-outdated.yml new file mode 100644 index 0000000..8b782d1 --- /dev/null +++ b/.github/workflows/pre-commit-detect-outdated.yml @@ -0,0 +1,62 @@ +# Copyright (c) 2023 Sebastian Pipping +# Licensed under the MIT license + +name: Detect outdated pre-commit hooks + +on: + schedule: + - cron: '0 16 * * 5' # Every Friday 4pm + +# NOTE: This will drop all permissions from GITHUB_TOKEN except metadata read, +# and then (re)add the ones listed below: +permissions: + contents: write + pull-requests: write + +jobs: + pre_commit_detect_outdated: + name: Detect outdated pre-commit hooks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.12 + uses: actions/setup-python@v4 + with: + python-version: 3.12 + + - name: Install pre-commit + run: |- + pip install \ + --disable-pip-version-check \ + --no-warn-script-location \ + --user \ + pre-commit + echo "PATH=${HOME}/.local/bin:${PATH}" >> "${GITHUB_ENV}" + + - name: Check for outdated hooks + run: |- + pre-commit autoupdate + git diff -- .pre-commit-config.yaml + + - name: Create pull request from changes (if any) + id: create-pull-request + uses: peter-evans/create-pull-request@v5 + with: + author: 'pre-commit ' + base: master + body: |- + For your consideration. + + :warning: Please **CLOSE AND RE-OPEN** this pull request so that [further workflow runs get triggered](https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs) for this pull request. + branch: precommit-autoupdate + commit-message: "pre-commit: Autoupdate" + delete-branch: true + draft: true + labels: enhancement + title: "pre-commit: Autoupdate" + + - name: Log pull request URL + if: "${{ steps.create-pull-request.outputs.pull-request-url }}" + run: | + echo "Pull request URL is: ${{ steps.create-pull-request.outputs.pull-request-url }}"