Pre-commit auto-update #194
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
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@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- uses: actions/create-github-app-token@31c86eb3b33c9b601a1f60f98dcbfd1d70f379b4 # v1.10.3 | |
id: app-token | |
with: | |
app-id: ${{ vars.SLICER_APP_ID }} | |
private-key: ${{ secrets.SLICER_APP_PRIVATE_KEY }} | |
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1 | |
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 > /dev/null 2>&1 | |
git checkout -- .pre-commit-config.yaml | |
pre-commit autoupdate --config .pre-commit-config.yaml | tee /tmp/pre-commit-autoupdate.log | |
- name: Save parse-autoupdate.py | |
run: | | |
cat <<EOF >> /tmp/parse-autoupdate.py | |
import re | |
import sys | |
for line in sys.stdin: | |
match = re.match(r"\[https://github.com/([^/]+/[^/]+)\] updating (v?[\d.]+) -> (v?[\d.]+)", line.strip()) | |
if match: | |
repo_url = match.group(1) | |
old_version = match.group(2) | |
new_version = match.group(3) | |
print(f"- [{repo_url}: {old_version} -> {new_version}](https://github.com/{repo_url}/compare/{old_version}...{new_version})") | |
EOF | |
- name: Parse autoupdate output | |
id: parse-autoupdate | |
run: | | |
{ | |
echo 'AUTOUPDATE_LOG<<EOF' | |
echo "updates:" | |
cat /tmp/pre-commit-autoupdate.log | python /tmp/parse-autoupdate.py | |
echo EOF | |
} >> "$GITHUB_OUTPUT" | |
shell: bash | |
- uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # v6.1.0 | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
commit-message: | | |
ENH: Update pre-commit hooks | |
${{ steps.parse-autoupdate.outputs.AUTOUPDATE_LOG }} | |
committer: slicer-app[bot] <163601113+slicer-app[bot]@users.noreply.github.com> | |
author: slicer-app[bot] <163601113+slicer-app[bot]@users.noreply.github.com> | |
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.AUTOUPDATE_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/main/.github/workflows/pre-commit-autoupdate.yml | |
draft: false |