• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
2# Licensed under the Apache License Version 2.0
3
4name: Keep pre-commit hooks up to date
5
6on:
7  schedule:
8    - cron: '0 16 * * 5'  # Every Friday 4pm
9  workflow_dispatch:
10
11# NOTE: This will drop all permissions from GITHUB_TOKEN except metadata read,
12#       and then (re)add the ones listed below:
13permissions:
14  contents: write
15  pull-requests: write
16
17jobs:
18  pre_commit_autoupdate:
19    name: Detect outdated pre-commit hooks
20    runs-on: ubuntu-22.04
21    steps:
22      - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871  # v4.2.1
23
24      - name: Set up Python 3.11
25        uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d  # v5.1.0
26        with:
27          python-version: 3.11
28
29      - name: Install pre-commit
30        run: |-
31          pip install \
32            --disable-pip-version-check \
33            --no-warn-script-location \
34            --user \
35            pre-commit
36          echo "PATH=${HOME}/.local/bin:${PATH}" >> "${GITHUB_ENV}"
37
38      - name: Check for outdated hooks
39        run: |-
40          pre-commit autoupdate
41          git diff -- .pre-commit-config.yaml
42
43      - name: Create pull request from changes (if any)
44        id: create-pull-request
45        uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f  # v7.0.5
46        with:
47          author: 'pre-commit <pre-commit@tools.invalid>'
48          base: main
49          body: |-
50            For your consideration.
51
52            :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.
53          branch: precommit-autoupdate
54          commit-message: "pre-commit: Autoupdate"
55          delete-branch: true
56          draft: true
57          labels: enhancement
58          title: "pre-commit: Autoupdate"
59
60      - name: Log pull request URL
61        if: "${{ steps.create-pull-request.outputs.pull-request-url }}"
62        run: |
63          echo "Pull request URL is: ${{ steps.create-pull-request.outputs.pull-request-url }}"
64