-
-
Notifications
You must be signed in to change notification settings - Fork 90
362 lines (326 loc) · 10.6 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
---
name: pip-tools
on: # yamllint disable-line rule:truthy
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)
|| ''
}}
concurrency:
group: >-
${{
github.workflow
}}-${{
github.event.inputs.package-distribuition
|| github.event.pull_request.number
|| github.sha
}}
cancel-in-progress: true
jobs:
deps:
name: >-
⛓🔒 🐍${{
matrix.python-version
}} @ ${{
matrix.os
}}
runs-on: ${{ matrix.os }}
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.8
- 3.11
- >-
3.10
- 3.9
os:
- ubuntu-20.04
- macOS-11.0
- windows-2019
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
PIP_NO_PYTHON_VERSION_WARNING: 1
PIP_NO_WARN_SCRIPT_LOCATION: 1
PY_COLORS: 1
steps:
- name: Grab the source from Git
uses: actions/checkout@v3 # Keep before `setup-python` for cache to work
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
cache: pip
cache-dependency-path: requirements/**
python-version: ${{ matrix.python-version }}
- name: Upgrade pip with `requires_python`
run: >-
python -m
pip install
--user
--upgrade
--force-reinstall
pip-with-requires-python
- name: Install pip-tools
run: >-
python -m
pip install
--user
pip-tools
- 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
id: constraints
# NOTE: `sed` under macOS needs a backup argument.
# Ref: https://stackoverflow.com/a/7573438/595220
run: >
set -x
BASE_NAME=$(
PYTHONPATH=bin/ python -c
'from pip_constraint_helpers import get_constraint_file_path,
get_runtime_python_tag;
print(get_constraint_file_path(
"", "py", get_runtime_python_tag())[:-4]
)
'
)
(cd requirements/;
${{
runner.os != 'Windows'
&& 'ln -svf tests.in "${BASE_NAME}.in"; git add "${BASE_NAME}.in"'
|| 'GIT_INDEX_OBJECT_SYMLINK_TYPE=120000;
SYMLINK_TARGET_HASH=$(echo -n tests.in | git hash-object --stdin);
CURRENT_SRC_OBJECT_TYPE="$(
git ls-tree HEAD -- "${BASE_NAME}.in"
| awk "{print\$1}"
)";
echo "CURRENT_SRC_OBJECT_TYPE=${CURRENT_SRC_OBJECT_TYPE}";
if [[ "${GIT_INDEX_OBJECT_SYMLINK_TYPE}" !=
"${CURRENT_SRC_OBJECT_TYPE}" ]];
then
git update-index --add --cacheinfo
"${GIT_INDEX_OBJECT_SYMLINK_TYPE}" "${SYMLINK_TARGET_HASH}"
"requirements/${BASE_NAME}.in" &&
git status &&
git restore -- "${BASE_NAME}.in";
fi'
}}
)
python -m piptools compile
${{
(
github.event_name == 'workflow_dispatch'
&& github.event.inputs.package-distribuition
)
&& format(
'--upgrade-package="{0}"',
github.event.inputs.package-distribuition
)
|| '--upgrade'
}}
--output-file="requirements/${BASE_NAME}.txt"
"requirements/${BASE_NAME}.in"
pyproject.toml
git add "requirements/${BASE_NAME}.txt"
git commit -m "Update ${BASE_NAME} constraints${{
(
github.event_name == 'workflow_dispatch'
&& github.event.inputs.package-distribuition
)
&& format(' for {0}', github.event.inputs.package-distribuition)
|| ''
}}" requirements/
&& {
echo
"patch=0001-Update-${BASE_NAME}-constraints.patch"
>> "${GITHUB_OUTPUT}"
;
}
|| :
shell: bash
- 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
- name: Create a patch from the last Git commit
if: steps.constraints.outputs.patch
run: >-
git format-patch
--output='${{
runner.temp
}}/patches/${{
steps.constraints.outputs.patch
}}'
-1
HEAD
- name: Save the package bump patch as a GHA artifact
if: steps.constraints.outputs.patch
uses: actions/upload-artifact@v3
with:
name: pip-constraints-git-patches
path: ${{ runner.temp }}/patches/${{ steps.constraints.outputs.patch }}
check: # This job does nothing and is only used for the branch protection
name: >-
check
⮸
${{
(
github.event_name == 'workflow_dispatch'
&& github.event.inputs.package-distribuition
)
&& format('`{0}`', github.event.inputs.package-distribuition)
|| 'everything'
}}
if: always()
needs:
- deps
runs-on: ubuntu-latest
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
environment: pip-tools
permissions:
contents: write # Needed to enable auto-merge
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@v3
with:
name: pip-constraints-git-patches
path: ${{ runner.temp }}/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@v3
with:
ssh-key: ${{ secrets.PIP_TOOLS_DEPLOYMENT_KEY }}
- 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 '${{ env.git-branch }}'
)" >> "${GITHUB_OUTPUT}"
- name: Fetch the existing remote PR branch
if: steps.pre-existing-remote-branch.outputs.info
run: git fetch origin '${{ env.git-branch }}'
- name: Switch to the PR branch
if: steps.artifacts.outputs.lockfile-updates-needed
run: git checkout -B '${{ env.git-branch }}'
- name: Make an empty initial commit
if: >-
!steps.pre-existing-remote-branch.outputs.info
&& steps.artifacts.outputs.lockfile-updates-needed
run: git commit --allow-empty -m "Pip-tools initial commit $(uuidgen)"
- name: Push the PR branch to remote
# ... so that it's possible to create a PR out of it
if: >-
!steps.pre-existing-remote-branch.outputs.info
&& steps.artifacts.outputs.lockfile-updates-needed
# FIXME: use `GITHUB_TOKEN`
run: git push --atomic origin 'HEAD:${{ env.git-branch }}'
- name: Wipe the dummy commit
if: >-
!steps.pre-existing-remote-branch.outputs.info
&& steps.artifacts.outputs.lockfile-updates-needed
# ... so that it's possible to create a PR out of it
run: git reset HEAD^
- name: Create a PR
if: >-
!steps.pre-existing-remote-branch.outputs.info
&& steps.artifacts.outputs.lockfile-updates-needed
id: pr
uses: vsoch/[email protected]
env:
BRANCH_PREFIX: ''
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST_BODY: >-
Automated pip-tools-managed pip constraint lockfiles update.
PULL_REQUEST_BRANCH: ${{ github.event.repository.default_branch }}
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: Log the pull request details
run: >-
echo
"PR number: ${{ steps.pr.outputs.pull_request_number }}"
"\nPR URL: ${{ steps.pr.outputs.pull_request_url }}"
- 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
# ... with only the useful commits which will cause a `pull_request`
# `synchronize` event because of the SSH key
if: steps.artifacts.outputs.lockfile-updates-needed
run: >-
git push
--atomic
origin 'HEAD:${{ env.git-branch }}'
--force-with-lease
- name: Enable auto-merge for the PR
if: steps.pr.outputs.pull_request_url
run: >-
gh pr merge
--auto --merge
'${{ steps.pr.outputs.pull_request_url }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
...