-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (154 loc) · 7.12 KB
/
update-python.yaml
File metadata and controls
178 lines (154 loc) · 7.12 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Update Python template version pins
on:
schedule:
- cron: '0 0 1 1,7 *'
workflow_dispatch:
env:
PYTHON_TEMPLATE_LOCATION: "python/{{cookiecutter.project_slug}}"
MIN_PYTHON_VERSION: "3.11" # use minimum supported python version
permissions:
contents: write
pull-requests: write
jobs:
update_ruff:
name: Update Python Ruff version pins
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.MIN_PYTHON_VERSION }}
- name: Install latest Ruff
run: python3 -m pip install ruff
- name: Get latest ruff version
id: ruff-version
run: |
echo "RUFF_VERSION=$(pip show ruff | grep 'Version' | cut -d ' ' -f 2)" >> $GITHUB_ENV
- name: Update Ruff Version in pyproject.toml
run: |
sed -i "s/\"ruff==.*\"/\"ruff==${{ env.RUFF_VERSION }}\"/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml
- name: Update Ruff version in .pre-commit-config.yaml
run: |
sed -i "s/rev: .* # ruff version/rev: v${{ env.RUFF_VERSION }} # ruff version/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
- name: Create new branch, commit, and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
if git diff --quiet; then
echo "new_commits=false" >> $GITHUB_ENV
exit 0
else
git checkout -b update-ruff-${{ env.RUFF_VERSION }}
git add ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
git commit -m "Update ruff version to ${{ env.RUFF_VERSION }}"
echo "new_commits=true" >> $GITHUB_ENV
fi;
git push --set-upstream origin update-ruff-${{ env.RUFF_VERSION }}
- name: Create pull request
if: env.new_commits == 'true'
run: |
gh pr create --title "style(python): update ruff to ${{ env.RUFF_VERSION }}" \
--body "Automatically update the Ruff version in \`pyproject.toml\` and \`.pre-commit-config.yaml\`." \
--base main \
--head update-ruff-${{ env.RUFF_VERSION }} \
--reviewer "jsstevenson,korikuzma" \
--label "priority:low"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update_precommit_and_hooks:
name: Update Python prek version pins and hooks
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.MIN_PYTHON_VERSION }}
- name: Install latest prek
run: python3 -m pip install prek
- name: Get latest prek version
id: prek-version
run: |
echo "PRECOMMIT_VERSION=$(pip show prek | grep 'Version' | cut -d ' ' -f 2)" >> $GITHUB_ENV
- name: Update prek version in pyproject.toml
run: |
sed -i "s/\"prek>=.*\"/\"prek>=${{ env.PRECOMMIT_VERSION }}\"/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml
- name: Update min prek version requirement in .pre-commit-config.yaml
run: |
sed -i "s/minimum_pre_commit_version: .*/minimum_pre_commit_version: ${{ env.PRECOMMIT_VERSION }}/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
- name: Create new branch, commit, and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
if git diff --quiet; then
echo "new_commits=false" >> $GITHUB_ENV
exit 0
else
git checkout -b update-precommit-${{ env.PRECOMMIT_VERSION }}
git add ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
git commit -m "Update precommit to ${{ env.PRECOMMIT_VERSION }}"
echo "new_commits=true" >> $GITHUB_ENV
fi;
git push --set-upstream origin update-precommit-${{ env.PRECOMMIT_VERSION }}
- name: Create pull request
if: env.new_commits == 'true'
run: |
gh pr create --title "cicd(python): update precommit to ${{ env.PRECOMMIT_VERSION }}" \
--body "Automatically update the prek version in \`pyproject.toml\` and \`.pre-commit-config.yaml\`." \
--base main \
--head update-precommit-${{ env.PRECOMMIT_VERSION }} \
--reviewer "jsstevenson,korikuzma" \
--label "priority:low"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update_precommit_hooks:
name: Update Python pre-commit-hooks version pins
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.MIN_PYTHON_VERSION }}
- name: Get latest pre-commit-hooks version
run: |
latest_tag=$(curl -s https://api.github.com/repos/pre-commit/pre-commit-hooks/releases | jq -r '.[0].tag_name')
echo "PRECOMMIT_HOOKS_VERSION=$latest_tag" >> $GITHUB_ENV
- name: Update pre-commit-hooks version in .pre-commit-config.yaml
run: |
sed -i "s/rev: .* # pre-commit-hooks version/rev: ${{ env.PRECOMMIT_HOOKS_VERSION }} # pre-commit-hooks version/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
- name: Create new branch, commit, and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
if git diff --quiet; then
echo "new_commits=false" >> $GITHUB_ENV
exit 0
else
git checkout -b update-precommit-hooks-${{ env.PRECOMMIT_HOOKS_VERSION }}
git add ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
git commit -m "Update pre-commit-hooks version to ${{ env.PRECOMMIT_HOOKS_VERSION }}"
echo "new_commits=true" >> $GITHUB_ENV
fi;
git push --set-upstream origin update-precommit-hooks-${{ env.PRECOMMIT_HOOKS_VERSION }}
- name: Create pull request
if: env.new_commits == 'true'
run: |
gh pr create --title "cicd(python): update pre-commit-hooks to ${{ env.PRECOMMIT_HOOKS_VERSION }}" \
--body "Automatically update the pre-commit-hooks version in \`.pre-commit-config.yaml\`." \
--base main \
--head update-precommit-hooks-${{ env.PRECOMMIT_HOOKS_VERSION }} \
--reviewer "jsstevenson,korikuzma" \
--label "priority:low"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}