-
Notifications
You must be signed in to change notification settings - Fork 5
248 lines (210 loc) · 7.91 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
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 \
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: Checksum artifacts
run: |
sha256sum /tmp/archives/* || true
publish:
needs: [ srpm ]
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