-
Notifications
You must be signed in to change notification settings - Fork 17
399 lines (355 loc) · 11.5 KB
/
pip-tools.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
---
name: 🔒 pip-tools
on:
workflow_dispatch:
inputs:
package-distribuition:
# github.event_name == 'workflow_dispatch'
# && github.event.inputs.package-distribuition
description: >-
A target Python package distribution to upgrade
required: false
pull_request:
paths:
- .github/workflows/pip-tools.yml
schedule:
- cron: 1 0 * * * # Run daily at 0:01 UTC
env:
GIT_BRANCH: >-
maintenance/pip-tools-constraint-lockfiles${{
(
github.event_name == 'workflow_dispatch'
&& github.event.inputs.package-distribuition
)
&& format('-updating-{0}', github.event.inputs.package-distribuition)
|| ''
}}
PIP_DISABLE_PIP_VERSION_CHECK: 1
PIP_NO_PYTHON_VERSION_WARNING: 1
PIP_NO_WARN_SCRIPT_LOCATION: 1
PY_COLORS: 1
concurrency:
group: >-
${{
github.workflow
}}-${{
github.event.inputs.package-distribuition
|| github.event.pull_request.number
|| github.sha
}}
cancel-in-progress: true
run-name: >-
⮸
Bumping
${{
(
github.event_name == 'workflow_dispatch'
&& github.event.inputs.package-distribuition
)
&& format('`{0}`', github.event.inputs.package-distribuition)
|| 'everything'
}}
in all the lock files
🔒
jobs:
deps:
name: >-
⛓${{ matrix.lock-file-env }}:
🐍${{
matrix.python-version
}}@${{
matrix.os
}}
runs-on: ${{ matrix.os }}
timeout-minutes: 3
strategy:
matrix:
python-version:
# NOTE: The latest and the lowest supported Pythons are prioritized
# NOTE: to improve the responsiveness. It's nice to see the most
# NOTE: important results first.
- 3.12
- 3.11
- ~3.13.0-0
os:
- ubuntu-22.04
- macos-14
- macos-13
- windows-2019
lock-file-env:
- build-dists
- build-docs
- linkcheck-docs
- metadata-validation
- pip-compile
- pip-compile-build-lock
- pip-compile-tox-env-lock
- pre-commit
- py
- tox
- spellcheck-docs
lock-file-extra-input:
- pyproject.toml
- ''
exclude:
- lock-file-env: build-dists
lock-file-extra-input: pyproject.toml
- lock-file-env: build-docs
lock-file-extra-input: ''
- lock-file-env: linkcheck-docs
lock-file-extra-input: ''
- lock-file-env: metadata-validation
lock-file-extra-input: pyproject.toml
- lock-file-env: pip-compile
lock-file-extra-input: pyproject.toml
- lock-file-env: pip-compile-build-lock
lock-file-extra-input: pyproject.toml
- lock-file-env: pip-compile-tox-env-lock
lock-file-extra-input: pyproject.toml
- lock-file-env: pre-commit
lock-file-extra-input: pyproject.toml
- lock-file-env: py
lock-file-extra-input: ''
- lock-file-env: tox
lock-file-extra-input: pyproject.toml
- lock-file-env: spellcheck-docs
lock-file-extra-input: ''
env:
TOXENV: pip-compile-tox-env-lock
steps:
- name: Grab the source from Git
uses: actions/checkout@v4 # Keep before `setup-python` for cache to work
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
cache: pip
cache-dependency-path: requirements/**
python-version: ${{ matrix.python-version }}
- name: Identify tox's own lock file
id: tox-deps
run: >
LOCK_FILE_PATH="requirements/$(
python bin/print_lockfile_base_name.py tox
).txt"
echo lock-file="$(
ls -1 "${LOCK_FILE_PATH}"
|| >&2 echo "${LOCK_FILE_PATH}" not found, not injecting...
)"
>> "${GITHUB_OUTPUT}"
shell: bash # windows compat
- name: Install tox
run: >-
python -Im pip install -r requirements/tox-tox.in
${{
steps.tox-deps.outputs.lock-file
&& format('--constraint={0}', steps.tox-deps.outputs.lock-file)
|| ''
}}
shell: bash # windows compat
- name: Pre-populate the tox env
run: python -Im tox --skip-missing-interpreters false --notest
- name: Setup git user as [bot]
# Refs:
# * https://github.community/t/github-actions-bot-email-address/17204/6
# * https://github.com/actions/checkout/issues/13#issuecomment-724415212
uses: fregante/[email protected]
- name: Generate constraints files
run: >-
python -Im tox r
--
${{ matrix.lock-file-env }} ${{ matrix.lock-file-extra-input }}
${{
(
github.event_name == 'workflow_dispatch'
&& github.event.inputs.package-distribuition
)
&& format(
'--upgrade-package="{0}"',
github.event.inputs.package-distribuition
)
|| '--upgrade'
}}
- name: Commit version bumps to Git
id: constraints
run: |
LOCK_BASE_NAME=$(python bin/print_lockfile_base_name.py ${{
matrix.lock-file-env
}})
git add "requirements/${LOCK_BASE_NAME}.txt"
git commit "requirements/${LOCK_BASE_NAME}.txt" \
-m "Update ${LOCK_BASE_NAME} constraints${{
(
github.event_name == 'workflow_dispatch'
&& github.event.inputs.package-distribuition
)
&& format(' for {0}', github.event.inputs.package-distribuition)
|| ''
}}" \
&& {
echo "patch=${{
runner.temp
}}/patches/0001-Update-${LOCK_BASE_NAME}-constraints.patch" \
>> "${GITHUB_OUTPUT}"
} \
|| :
shell: bash # windows compat
- name: Log the patch
if: steps.constraints.outputs.patch
run: git show --color
- name: Create a temporary patch directory
if: steps.constraints.outputs.patch
run: mkdir -pv '${{ runner.temp }}/patches'
shell: bash # windows compat
- name: Create a patch from the last Git commit
if: steps.constraints.outputs.patch
run: >-
git format-patch
--output='${{ steps.constraints.outputs.patch }}'
-1
HEAD
- name: Make a GHA artifact suffix
if: steps.constraints.outputs.patch
id: random
run: >-
echo uuid=$(python -c 'import uuid; print(uuid.uuid4())')
>> "${GITHUB_OUTPUT}"
shell: bash # windows compat
- name: Save the package bump patch as a GHA artifact
if: steps.constraints.outputs.patch
uses: actions/upload-artifact@v4
with:
name: pip-constraints-git-patches--${{ steps.random.outputs.uuid }}
path: ${{ steps.constraints.outputs.patch }}
check: # This job does nothing and is only used for the branch protection
if: always()
needs:
- deps
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
publish-pr:
name: Open/refresh a PR
if: github.event_name != 'pull_request'
needs:
- check
runs-on: Ubuntu-latest
timeout-minutes: 1
environment:
name: pip-tools
url: ${{ steps.pr.outputs.pull_request_url }}
permissions:
contents: write
pull-requests: write
steps:
- name: Download all the dists
id: artifacts-download
continue-on-error: true # and judge whether there's updates later
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: ${{ runner.temp }}/patches/
pattern: pip-constraints-git-patches--*
- name: >-
Determine whether any change suggestions to lockfiles
have been produced
if: steps.artifacts-download.outcome == 'success'
id: artifacts
run: >-
echo "lockfile-updates-needed=true" >> "${GITHUB_OUTPUT}"
- name: Grab the source from Git
if: steps.artifacts.outputs.lockfile-updates-needed
uses: actions/checkout@v4
- name: Setup git user as [bot]
if: steps.artifacts.outputs.lockfile-updates-needed
# Refs:
# * https://github.community/t/github-actions-bot-email-address/17204/6
# * https://github.com/actions/checkout/issues/13#issuecomment-724415212
uses: fregante/[email protected]
- name: Figure out if the pre-existing remote branch exists
if: steps.artifacts.outputs.lockfile-updates-needed
id: pre-existing-remote-branch
run: >-
echo "info=$(
git ls-remote origin "${GIT_BRANCH}"
)" >> "${GITHUB_OUTPUT}"
- name: Fetch the existing remote PR branch
if: steps.pre-existing-remote-branch.outputs.info
run: git fetch origin "${GIT_BRANCH}"
- name: Switch to the PR branch
if: steps.artifacts.outputs.lockfile-updates-needed
run: git checkout -B "${GIT_BRANCH}"
- name: List Git patches
if: steps.artifacts.outputs.lockfile-updates-needed
run: ls -alh '${{ runner.temp }}/patches/'
- name: Apply patches to the Git repo
if: steps.artifacts.outputs.lockfile-updates-needed
run: git am '${{ runner.temp }}/patches'/*.patch
- name: Force-push the PR branch to remote
if: steps.artifacts.outputs.lockfile-updates-needed
run: git push origin "HEAD:${GIT_BRANCH}" --force-with-lease
- name: Create a PR
if: >-
!steps.pre-existing-remote-branch.outputs.info
&& steps.artifacts.outputs.lockfile-updates-needed
id: new-pr
uses: vsoch/[email protected]
env:
BRANCH_PREFIX: ''
GITHUB_TOKEN: ${{ github.token }}
PULL_REQUEST_BODY: >-
Automated pip-tools-managed pip constraint lockfiles update.
PULL_REQUEST_BRANCH: ${{ github.event.repository.default_branch }}
PULL_REQUEST_DRAFT: true
PULL_REQUEST_FROM_BRANCH: ${{ env.GIT_BRANCH }}
PULL_REQUEST_TITLE: >-
⛓🔒 Bump transitive deps in pip-tools-managed lockfiles${{
(
github.event_name == 'workflow_dispatch'
&& github.event.inputs.package-distribuition
)
&& format(' for {0}', github.event.inputs.package-distribuition)
|| ''
}}
- name: Retrieve the existing PR URL
if: steps.pre-existing-remote-branch.outputs.info
id: existing-pr
env:
GITHUB_TOKEN: ${{ github.token }}
run: >
echo -n pull_request_url=
>> "${GITHUB_OUTPUT}"
gh pr view
--json 'url'
--jq '.url'
--repo '${{ github.repository }}'
'${{ env.GIT_BRANCH }}'
>> "${GITHUB_OUTPUT}"
- name: Select the actual PR URL
id: pr
env:
GITHUB_TOKEN: ${{ github.token }}
run: >
echo -n pull_request_url=
>> "${GITHUB_OUTPUT}"
echo '${{
steps.new-pr.outputs.pull_request_url
|| steps.existing-pr.outputs.pull_request_url
}}'
>> "${GITHUB_OUTPUT}"
- name: Log the pull request details
run: >-
echo 'PR URL: ${{ steps.pr.outputs.pull_request_url }}'
| tee -a "${GITHUB_STEP_SUMMARY}"
- name: Instruct the maintainers to trigger CI by undrafting the PR
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh pr comment
--body 'Please mark the PR as ready for review to trigger PR checks.'
--repo '${{ github.repository }}'
'${{ steps.pr.outputs.pull_request_url }}'
...