-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce reusable workflow to update pre-commit dependenices
- Loading branch information
Showing
3 changed files
with
138 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Automated Change Note | ||
|
||
on: | ||
workflow_call: | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
env: | ||
COMMIT_MESSAGE: "Add changenote." | ||
|
||
jobs: | ||
changenote: | ||
name: Automated Change Note | ||
if: github.repository != 'beeware/.github' | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 1 | ||
token: ${{ secrets.BRUTUS_PAT_TOKEN }} | ||
|
||
- name: Configure git | ||
run: | | ||
git config user.email "brutus@beeware.org" | ||
git config user.name "Brutus (robot)" | ||
- name: Change Note Details | ||
id: changenote | ||
run: | | ||
# If the last commit was a changenote commit, then a changenote commit is not needed on this run | ||
if [[ "${{ github.event.head_commit.message }}" == "${COMMIT_MESSAGE}"* ]]; then | ||
echo "needed=false" >> ${GITHUB_OUTPUT} | ||
else | ||
echo "needed=true" >> ${GITHUB_OUTPUT} | ||
# Generate a filename for the changenote based on the PR for this commit | ||
API_URL="${{ github.api_url }}/repos/${{ github.repository }}/commits/${{ github.event.head_commit.id }}/pulls" | ||
PR_NUM=$(curl -s -H "Accept: application/vnd.github+json" "${API_URL}" | jq -r '.[].number') | ||
echo "filename="./changes/${PR_NUM}.misc.rst"" >> ${GITHUB_OUTPUT} | ||
fi | ||
- name: Create Dependabot Change Note | ||
id: dependabot | ||
if: startsWith(github.ref, 'refs/heads/dependabot/') && (steps.changenote.outputs.needed == 'true') | ||
run: | | ||
# Create change note from first line of dependabot commit | ||
NEWS=$(printf "%s" "${{ github.event.head_commit.message }}" | head -n1 | sed -e 's/Bump/Updated/') | ||
printf "%s.\n" "${NEWS}" > "${{ steps.changenote.outputs.filename }}" | ||
git add "${{ steps.changenote.outputs.filename }}" | ||
echo "skip=true" >> ${GITHUB_OUTPUT} | ||
- name: Create pre-commit Autoupdate Change Note | ||
id: pre-commit | ||
if: github.ref == 'refs/heads/pre-commit-autoupdate' && (steps.changenote.outputs.needed == 'true') | ||
run: | | ||
printf 'Updated hooks for ``pre-commit`` to the latest version.\n' > "${{ steps.changenote.outputs.filename }}" | ||
git add "${{ steps.changenote.outputs.filename }}" | ||
- name: Commit and Push changenote | ||
if: steps.changenote.outputs.needed == 'true' | ||
run: | | ||
if [[ "${{ steps.dependabot.outputs.skip }}" == "true" ]]; then | ||
# "dependabot skip" tells Dependabot to continue rebasing this branch despite foreign commits | ||
COMMIT_MESSAGE="${COMMIT_MESSAGE} [dependabot skip]" | ||
fi | ||
# Only attempt to push if files changed; otherwise, the empty push fails the entire job. | ||
if [[ $(git status --porcelain) ]]; then | ||
echo "Pushing commit..." | ||
git commit -m "${COMMIT_MESSAGE}" | ||
git push origin | ||
fi |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Update pre-commit | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
pre-commit-source: | ||
description: "The arguments for `pip install` to install pre-commit; use ./path/to/package[dev] for the repo's pinned version." | ||
default: '.[dev]' | ||
type: string | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
jobs: | ||
pre-commit-update: | ||
name: Update pre-commit | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
steps: | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 1 | ||
token: ${{ secrets.BRUTUS_PAT_TOKEN }} | ||
|
||
- name: Configure git | ||
run: | | ||
git config user.email "brutus@beeware.org" | ||
git config user.name "Brutus (robot)" | ||
- name: Set up Python | ||
uses: actions/setup-python@v4.5.0 | ||
with: | ||
python-version: 3.X | ||
|
||
- name: Install pre-commit | ||
run: python -m pip install ${{ inputs.pre-commit-source }} | ||
|
||
- name: Update pre-commit hooks | ||
run: | | ||
pre-commit autoupdate | ||
pre-commit install-hooks | ||
- name: Run pre-commit | ||
# pre-commit returns non-zero when files are changed and fails the job | ||
continue-on-error: true | ||
run: pre-commit run --all-files | ||
|
||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v4.2.3 | ||
with: | ||
token: ${{ secrets.BRUTUS_PAT_TOKEN }} | ||
title: Auto-update `pre-commit` hooks | ||
branch: pre-commit-autoupdate | ||
commit-message: Auto-updated `pre-commit` hooks. | ||
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. | ||
labels: dependencies |