-
Notifications
You must be signed in to change notification settings - Fork 3
70 lines (61 loc) · 2.38 KB
/
reusable-update-pre-commit.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Reusable Update pre-commit
# Update pre-commit config and create PR if changes are detected
# author: Christoph Fröhlich <[email protected]>
on:
workflow_call:
inputs:
ref_for_scheduled_build:
description: 'Reference on which the repo should be checkout for scheduled build. Usually is this name of a branch or a tag.'
default: ''
required: false
type: string
jobs:
auto_update_and_create_pr:
runs-on: ubuntu-latest
env:
# this will be src/{repo-owner}/{repo-name}
path: src/${{ github.repository }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
path: ${{ env.path }}
ref: ${{ github.event.inputs.ref_for_scheduled_build }}
- name: Install pre-commit
run: |
sudo apt-get install -qq python3-venv
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install pre-commit
- name: Auto-update with pre-commit
run: |
source .venv/bin/activate
cd ${{ env.path }}
pre-commit autoupdate || true # Ignoring errors
- name: Check for changes
id: git_status
run: |
cd ${{ env.path }}
git diff --quiet && echo "changed=false" >> $GITHUB_OUTPUT || echo "changed=true" >> $GITHUB_OUTPUT
- name: There are changes
if: steps.git_status.outputs.changed == 'true'
run: |
cd ${{ env.path }}
git diff --exit-code || true
- name: No changes!
if: steps.git_status.outputs.changed == 'false'
run: |
echo "No changes detected"
- name: Create Pull Request
if: steps.git_status.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: auto-update-${{ github.event.inputs.ref_for_scheduled_build }}
commit-message: Bump version of pre-commit hooks
title: Bump version of pre-commit hooks
body: This pull request contains auto-updated files of the pre-commit config. @ros-controls/ros2-maintainers please run the pre-commit workflow manually on the branch `auto-update-${{ github.event.inputs.ref_for_scheduled_build }}` before merging.
delete-branch: true
draft: true
path: ${{ env.path }}