forked from ctc-oss/fapolicy-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
381 lines (323 loc) · 11.9 KB
/
rpm.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
on:
push:
branches:
- 'master'
- 'release/*'
- 'rpm/test/*'
tags:
- 'v*'
pull_request:
branches:
- 'master'
- 'release/*'
name: RPM
jobs:
config:
name: Load configuration
runs-on: ubuntu-20.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
is-copr-enabled: ${{ steps.is-copr-enabled.outputs.defined }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Load config matrix
id: set-matrix
run: |
echo "::set-output name=matrix::$(cat .github/rpm-matrix.json | tr -d '\n' | tr -d ' ')"
- name: Copr token discovery
id: is-copr-enabled
if: "${{ env.COPR_KEY != '' }}"
run: echo "::set-output name=defined::true"
env:
COPR_KEY: ${{ secrets.COPR_API_LOGIN }}
source0:
name: Vendor Source0
container: registry.fedoraproject.org/fedora:38
runs-on: ubuntu-20.04
steps:
- name: Install deps
run: dnf install -y git make python3
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Mark as git safe
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
- name: Generate build info
run: |
scripts/build-info.py --git
git add -f fapolicy_analyzer/resources/build-info.json
git config user.name 'CI'
git config user.email '<>'
git commit -m build-info
- name: Vendor
run: |
make -f .copr/Makefile vendor-app spec=fapolicy-analyzer.spec
- name: Rename source0 with prerelease version
if: endsWith(github.ref, '/master')
run: |
spec_version=$(grep "Version:" fapolicy-analyzer.spec | tr -s ' ' | cut -d' ' -f2)
commit_number=$(git rev-list HEAD~1 --count)
patched_version="$spec_version~dev${commit_number}"
mv fapolicy-analyzer-${spec_version}.tar.gz fapolicy-analyzer-${patched_version}.tar.gz
- name: Rename source0 with pull request version
if: github.event_name == 'pull_request'
run: |
spec_version=$(grep "Version:" fapolicy-analyzer.spec | tr -s ' ' | cut -d' ' -f2)
pr_number=${{ github.event.pull_request.number }}
patched_version="0.0.${pr_number}"
mv fapolicy-analyzer-${spec_version}.tar.gz fapolicy-analyzer-${patched_version}.tar.gz
- name: Upload
uses: actions/upload-artifact@v3
with:
name: source0
path: |
fapolicy-analyzer-*.tar.gz
- name: Checksum
run: |
sha256sum fapolicy-analyzer-*.tar.gz
srpm:
needs: [ config, source0 ]
name: SRPM Build ${{ matrix.props.dist }}
container: ${{ matrix.props.image }}
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJson(needs.config.outputs.matrix) }}
steps:
- name: Enable EPEL
if: startsWith(matrix.props.dist, 'el')
run: |
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-${{ matrix.props.version }}.noarch.rpm
- name: Install Git
run: dnf install -y git
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Strip ref to tag
id: tag_name
if: startsWith(github.ref, 'refs/tags/v')
run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d/ -f3)
- name: Mark as git safe
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
- name: Ensure spec version matches tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
spec_version=$(grep "Version:" ${{ matrix.props.spec }} | tr -s ' ' | cut -d' ' -f2)
tag="${{ steps.tag_name.outputs.VERSION }}"
tag_version="${tag#v}"
echo "Got version $tag_version from git tag $tag"
if [[ "$tag_version" == *-rc* ]] && [[ "$spec_version" != *~rc* ]]; then
echo "The spec version ($spec_version) prerelease tag does not agree with git ($tag_version)"
exit 1
fi
normalized_spec_version=$(echo "$spec_version" | tr "~" "-")
if [[ ! "$tag_version" == "$normalized_spec_version" ]]; then
echo "The spec version ($normalized_spec_version) does not agree with git ($tag_version)"
exit 2
fi
echo "The spec version $spec_version is correct based on git tag $tag"
- name: Patch spec with prerelease version
if: endsWith(github.ref, '/master')
run: |
spec_version=$(grep "Version:" ${{ matrix.props.spec }} | tr -s ' ' | cut -d' ' -f2)
commit_number=$(git rev-list HEAD --count)
patched_version="$spec_version~dev${commit_number}"
sed -i "s#Version:\s*${spec_version}#Version: ${patched_version}#" ${{ matrix.props.spec }}
grep Version ${{ matrix.props.spec }}
- name: Patch spec with pull request version
if: github.event_name == 'pull_request'
run: |
spec_version=$(grep "Version:" ${{ matrix.props.spec }} | tr -s ' ' | cut -d' ' -f2)
pr_number=${{ github.event.pull_request.number }}
patched_version="0.0.${pr_number}"
sed -i "s#Version:\s*${spec_version}#Version: ${patched_version}#" ${{ matrix.props.spec }}
grep Version ${{ matrix.props.spec }}
- name: Install RPM build dependencies
run: |
dnf install -y make rpm rpmdevtools dnf-plugins-core
- name: Install SRPM build dependencies
run: |
make -f .copr/Makefile dnf OS_ID=${{ matrix.props.platform }}
- name: Fetch Source0 tarball
uses: actions/download-artifact@v3
with:
name: source0
path: /tmp/rpmbuild/SOURCES/
- name: Mark as git safe
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
- name: Generate doc tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo "${{ steps.tag_name.outputs.VERSION }}" > help/version
cat help/version
- name: Build SRPM
run: |
make -f .copr/Makefile \
vendor build export \
outdir=/tmp/archives \
spec=${{ matrix.props.spec }} \
OS_ID=${{ matrix.props.platform }}
- name: Export common tarballs
run: |
mkdir -p /tmp/archives
mv vendor-docs-*.tar.gz /tmp/archives
env:
PLATFORM: ${{ matrix.props.dist }}
- name: Export el tarballs
if: startsWith(matrix.props.dist, 'el')
run: |
version=$(grep "Version:" ${{ matrix.props.spec }} | tr -s ' ' | cut -d' ' -f2)
mv vendor-rs-${version}.tar.gz /tmp/archives/
- name: Upload SourceX
uses: actions/upload-artifact@v3
with:
name: tarball-artifacts
path: |
/tmp/archives/*.tar.gz
- name: Upload SRPMs
uses: actions/upload-artifact@v3
with:
name: srpm-artifacts
path: |
/tmp/archives/*.src.rpm
- name: Checksum artifacts
run: |
sha256sum /tmp/archives/* || true
copr:
needs: [ config, srpm ]
name: Copr Build ${{ matrix.props.dist }}
if: needs.config.outputs.is-copr-enabled == 'true'
container: 'rockylinux:8.6'
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJson(needs.config.outputs.matrix) }}
steps:
- name: Install Copr CLI
run: |
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install -y copr-cli
- name: Download srpm artifacts
uses: actions/download-artifact@v3
with:
name: srpm-artifacts
path: /tmp/
- name: Checksum artifacts
run: |
sha256sum /tmp/*.src.rpm
- name: Install Config
run: |
mkdir -p $HOME/.config
echo "[copr-cli]" > $HOME/.config/copr
echo "username = ${COPR_USER}" >> $HOME/.config/copr
echo "login = ${COPR_LOGIN}" >> $HOME/.config/copr
echo "token = ${COPR_TOKEN}" >> $HOME/.config/copr
echo "copr_url = https://copr.fedorainfracloud.org" >> $HOME/.config/copr
env:
COPR_USER: ${{ secrets.COPR_API_USER }}
COPR_LOGIN: ${{ secrets.COPR_API_LOGIN }}
COPR_TOKEN: ${{ secrets.COPR_API_TOKEN }}
- name: build
run: |
copr-cli build --chroot ${{ matrix.props.chroot }} fapolicy-analyzer /tmp/fapolicy-analyzer-*.${{ matrix.props.dist }}.src.rpm
rpm:
needs: [ config, srpm ]
name: Rebuild ${{ matrix.props.dist }}
container: ${{ matrix.props.image }}
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJson(needs.config.outputs.matrix )}}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Download srpm artifacts
uses: actions/download-artifact@v3
with:
name: srpm-artifacts
path: /tmp/src/
- name: Checksum artifacts
run: |
sha256sum /tmp/src/*
- name: Enable EPEL
if: startsWith(matrix.props.dist, 'el')
run: |
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-${{ matrix.props.version }}.noarch.rpm
- name: Install RPM build dependencies
run: |
dnf install -y make rpm rpmdevtools dnf-plugins-core
- name: Rebuild SRPM
run: |
dnf builddep -y ${{ matrix.props.spec }}
rpmbuild --rebuild /tmp/src/fapolicy-analyzer-*.${{ matrix.props.dist }}.src.rpm
- name: Export RPMs
run: |
mkdir -p /tmp/archives
ls | grep -v debug | xargs mv -t /tmp/archives
working-directory: /github/home/rpmbuild/RPMS/x86_64
- name: Upload RPMs
uses: actions/upload-artifact@v3
with:
name: rpm-artifacts
path: |
/tmp/archives/*.x86_64.rpm
install:
needs: [ config, srpm, rpm ]
name: Install ${{ matrix.props.dist }}
container: ${{ matrix.props.image }}
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJson(needs.config.outputs.matrix )}}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Download rpm artifacts
uses: actions/download-artifact@v3
with:
name: rpm-artifacts
path: /tmp/src/
- name: Checksum artifacts
run: |
sha256sum /tmp/src/*
- name: Enable EPEL
if: startsWith(matrix.props.dist, 'el')
run: |
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-${{ matrix.props.version }}.noarch.rpm
- name: Install RPM
run: |
dnf install -y /tmp/src/fapolicy-analyzer-*.${{ matrix.props.dist }}.x86_64.rpm
- name: Check RPM
run: |
rpm -qa --dump fapolicy-analyzer
rpm -q fapolicy-analyzer
publish:
needs: [ srpm, rpm, install, copr ]
name: Publish
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: /tmp/archives/
- name: Release artifacts
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.tag_name.outputs.VERSION }}
prerelease: ${{ startsWith(github.ref, 'refs/tags/v0') || contains(github.ref, 'rc') }}
draft: true
files: |
fapolicy-analyzer.spec
/tmp/archives/source0/*.tar.gz
/tmp/archives/rpm-artifacts/*.rpm
/tmp/archives/srpm-artifacts/*.src.rpm
/tmp/archives/tarball-artifacts/*.tar.gz