From c875b2d50d6cf4e1ba7e153aad06e2fb132b7d53 Mon Sep 17 00:00:00 2001 From: Russell Martin Date: Sun, 28 May 2023 18:39:59 -0400 Subject: [PATCH] Create separate PRs for individual `pre-commit` hooks --- .github/workflows/pre-commit-update.yml | 40 +++++++++++++++++++------ 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pre-commit-update.yml b/.github/workflows/pre-commit-update.yml index 87adaad3..6527ca69 100644 --- a/.github/workflows/pre-commit-update.yml +++ b/.github/workflows/pre-commit-update.yml @@ -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" @@ -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: @@ -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 @@ -75,6 +95,8 @@ 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 @@ -82,12 +104,12 @@ jobs: 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) " author: "Brutus (robot) " - 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 @@ -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."