-
Notifications
You must be signed in to change notification settings - Fork 2
214 lines (213 loc) · 8.52 KB
/
ci-build.yaml
File metadata and controls
214 lines (213 loc) · 8.52 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
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
# Generate a distribution package for PyPI.
# Publish the package on PyPI or TestPyPI.
# This reusable workflow uses the [pypi-publish](https://github.com/pypa/gh-action-pypi-publish) GitHub Action
# to publish the distribution package on either PyPI or TestPyPI, depending on the input.
name: '[Reusable]: Build'
on:
workflow_call:
inputs:
config:
description: Configuration as a JSON string.
type: string
required: true
outputs:
hashes:
description: |
Hash values of the generated build distributions.
This is a JSON string representing an array of objects.
value: ${{ jobs.hash-digest.outputs.hashes }}
jobs:
pure:
name: ${{ fromJSON(inputs.config).pure_python && 'Source & Binary Distributions' || 'Source Distribution' }}
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
steps:
- name: Repository Checkout
uses: actions/checkout@v4
with:
repository: ${{ fromJSON(inputs.config).repository }}
ref: ${{ fromJSON(inputs.config).ref }}
fetch-depth: 0
- name: Environment Setup
id: setup
uses: ./.github/actions/install-env
with:
load_cache: 'false'
- name: Build
id: build
run: |
output_path=$(${{ fromJSON(inputs.config).build_command }})
echo "output_path=$output_path" >> "$GITHUB_OUTPUT"
- name: README Render
if: fromJSON(inputs.config).readme_command
id: render
run: |
output_path=$(${{ fromJSON(inputs.config).readme_command }})
echo "output_path=$output_path" >> "$GITHUB_OUTPUT"
- name: Source Distribution Upload
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
path: ${{ steps.build.outputs.output_path }}/**/*.tar.gz
name: ${{ fromJSON(inputs.config).artifact.sdist.name }}
include-hidden-files: ${{ fromJSON(inputs.config).artifact.sdist.include_hidden }}
retention-days: ${{ fromJSON(inputs.config).artifact.sdist.retention_days }}
- name: Binary Distribution Upload
if: ${{ !cancelled() && fromJSON(inputs.config).pure_python }}
uses: actions/upload-artifact@v4
with:
path: ${{ steps.build.outputs.output_path }}/**/*.whl
name: ${{ fromJSON(inputs.config).artifact.wheel.name }}
include-hidden-files: ${{ fromJSON(inputs.config).artifact.wheel.include_hidden }}
retention-days: ${{ fromJSON(inputs.config).artifact.wheel.retention_days }}
- name: ReadMe Upload
if: fromJSON(inputs.config).readme_command
uses: actions/upload-artifact@v4
with:
path: ${{ steps.render.outputs.output_path }}
name: ${{ fromJSON(inputs.config).artifact.readme.name }}
include-hidden-files: ${{ fromJSON(inputs.config).artifact.readme.include_hidden }}
retention-days: ${{ fromJSON(inputs.config).artifact.readme.retention_days }}
native:
name: Binary Distribution | ${{ matrix.build.os.name }}
if: ${{ !fromJSON(inputs.config).pure_python }}
runs-on: ${{ matrix.build.runner }}
strategy:
fail-fast: false
matrix:
build: ${{ fromJSON(inputs.config).cibw }}
steps:
- name: Repository Checkout
uses: actions/checkout@v4
with:
repository: ${{ fromJSON(inputs.config).repository }}
fetch-depth: 0
ref: ${{ fromJSON(inputs.config).ref }}
path: repo
- name: Build
# https://cibuildwheel.readthedocs.io/en/stable/
# https://github.com/pypa/cibuildwheel
uses: pypa/cibuildwheel@v2.22
with:
package-dir: ./repo/${{ fromJSON(inputs.config).pkg_path }}
output-dir: ./dist
env:
CIBW_BUILD: ${{ matrix.build.python }}-${{ matrix.build.platform }}
CIBW_BUILD_VERBOSITY: 2
- name: Build Upload
uses: actions/upload-artifact@v4
with:
path: ./dist
name: ${{ matrix.build.artifact.wheel.name }}
include-hidden-files: ${{ matrix.buildartifact.wheel.include_hidden }}
retention-days: ${{ matrix.build.artifact.wheel.retention_days }}
conda:
name: Conda Distribution | ${{ matrix.task.os.name }}
runs-on: ${{ matrix.task.os.runner }}
strategy:
fail-fast: false
matrix:
task: ${{ fromJSON(inputs.config).conda-builds }}
defaults:
run:
shell: bash -el {0}
steps:
- name: Repository Checkout
uses: actions/checkout@v4
with:
repository: ${{ fromJSON(inputs.config).repository }}
ref: ${{ fromJSON(inputs.config).ref }}
fetch-depth: 0
- name: Environment Setup
id: setup
uses: ./.github/actions/install-env
with:
load_cache: 'false'
- name: Build
id: build
env:
PKG_ID: ${{ fromJSON(inputs.config).pkg_id }}
run: |
output_channel_path=$(${{ fromJSON(inputs.config).build_command_conda }})
echo "output_channel_path=$output_channel_path" >> "$GITHUB_OUTPUT"
- name: Build Upload
uses: actions/upload-artifact@v4
with:
path: ${{ steps.build.outputs.output_channel_path }}
name: ${{ matrix.task.artifact.name }}
include-hidden-files: ${{ matrix.task.artifact.include_hidden }}
retention-days: ${{ matrix.task.artifact.retention_days }}
wheel-merge:
name: Artifact Merge
if: ${{ !cancelled() }}
needs: [ pure, native, conda ]
runs-on: ubuntu-latest
steps:
- name: Wheels
uses: actions/upload-artifact/merge@v4
if: ${{ fromJSON(inputs.config).artifact.wheel.merge }}
with:
name: ${{ fromJSON(inputs.config).artifact.wheel.merge.name }}
pattern: ${{ fromJSON(inputs.config).artifact.wheel.merge.pattern }}
include-hidden-files: ${{ fromJSON(inputs.config).artifact.wheel.include_hidden }}
retention-days: ${{ fromJSON(inputs.config).artifact.wheel.retention_days }}
separate-directories: 'false'
delete-merged: 'true'
- name: Conda Dists
uses: actions/upload-artifact/merge@v4
if: ${{ !cancelled() && fromJSON(inputs.config).artifact.conda.merge }}
with:
name: ${{ fromJSON(inputs.config).artifact.conda.merge.name }}
pattern: ${{ fromJSON(inputs.config).artifact.conda.merge.pattern }}
include-hidden-files: ${{ fromJSON(inputs.config).artifact.conda.include_hidden }}
retention-days: ${{ fromJSON(inputs.config).artifact.conda.retention_days }}
separate-directories: 'true'
delete-merged: 'true'
hash-digest:
name: Hash Digest
if: ${{ !cancelled() }}
needs: [ wheel-merge ]
runs-on: ubuntu-latest
outputs:
hashes: ${{ steps.hash.outputs.hashes }}
steps:
- name: Source Distribution Download
uses: actions/download-artifact@v4
with:
name: ${{ fromJSON(inputs.config).artifact.sdist.name }}
path: dists/sdist
- name: Binary Distribution Download
uses: actions/download-artifact@v4
with:
name: ${{ fromJSON(inputs.config).artifact.wheel.merge.name }}
pattern: ${{ fromJSON(inputs.config).artifact.wheel.merge.pattern }}
path: dists/wheels
merge-multiple: 'true'
- name: Conda Distribution Download
uses: actions/download-artifact@v4
with:
name: ${{ fromJSON(inputs.config).artifact.conda.merge.name }}
pattern: ${{ fromJSON(inputs.config).artifact.conda.merge.pattern }}
path: dists/conda
merge-multiple: 'true'
- name: File Overview
run: tree
- name: Hash Generation
id: hash
run: |
directory="dists"
hashes="["
while IFS= read -r -d '' file; do
filename=$(basename "$file")
md5=$(openssl dgst -md5 "$file" | awk '{print $NF}')
sha1=$(openssl dgst -sha1 "$file" | awk '{print $NF}')
sha256=$(openssl dgst -sha256 "$file" | awk '{print $NF}')
hashes="$hashes{\"filename\":\"$filename\",\"md5\":\"$md5\",\"sha1\":\"$sha1\",\"sha256\":\"$sha256\"},"
done < <(find "$directory" -type f \( -name "*.tar.gz" -o -name "*.whl" -o -name "*.conda" \) -print0)
# Remove trailing comma and close the JSON array
hashes="${hashes%,}]"
# Output the JSON array
echo "Hashes: $hashes"
echo "hashes=$hashes" >> $GITHUB_OUTPUT