forked from Slicer/Slicer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COMP: Add Github workflow for keeping pre-commit configuration up-to-…
…date This commit introduces a GitHub workflow specifically designed to keep the pre-commit configuration current. It leverages the credentials of the "Slicer GitHub App" associated with the Slicer organization. The decision to opt for a dedicated workflow over granting access to the pre-commit.ci service was made to ensure a tested and adaptable solution. By adopting this approach, we pave the way for potential reuse of the workflow in custom applications hosted privately.
- Loading branch information
Showing
1 changed file
with
87 additions
and
0 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,87 @@ | ||
name: Pre-commit auto-update | ||
|
||
on: | ||
# every day at midnight | ||
schedule: | ||
- cron: "0 0 * * *" | ||
# on demand | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
auto-update: | ||
permissions: | ||
# Needed for peter-evans/create-pull-request to create branch | ||
contents: write | ||
# Needed for peter-evans/create-pull-request to create a PR | ||
pull-requests: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
|
||
- uses: actions/create-github-app-token@f2acddfb5195534d487896a656232b016a682f3c # v1.9.0 | ||
id: app-token | ||
with: | ||
app-id: ${{ vars.SLICER_APP_ID }} | ||
private-key: ${{ secrets.SLICER_APP_PRIVATE_KEY }} | ||
|
||
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 | ||
with: | ||
python-version: 3.12 | ||
|
||
- run: pip install pre-commit | ||
|
||
- name: pre-commit autoupdate | ||
run: | | ||
# To ensure the output only contain lines like the following: | ||
# `Updating https://github.com/org/user ... updating v1.2.3 -> v1.2.4` | ||
# without interleaved string like the following: | ||
# `[INFO] Initializing environment for https://github.com/org/user.` | ||
# we perform the autoupdate twice. This ensures the second run can easily be parsed. | ||
pre-commit autoupdate --config .pre-commit-config.yaml 2>&1 | ||
git checkout -- .pre-commit-config.yaml | ||
pre-commit autoupdate | tee /tmp/pre-commit-autoupdate.log | ||
- name: Parse autoupdate output | ||
id: parse-autoupdate | ||
run: | | ||
{ | ||
echo 'AUTOUPATE_LOG<<EOF' | ||
echo "updates:" | ||
while IFS= read -r line; do | ||
repo_url=$(echo "$line" | sed -n 's/Updating \(https:\/\/github.com\/[^\/]\+\/[^\/]\+\) \.\.\. updating \(v[0-9.]\+\) -> \(v[0-9.]\+\)\./\1/p') | ||
old_version=$(echo "$line" | sed -n 's/Updating \(https:\/\/github.com\/[^\/]\+\/[^\/]\+\) \.\.\. updating \(v[0-9.]\+\) -> \(v[0-9.]\+\)\./\2/p') | ||
new_version=$(echo "$line" | sed -n 's/Updating \(https:\/\/github.com\/[^\/]\+\/[^\/]\+\) \.\.\. updating \(v[0-9.]\+\) -> \(v[0-9.]\+\)\./\3/p') | ||
if [ -n "$repo_url" ] && [ -n "$old_version" ] && [ -n "$new_version" ]; then | ||
repo_name=$(echo "$repo_url" | awk -F'/' '{print $NF}') | ||
echo "- [${repo_url}: ${old_version} -> ${new_version}](pre-commit/${repo_name}@${old_version}...${new_version})" | ||
fi | ||
done < /tmp/pre-commit-autoupdate.log | ||
echo EOF | ||
} >> "$GITHUB_OUTPUT" | ||
- run: pre-commit run --all-files | ||
|
||
- uses: peter-evans/create-pull-request@a4f52f8033a6168103c2538976c07b467e8163bc # v6.0.1 | ||
with: | ||
token: ${{ steps.app-token.outputs.token }} | ||
commit-message: | | ||
ENH: Update pre-commit hooks | ||
steps.parse-autoupdate.outputs.AUTOUPATE_LOG | ||
signoff: false | ||
branch: update/pre-commit-hooks | ||
delete-branch: true | ||
title: "ENH: Update pre-commit hooks" | ||
body: | | ||
<!--pre-commit autoupdate log start--> | ||
${{ steps.parse-autoupdate.outputs.AUTOUPATE_LOG }} | ||
<!--pre-commit autoupdate log start--> | ||
This pull-request was auto-generated by the [pre-commit-autoupdate][1] GitHub action workflow. | ||
[1]: https://github.com/${{ github.repository }}/blob/${{ steps.head_branch.outputs.sha }}/.github/workflows/pre-commit-autoupdate.yml | ||
draft: false |