-
Notifications
You must be signed in to change notification settings - Fork 1
319 lines (300 loc) · 10.3 KB
/
rpmbuild.yaml
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
on: # yamllint disable-line rule:truthy
push:
branches:
- master
env:
PYTHONUNBUFFERED: "1"
name: Create RPM Release
jobs:
check-if-himan-bin-changed:
name: check-if-himan-bin-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: himan-bin-changed
with:
filters: |
src:
- 'himan-bin/**'
outputs:
changed: ${{ steps.himan-bin-changed.outputs.src }}
check-if-himan-lib-changed:
name: check-if-himan-lib-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: himan-lib-changed
with:
filters: |
src:
- 'himan-lib/**'
outputs:
changed: ${{ steps.himan-lib-changed.outputs.src }}
check-if-himan-plugins-changed:
name: check-if-himan-plugins-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: himan-plugins-changed
with:
filters: |
src:
- 'himan-plugins/**'
outputs:
changed: ${{ steps.himan-plugins-changed.outputs.src }}
check-if-himan-scripts-changed:
name: check-if-himan-scripts-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: himan-scripts-changed
with:
filters: |
src:
- 'himan-scripts/**'
outputs:
changed: ${{ steps.himan-scripts-changed.outputs.src }}
build-rpms:
name: build-rpms
runs-on: ubuntu-latest
container:
image: rockylinux/rockylinux:8
volumes:
- ${{ github.workspace }}:/github/workspace
needs:
- check-if-himan-bin-changed
- check-if-himan-lib-changed
- check-if-himan-scripts-changed
- check-if-himan-plugins-changed
outputs:
trigger: ${{ steps.set-trigger.outputs.trigger }}
steps:
- name: Install build tools
shell: bash
run: |
dnf -y install rpm-build rpmdevtools git yum-utils dnf-plugins-core findutils
git config --global --add safe.directory '*'
- name: Checkout code
uses: actions/checkout@master
- name: List workspace
run: ls -lah
- name: Setup repositories
shell: bash
run: |
dnf -y install epel-release https://download.fmi.fi/smartmet-open/rhel/8/x86_64/smartmet-open-release-latest-8.noarch.rpm
dnf config-manager --set-enabled powertools
dnf -y module disable postgresql
dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo
dnf config-manager --setopt='epel.exclude=eccodes*' --save
- name: Setup rpmtree
shell: bash
run: |
rpmdev-setuptree
- name: Build himan-lib rpm
id: build-himan-lib
if: needs.check-if-himan-lib-changed.outputs.changed == 'true'
shell: bash
run: |
cd himan-lib
yum-builddep -y himan-lib.spec
make rpm
- name: Build himan-bin rpm
id: build-himan-bin
if: needs.check-if-himan-bin-changed.outputs.changed == 'true'
shell: bash
run: |
cd himan-bin
yum-builddep -y himan-bin.spec
make rpm
- name: Build himan-plugins rpm
id: build-himan-plugins
if: needs.check-if-himan-plugins-changed.outputs.changed == 'true'
shell: bash
run: |
cd himan-plugins
yum-builddep -y himan-plugins.spec
make rpm
- name: Build himan-scripts rpm
id: build-himan-scripts
if: needs.check-if-himan-scripts-changed.outputs.changed == 'true'
shell: bash
run: |
cd himan-scripts
yum-builddep -y himan-scripts.spec
make rpm
- name: Set output
id: set-output
if: |
always() && (steps.build-himan-bin.conclusion == 'success' || steps.build-himan-lib.conclusion == 'success' || steps.build-himan-plugins.conclusion == 'success' || steps.build-himan-scripts.conclusion == 'success')
shell: bash
run: |
mkdir -p /github/workspace/rpmbuild/SRPMS /github/workspace/rpmbuild/RPMS
find /github/home/rpmbuild/SRPMS/ -type f -name "*.src.rpm" -exec cp {} /github/workspace/rpmbuild/SRPMS \;
find /github/home/rpmbuild/RPMS/ -type f -name "*.rpm" -not -name "*debug*" -exec cp {} /github/workspace/rpmbuild/RPMS \;
ls -la /github/workspace/rpmbuild/SRPMS /github/workspace/rpmbuild/RPMS
echo "srpm_dir_path=rpmbuild/SRPMS/" >> "$GITHUB_OUTPUT"
echo "rpm_dir_path=rpmbuild/RPMS/" >> "$GITHUB_OUTPUT"
- name: Save RPM as an artifact
id: save-rpm
if: always() && steps.set-output.conclusion == 'success'
uses: actions/upload-artifact@v2
with:
name: rpm-files
path: ${{ steps.set-output.outputs.rpm_dir_path }}
retention-days: 1
- name: Set trigger
id: set-trigger
if: always() && steps.save-rpm.conclusion == 'success'
shell: bash
run: |
echo "trigger=yes" >> "$GITHUB_OUTPUT"
sync-to-beta-repo:
name: sync-to-beta-repo
needs: build-rpms
runs-on: ubuntu-latest
if: always() && needs.build-rpms.outputs.trigger == 'yes'
steps:
- name: Retrieve saved rpms
uses: actions/download-artifact@v2
with:
name: rpm-files
- name: List rpms
run: find ${{ github.workspace }}
shell: bash
- name: Copy to repo
shell: bash
env:
USER: ${{ secrets.RPM_API_USER }}
PASS: ${{ secrets.RPM_API_PASS }}
HOST: ${{ secrets.RPM_API_HOST_BETA_RHEL8 }}
run: |
find ${{ github.workspace }} -type f -name "*.rpm" -not -name "*debug*" -exec curl --show-error --fail -u $USER:$PASS -F file=@{} $HOST/api/upload \;
run-tests:
name: run-tests
runs-on: ubuntu-latest
needs: sync-to-beta-repo
steps:
- name: Install launch dependencies
shell: bash
run: |
sudo apt -y update && sudo apt -y install python3 python3-boto3 python3-requests
- name: Start tests
id: start-tests
shell: python
run: |
import boto3
import datetime
import os
batch = boto3.client('batch',
aws_access_key_id="${{ secrets.AWS_ACCESS_KEY_ID }}",
aws_secret_access_key="${{ secrets.AWS_SECRET_ACCESS_KEY }}",
region_name="eu-west-1")
response = batch.submit_job(
jobName='himantests-testgh-{}'.format(datetime.datetime.now().strftime("%Y%m%dT%H%M%S")),
jobQueue='himantests-test-queue',
jobDefinition='himantests-testgh-job'
)
print(response)
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f"job-id={response['jobId']}", file=fh)
- name: Wait until finished
id: wait-until-finished
shell: python
run: |
import boto3
import time
import datetime
import os
batch = boto3.client('batch',
aws_access_key_id="${{ secrets.AWS_ACCESS_KEY_ID }}",
aws_secret_access_key="${{ secrets.AWS_SECRET_ACCESS_KEY }}",
region_name="eu-west-1")
jobid = "${{ steps.start-tests.outputs.job-id }}"
status = batch.describe_jobs(jobs=[jobid])['jobs'][0]
print(status)
wait = 30
while status['status'] not in ['FAILED', 'SUCCEEDED']:
time.sleep(wait)
status = batch.describe_jobs(jobs=[jobid])['jobs'][0]
curtime = datetime.datetime.now()
print(f"{curtime}: job status: {status['status']}")
print(f"Finished with status: {status['status']}")
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f"status={status['status']}", file=fh)
print(f"logstream-name={status['attempts'][0]['container']['logStreamName']}", file=fh)
- name: Retrieve logs
if: always()
id: retrieve-logs
shell: python
run: |
import boto3
import datetime
logstream = "${{ steps.wait-until-finished.outputs.logstream-name }}"
print(f"logs at {logstream}")
logs = boto3.client('logs',
aws_access_key_id="${{ secrets.AWS_ACCESS_KEY_ID }}",
aws_secret_access_key="${{ secrets.AWS_SECRET_ACCESS_KEY }}",
region_name="eu-west-1")
response = logs.get_log_events(
logGroupName="/aws/batch/job",
logStreamName=logstream,
startFromHead=True
)
for line in response['events']:
time = datetime.datetime.fromtimestamp(int(line['timestamp'])/1000).strftime("%Y-%m-%d %H:%M:%S.%f")
msg = line['message']
print(f"{time}: {msg}")
sync-to-release-repo:
name: update-rpm-release-repository
needs: run-tests
runs-on: ubuntu-latest
steps:
- name: Retrieve saved rpms
uses: actions/download-artifact@v2
with:
name: rpm-files
- name: List rpms
run: find ${{ github.workspace }}
shell: bash
- name: Copy to repo
shell: bash
env:
USER: ${{ secrets.RPM_API_USER }}
PASS: ${{ secrets.RPM_API_PASS }}
HOST: ${{ secrets.RPM_API_HOST }}
run: |
find ${{ github.workspace }} -type f -name "*.rpm" -not -name "*debug*" -exec curl --show-error --fail -u $USER:$PASS -F file=@{} $HOST/api/upload \;
build-image:
name: build-image-and-push-to-quay.io
runs-on: ubuntu-latest
needs: sync-to-release-repo
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: himan
tags: latest
containerfiles: Containerfile
- name: Test image
uses: fmidev/podman-run-action@v1
with:
image: ${{ steps.build-image.outputs.image-with-tag }}
run: himan -d 5 -l
- name: Push to quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: quay.io/fmi
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Print image url
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"