-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
83 lines (75 loc) · 2.73 KB
/
action.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
71
72
73
74
75
76
77
78
79
80
81
82
83
name: 'Run pre-commit autoupdate'
description: 'Runs pre-commit autoupdate, then runs against all files'
branding:
icon: "chevrons-up"
color: "purple"
inputs:
python-version:
description: "The python version to use with pre-commit"
default: '3.10.12'
runs:
using: "composite"
steps:
#----------------------------------------------
# Check minimum python version
#----------------------------------------------
# 3.10.5 is the min version support for ubuntu 22.04 (latest)
- name: Check compatible version
run: |
min_python_version="3.10.5"
if [ "$(printf '%s\n' "$min_python_version" "${{ inputs.python-version }}" | sort -V | head -n1)" != "$min_python_version" ]; then
echo "Less than the minimum required python version: ${min_python_version}, exiting workflow"
echo "RUN_UPDATE=false" >> $GITHUB_ENV
exit 0
fi
shell: bash
#----------------------------------------------
# Check out the caller repo & Set up python
#----------------------------------------------
- name: Check out repository
if: env.RUN_UPDATE != 'false'
uses: actions/checkout@v4
- name: Set up python
if: env.RUN_UPDATE != 'false'
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
#----------------------------------------------
# Run pre-commit autoupdate
#----------------------------------------------
- if: env.RUN_UPDATE != 'false'
run: pip install pre-commit
shell: bash
- if: env.RUN_UPDATE != 'false'
run: |
UPDATE_MESSAGE=$(pre-commit autoupdate | grep -i 'updating' | grep -v 'Updating dependencies' | sed 's/Updating//g')
echo $UPDATE_MESSAGE
{
echo "UPDATE_MESSAGE<<EOF"
echo "${UPDATE_MESSAGE}"
echo "EOF"
} >> $GITHUB_ENV
shell: bash
- id: run_pre_commit
if: env.RUN_UPDATE != 'false'
run: pre-commit run --all-files
shell: bash
continue-on-error: true
- name: Re-run pre-commit if failed
if: steps.run_pre_commit.outcome != 'success' && env.RUN_UPDATE != 'false'
run: pre-commit run --all-files
shell: bash
#----------------------------------------------
# Create a pull request
#----------------------------------------------
- name: Create Pull Request
if: env.RUN_UPDATE != 'false'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ github.token }}
branch: update/pre-commit-update
title: Update pre-commit
commit-message: "Chore(deps): Updating `pre-commit`"
body: |
Update `pre-commit`.
${{ env.UPDATE_MESSAGE }}