Skip to content

Commit

Permalink
Add changenote directly in pre-commit workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Feb 1, 2023
1 parent b7c8ed7 commit 3a8eb3a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 89 deletions.
82 changes: 0 additions & 82 deletions .github/workflows/automation-changenote.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/dependabot-changenote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Dependabot Change Note

on:
workflow_call:

permissions:
pull-requests: write

jobs:
changenote:
name: Dependabot Change Note
if: github.actor == 'dependabot[bot]' && 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 --local user.email "$(git log --pretty='%ae' -1)"
git config --local user.name "Dependabot[bot]"
- name: Commit Change Note
run: |
# Fetch PR number for commit from Github API
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')
# 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}" > "./changes/${PR_NUM}.misc.rst"
# Commit the change note
git add "./changes/${PR_NUM}.misc.rst"
# "dependabot skip" tells Dependabot to continue rebasing this branch despite foreign commits
git commit -m "Add changenote. [dependabot skip]"
- name: Push
run: git push origin
46 changes: 39 additions & 7 deletions .github/workflows/pre-commit-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ on:
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
create-changenote:
description: "If 'true', creates a misc changenote in the './changes' directory."
default: true
type: boolean

permissions:
pull-requests: write

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

jobs:
pre-commit-update:
name: Update pre-commit
Expand Down Expand Up @@ -51,14 +59,38 @@ jobs:
continue-on-error: true
run: pre-commit run --all-files

- name: PR Needed?
id: pr
run: |
if [[ $(git status --porcelain) ]]; then
echo "needed=true" >> ${GITHUB_OUTPUT}
else
echo "needed=false" >> ${GITHUB_OUTPUT}
fi
- name: Create Pull Request
id: created-pr
if: steps.pr.outputs.needed == 'true'
uses: peter-evans/create-pull-request@v4.2.3
with:
token: ${{ secrets.BRUTUS_PAT_TOKEN }}
title: Auto-update `pre-commit` hooks
branch: autoupdates/pre-commit
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
title: "Auto-update `pre-commit` hooks"
branch: ${{ env.BRANCH_NAME }}
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"

- name: Add changenote
if: (inputs.create-changenote == true) && (steps.created-pr.outputs.pull-request-number != '')
run: |
git fetch origin
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}"
git add "${FILENAME}"
git commit -m "Add changenote."
git push --set-upstream origin ${{ env.BRANCH_NAME }}

0 comments on commit 3a8eb3a

Please # to comment.