Skip to content

Commit

Permalink
Merge pull request #39 from rmartin16/individual-pre-commit-updates
Browse files Browse the repository at this point in the history
Create separate PRs for individual `pre-commit` hooks
  • Loading branch information
freakboy3742 authored May 29, 2023
2 parents a03e2d4 + c875b2d commit 4484056
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions .github/workflows/pre-commit-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ permissions:
pull-requests: write

env:
BRANCH_NAME: "autoupdates/pre-commit"
BRANCH_PREFIX: "autoupdates/pre-commit"
CHANGENOTE_DIR: "./changes"
FORCE_COLOR: "1"

Expand All @@ -32,12 +32,32 @@ defaults:
shell: bash

jobs:
pre-commit-hooks:
name: Pre-commit hooks
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
hook-repos: ${{ steps.hooks.outputs.repos }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3.5.2

- name: Get Pre-commit Hooks
id: hooks
run: |
REPOS=$(yq .repos[].repo < .pre-commit-config.yaml | jq -R -s -c 'split("\n")[:-1]')
echo "repos=${REPOS}" >> ${GITHUB_OUTPUT}
pre-commit-update:
name: Update Pre-commit config
name: Update Pre-commit hook
needs: pre-commit-hooks
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
hook-repo: ${{ fromJson(needs.pre-commit-hooks.outputs.hook-repos) }}
steps:

- name: Checkout
uses: actions/checkout@v3
with:
Expand All @@ -59,7 +79,7 @@ jobs:

- name: Update pre-commit hooks
run: |
pre-commit autoupdate
pre-commit autoupdate --repo ${{ matrix.hook-repo }}
pre-commit install-hooks
- name: Run pre-commit
Expand All @@ -75,19 +95,21 @@ jobs:
else
echo "needed=false" >> ${GITHUB_OUTPUT}
fi
REPO="${{ matrix.hook-repo }}"
echo "hook-name=${REPO##*/}" >> ${GITHUB_OUTPUT}
- name: Create Pull Request
id: created-pr
if: steps.pr.outputs.needed == 'true'
uses: peter-evans/create-pull-request@v5.0.1
with:
token: ${{ secrets.BRUTUS_PAT_TOKEN }}
title: "Auto-update `pre-commit` hooks"
branch: ${{ env.BRANCH_NAME }}
commit-message: "Auto-updated `pre-commit` hooks."
title: "Bump pre-commit hook for ${{ steps.pr.outputs.hook-name }}"
branch: "${{ env.BRANCH_PREFIX }}/${{ steps.pr.outputs.hook-name }}"
commit-message: "Bumped pre-commit hook for ${{ steps.pr.outputs.hook-name }}"
committer: "Brutus (robot) <brutus@beeware.org>"
author: "Brutus (robot) <brutus@beeware.org>"
body: "Updated `pre-commit` hooks to their latest versions and ran updated hooks against the repo."
body: "Automatically bumped `pre-commit` hook for `${{ steps.pr.outputs.hook-name }}` and ran the update against the repo."
labels: "dependencies"

- name: Add changenote
Expand All @@ -97,7 +119,7 @@ jobs:
git checkout ${{ env.BRANCH_NAME }}
FILENAME="${{ env.CHANGENOTE_DIR }}/${{ steps.created-pr.outputs.pull-request-number }}.misc.rst"
printf 'Updated ``pre-commit`` hooks to the latest version.\n' > "${FILENAME}"
printf 'The ``pre-commit`` hook for ``${{ steps.pr.outputs.hook-name }}`` was updated to its latest version.\n' > "${FILENAME}"
git add "${FILENAME}"
git commit -m "Add changenote."
Expand Down

0 comments on commit 4484056

Please sign in to comment.