-
Notifications
You must be signed in to change notification settings - Fork 0
306 lines (276 loc) · 10.8 KB
/
create-package.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
name: Create package
on:
workflow_call:
inputs:
skip_checks:
description: Value `true` will skip version checks, use for testing or in nightly builds.
type: boolean
required: false
build_config:
description:
Path to build configuration yaml. Relative path from the repository root,
e.g. `.github/build-config.yml`.
required: false
default: ".github/ci-config.yml"
type: string
cpack_options:
description: CPack options to be used on all platforms.
type: string
required: false
cpack_options_deb:
description: CPack options for DEB generator
type: string
required: false
cpack_options_rpm:
description: CPack options for RPM generator
type: string
required: false
restrict_matrix_jobs:
description: list of matrix jobs to restrict to
type: string
required: false
secrets:
url_debian_11:
description: Use other than the default url for Debian 11.
required: false
token_debian_11:
description: Use other than the default token for Debian 11.
required: false
url_debian_12:
description: Use other than the default url for Debian 12.
required: false
token_debian_12:
description: Use other than the default token for Debian 12.
required: false
url_centos_7:
description: Use other than the default url for CentOS 7.
required: false
token_centos_7:
description: Use other than the default token for CentOS 7.
required: false
url_rocky_8:
description: Use other than the default url for Rocky 8.
required: false
token_rocky_8:
description: Use other than the default token for Rocky 8.
required: false
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
- name: Test tag name pattern
if: ${{ ! inputs.skip_checks }}
shell: python
run: |
import re
import sys
tag_pattern = r"${{ vars.TAG_REGEX_FOR_DEPLOYMENT }}"
ref = "${{ github.ref_name }}"
if not tag_pattern:
sys.exit(0)
if not re.match(tag_pattern, ref):
print(f"::error::{ref} does not match {tag_pattern}")
sys.exit(1)
- name: Test branch name pattern
if: ${{ vars.BRANCH_REGEX_FOR_DEPLOYMENT != '' && (! inputs.skip_checks) }}
run: |
git branch --all --list --format "%(refname:lstrip=-1)" --contains "${{ github.ref_name }}" | grep -E "${{ vars.BRANCH_REGEX_FOR_DEPLOYMENT }}"
setup:
name: setup
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Set Matrix
id: set-matrix
shell: bash -eux {0}
run: |
MATRIX=$(cat << 'EOS'
name:
- gnu@debian-11
- gnu@debian-12
# centos 7 is not compatible with node20
include:
- name: gnu@debian-11
labels: [self-hosted, platform-builder-debian-11]
os: debian-11
compiler: gnu
compiler_cc: gcc
compiler_cxx: g++
compiler_fc: gfortran
cpack_generator: DEB
cpack_options: >
-D CPACK_PACKAGING_INSTALL_PREFIX=/opt/ecmwf
-DCPACK_DEBIAN_PACKAGE_SHLIBDEPS=ON ${{ inputs.cpack_options_deb }}
upload_token: NEXUS_TEST_REPO_UPLOAD_TOKEN
upload_url: NEXUS_TEST_REPO_URL_DEBIAN_11
- name: gnu@debian-12
labels: [self-hosted, platform-builder-debian-12]
os: debian-12
compiler: gnu
compiler_cc: gcc
compiler_cxx: g++
compiler_fc: gfortran
cpack_generator: DEB
cpack_options: >
-D CPACK_PACKAGING_INSTALL_PREFIX=/opt/ecmwf
-DCPACK_DEBIAN_PACKAGE_SHLIBDEPS=ON ${{ inputs.cpack_options_deb }}
upload_token: NEXUS_TEST_REPO_UPLOAD_TOKEN
upload_url: NEXUS_TEST_REPO_URL_DEBIAN_12
# - name: [email protected]
# labels: [self-hosted, platform-builder-centos-7.9]
# os: centos-7.9
# compiler: gnu-8
# compiler_cc: gcc-8
# compiler_cxx: g++-8
# compiler_fc: gfortran-8
# cpack_generator: RPM
# cpack_options: >
# -D CPACK_PACKAGING_INSTALL_PREFIX=/opt/ecmwf
# ${{ inputs.cpack_options_rpm }}
# upload_token: NEXUS_TEST_REPO_UPLOAD_TOKEN
# upload_url: NEXUS_TEST_REPO_URL_CENTOS_7
- name: [email protected]
labels: [self-hosted, platform-builder-rocky-8.6]
os: rocky-8.6
compiler: gnu
compiler_cc: gcc
compiler_cxx: g++
compiler_fc: gfortran
cpack_generator: RPM
cpack_options: >
-D CPACK_PACKAGING_INSTALL_PREFIX=/opt/ecmwf
${{ inputs.cpack_options_rpm }}
upload_token: NEXUS_TEST_REPO_UPLOAD_TOKEN
upload_url: NEXUS_TEST_REPO_URL_ROCKY_8
EOS
)
RESTRICT_MATRIX_JOBS=$(cat << 'EOS'
${{ inputs.restrict_matrix_jobs }}
EOS
)
echo "MATRIX:"
echo $MATRIX
SELECT_NAME_COND="1 != 1"
SELECT_INCLUDE_COND="1 != 1"
for restrict_job in $RESTRICT_MATRIX_JOBS; do SELECT_NAME_COND="$SELECT_NAME_COND or . != \"$restrict_job\""; SELECT_INCLUDE_COND="$SELECT_INCLUDE_COND or .name != \"$restrict_job\""; done
echo matrix=$(echo "$MATRIX" | yq eval "del(.name[] | select($SELECT_NAME_COND)) | del(.include[] | select($SELECT_INCLUDE_COND))" --output-format json --indent 0 -) >> $GITHUB_OUTPUT
echo "GITHUB_OUTPUT:"
echo $GITHUB_OUTPUT
deploy:
if: ${{ github.ref_type == 'tag' || inputs.skip_checks }}
needs: [check, setup]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
runs-on: ${{ matrix.labels }}
steps:
- uses: actions/checkout@v4
- name: Check version number
if: ${{ !inputs.skip_checks }}
shell: python3 {0}
run: |
import os
import re
import sys
tag = "${{ github.ref_name }}"
def check_version():
file_name = "VERSION"
if os.path.isfile(file_name):
with open(file_name, 'r') as f:
version = f.read().strip()
return version
else:
print(f"::warning::{file_name} file not found! Using {file_name} is the preferred method.")
return
def check_cmakelists():
file_name = "CMakeLists.txt"
if os.path.isfile(file_name):
with open(file_name, 'r') as f:
content = f.read()
pattern = r"project\([\s\w]+VERSION\s+((?:\d+)(?:.\d+){0,3})"
hit = re.search(pattern, content)
version = hit.group(1)
return version
else:
print(f"::warning::{file_name} file not found!")
return
version = check_version() or check_cmakelists()
if not version:
print("::error::Version not found!")
sys.exit(1)
if version != tag:
print(f"::error::Git tag ({tag}) and project version ({version}) do not match!")
sys.exit(1)
print("OK: Git tag and project versions match.")
- name: Create package
id: build
uses: ecmwf-actions/reusable-workflows/build-package-with-config@v2
with:
repository: ${{ format('{0}@{1}', github.repository, github.sha ) }}
build_package_inputs: |
repository: ${{ format('{0}@{1}', github.repository, github.sha ) }}
cpack_generator: ${{ matrix.cpack_generator }}
cpack_options: ${{ matrix.cpack_options }} ${{ inputs.cpack_options }}
force_build: true
recreate_cache: true
save_cache: false
self_test: false
build_config: ${{ inputs.build_config }}
- name: Upload binary as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}
path: ${{ steps.build.outputs.package_path }}
retention-days: 3
- name: Upload
run: |
if [ -z "${{ steps.build.outputs.package_path }}" ] || [ ! -f ${{ steps.build.outputs.package_path }} ]; then
echo "::error::Built package not found!"
exit 1
fi
os=${{ matrix.os }}
token=""
url=""
case "$os" in
"debian-11")
token=${{ secrets.token_debian_11 || secrets[matrix.upload_token] }}
url=${{ secrets.url_debian_11 || secrets[matrix.upload_url] }}
;;
"debian-12")
token=${{ secrets.token_debian_12 || secrets[matrix.upload_token] }}
url=${{ secrets.url_debian_12 || secrets[matrix.upload_url] }}
;;
"centos-7.9")
token=${{ secrets.token_centos_7 || secrets[matrix.upload_token] }}
url=${{ secrets.url_centos_7 || secrets[matrix.upload_url] }}
;;
"rocky-8.6")
token=${{ secrets.token_rocky_8 || secrets[matrix.upload_token] }}
url=${{ secrets.url_rocky_8 || secrets[matrix.upload_url] }}
;;
*)
token=${{ secrets[matrix.upload_token] }}
url=${{ secrets[matrix.upload_url] }}
;;
esac
if [ "${{ matrix.cpack_generator }}" == "DEB" ]; then
response=$(curl -w "%{http_code}" --user "$token" -H "Content-Type: multipart/form-data" --data-binary "@${{ steps.build.outputs.package_path }}" "$url")
elif [ "${{ matrix.cpack_generator }}" == "RPM" ]; then
file_name=$(basename "${{ steps.build.outputs.package_path }}")
response=$(curl -w "%{http_code}" --user "$token" --upload-file ${{ steps.build.outputs.package_path }} $url/$file_name)
fi
status=$(echo $response | tail -c 4)
if [ $status -eq 201 ] || [ $status -eq 200 ]; then
echo "Successfully uploaded!"
else
echo "$status: Upload failed"
exit 1
fi