-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
267 lines (218 loc) · 6.89 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
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
---
name: build-python-dists
description: >-
GitHub Action for building Python package distributions via PEP 517
author: >-
Sviatoslav Sydorenko
<wk+~github.com/re-actors/build-python-dists@sydorenko.org.ua>
branding:
icon: package
color: green
inputs:
build-extra-args:
default:
description: >-
Extra args to pass to the PyPA/build tool invocation
(can be used to pass `--config-setting` args)
required: false
pip-constraints-file:
default:
description: >-
`constraints.txt`-compliant file path for the managed isolated
build environment to respect
required: false
dist-type:
default:
description: >-
One of `sdist` or `wheel` (defaults to building both)
required: false
dists-dir:
default: dist/
description: >-
A directory to put the dists into (default: `dist/`)
required: false
workflow-artifact-name:
default:
description: >-
If set, is used the produced dists are made accessible to the
later jobs under this name (defaults to unset)
required: false
expected-artifact-names:
default:
description: >-
Space-delimited list of globs for the filenames. If set, it is
used as a sanity check to fail-fast if the produced artifacts do
not match the expectation (defaults to unset)
required: false
isolated-build-env:
default: true
description: >-
Whether or not to create an isolated build environment
required: false
check-build-deps:
default: true
description: >-
Whether or not validate the PEP 517 build backend required
dependencies against what's installed in the build environment
required: false
build-version-spec:
default: build
description: >-
PyPA/build tool version to use for building the dists
(defaults to `build`, can be pinned to a precise version)
required: false
python-version:
default: >-
3.10
description: >-
Python version to use as the current tox runtime
(defaults to `3.10`)
required: false
validate-dists-meta:
default: true
description: >-
Whether or not to perform the produced distribution packages
validation
required: false
build-source:
default: git
description: >-
Where to check out the source from
(defaults to `git`, can also be `sdist` or `skip`)
required: false
outputs:
dists:
description: List of the built distribution packages
value: ${{ steps.dists.outputs.all }}
sdist:
description: Name of the source distribution package
value: ${{ steps.dists.outputs.sdist }}
wheels:
description: List of the binary distribution packages
value: ${{ steps.dists.outputs.wheels }}
workflow-artifact-name:
description: Workflow artifact that contains all of the produced dists
value: ${{ inputs.workflow-artifact-name }}
runs:
using: composite
steps:
- name: Validate that a valid dist type was requested
if: >-
inputs.dist-type
&& inputs.dist-type != 'sdist'
&& inputs.dist-type != 'wheel'
run: exit 1
shell: bash
- name: Retrieve the project source from the repository
if: inputs.build-source == 'git'
uses: actions/checkout@v2
- name: Retrieve the project source from an sdist inside the GHA artifact
if: inputs.workflow-artifact-name && inputs.build-source == 'sdist'
uses: re-actors/checkout-python-sdist@main
with:
workflow-artifact-name: ${{ inputs.workflow-artifact-name }}
source-tarball-name: >-
*.tar.gz
- name: Set the active Python interpeter to ${{ inputs.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ inputs.python-version }}
- name: Install ${{ inputs.build-version-spec }}
run: >
echo '::group::Installing ${{ inputs.build-version-spec }}'
python -m pip install '${{ inputs.build-version-spec }}'
echo '::endgroup::'
shell: bash
- name: Prepare a temporary for putting the dists there
id: dists-tmp
run: >
echo '::group::Preparing a temporary dists directory...'
TMPDIR=$(
mktemp -d --suffix=-dists "${GITHUB_ACTION_PATH}/tmp-XXXXX"
)
&& echo "::set-output name=dir::${TMPDIR}"
echo '::endgroup::'
shell: bash
- name: Build dists v${{ inputs.build-version-spec }}
env:
PIP_CONSTRAINT: ${{ inputs.pip-constraints-file }}
run: >
set -x
echo '::group::Building dists v${{ inputs.build-version-spec }}'
python -m build ${{
inputs.dist-type
&& format('--{0}', inputs.dist-type)
|| ''
}} --outdir '${{
steps.dists-tmp.outputs.dir
}}' ${{
!fromJSON(inputs.check-build-deps)
&& '--skip-dependency-check'
|| ''
}} ${{
!fromJSON(inputs.isolated-build-env)
&& '--no-isolation'
|| ''
}} ${{
inputs.build-extra-args
}}
echo '::endgroup::'
shell: bash
- name: Validate the artifact names
if: inputs.expected-artifact-names
run: >
echo '::group::Validating the artifact names...'
ls -1
${{ inputs.expected-artifact-names }}
mkdir -pv '${{ steps.dists-tmp.outputs.dir }}--tmp'
&& mv ${{ inputs.expected-artifact-names }}
'${{ steps.dists-tmp.outputs.dir }}--tmp/'
test -z "$(ls -A)"
mv -v ${{ steps.dists-tmp.outputs.dir }}--tmp/* .
&& rmdir -v '${{ steps.dists-tmp.outputs.dir }}--tmp'
echo '::endgroup::'
shell: bash
working-directory: ${{ steps.dists-tmp.outputs.dir }}
- name: Validate artifacts metadata
if: inputs.expected-artifact-names
run: >
echo '::group::Validating the artifacts metadata per spec...'
twine check --strict
${{
inputs.expected-artifact-names
&& inputs.expected-artifact-names
|| '*'
}}
echo '::endgroup::'
shell: bash
working-directory: ${{ steps.dists-tmp.outputs.dir }}
- name: Save the dists as a GHA artifact
if: inputs.workflow-artifact-name
uses: actions/upload-artifact@v2
with:
name: ${{ inputs.workflow-artifact-name }}
path: ${{ steps.dists-tmp.outputs.dir }}
- name: Move dists to the requested target directory
run: >
echo '::group::Putting the dists into the requested location...'
mkdir -pv ${{ inputs.dists-dir }}
&& mv -v
${{ steps.dists-tmp.outputs.dir }}/*
${{ inputs.dists-dir }}
echo '::endgroup::'
shell: bash
- name: Move dists to the requested target directory
id: dists
run: >
echo '::group::Saving the dist names as outputs...'
echo "::set-output name=all::$(
ls -1 *.tar.gz *.whl
| tr '\n' ' '
| sed 's#\s\+$##;s#^\s\+##g'
)"
echo "::set-output name=sdist::$(ls -1 *.tar.gz)"
echo "::set-output name=wheels::$(ls -1 *.whl | cat)"
echo '::endgroup::'
shell: bash
working-directory: ${{ inputs.dists-dir }}
...