-
Notifications
You must be signed in to change notification settings - Fork 275
428 lines (376 loc) · 16 KB
/
plugins.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
name: plugins
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
on:
workflow_dispatch:
pull_request:
paths:
- '.github/workflows/plugins.yml'
- '.github/scripts/plugins-source.container.pl'
- '.github/packaging/centreon-plugin.yaml.template'
- 'src/**'
- 'packaging/**'
push:
branches:
- develop
- master
paths:
- '.github/workflows/plugins.yml'
- '.github/scripts/plugins-source.container.pl'
- '.github/packaging/centreon-plugin.yaml.template'
- 'src/**'
- 'packaging/**'
jobs:
get-environment:
uses: ./.github/workflows/get-environment.yml
get-plugins:
runs-on: ubuntu-22.04
outputs:
plugins: ${{ steps.get_plugins.outputs.plugins }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
with:
python-version: '3.9'
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
base: ${{ github.ref }}
list-files: shell
filters: |
common:
- added|deleted|modified: src/centreon/**
- modified: .github/packaging/centreon-plugin.yaml.template
packages:
- added|modified: packaging/**
plugins:
- added|modified: src/**
- name: transform to directories
run: |
folders=()
for f in ${{ steps.filter.outputs.packages_files }}; do
echo "Adding $(dirname $f) to folders"
folders+=($(dirname $f))
done
unique_folders=($(printf "%s\n" "${folders[@]}" | sort -u | tr '\n' ' '))
jq --compact-output --null-input '$ARGS.positional' --args -- ${unique_folders[@]} > package_directories.txt
files=()
for f in ${{ steps.filter.outputs.plugins_files }}; do
echo "Adding $f to files"
files+=($f)
done
unique_files=($(printf "%s\n" "${files[@]}" | sort -u | tr '\n' ' '))
jq --compact-output --null-input '$ARGS.positional' --args -- ${unique_files[@]} > plugins.txt
shell: bash
- name: Get plugins for build
id: get_plugins
if: ${{ steps.filter.outputs.common == 'true' || steps.filter.outputs.packages == 'true' || steps.filter.outputs.plugins == 'true' }}
run: |
PLUGINS="$(python3 .github/scripts/process-plugins.py '${{ steps.filter.outputs.common == 'true' }}')"
echo "plugins=$(echo $PLUGINS)" >> $GITHUB_OUTPUT
if [ "$PLUGINS" == '' ]; then
echo "::notice::There are no modifications to the plugins packages"
fi
shell: bash
unit-tests:
needs: [get-environment, get-plugins]
strategy:
fail-fast: false
matrix:
image: [unit-tests-alma8, unit-tests-alma9, unit-tests-bullseye, unit-tests-bullseye-arm64, unit-tests-bookworm, unit-tests-jammy]
include:
- runner_name: ubuntu-22.04
- package_extension: rpm
image: unit-tests-alma8
distrib: el8
- package_extension: rpm
image: unit-tests-alma9
distrib: el9
- package_extension: deb
image: unit-tests-bullseye
distrib: bullseye
- package_extension: deb
image: unit-tests-bullseye-arm64
runner_name: ["self-hosted", "collect-arm64"]
distrib: bullseye
- package_extension: deb
image: unit-tests-bookworm
distrib: bookworm
- package_extension: deb
image: unit-tests-jammy
distrib: jammy
runs-on: ${{ matrix.runner_name }}
container:
image: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/${{ matrix.image }}
credentials:
username: ${{ secrets.HARBOR_CENTREON_PULL_USERNAME }}
password: ${{ secrets.HARBOR_CENTREON_PULL_TOKEN }}
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Run unit tests
uses: ./.github/actions/unit-tests
- name: Upload logs as artifacts if tests failed
if: failure()
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: plugin-installation-${{ matrix.distrib }}
path: ./lastlog.jsonl
retention-days: 1
fatpacker:
if: ${{ needs.get-plugins.outputs.plugins != '' }}
needs: [get-environment, get-plugins, unit-tests]
runs-on: ubuntu-22.04
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 1
- name: Prepare FatPacker
uses: shogo82148/actions-setup-perl@9c1eca9952ccc07f9ca4a2097b63df93d9d138e9 # v1.31.3
with:
perl-version: '5.34'
install-modules-with: cpm
install-modules: App::FatPacker File::Copy::Recursive JSON
- name: Run FatPacker
run: |
COMMIT=$(git log -1 HEAD --pretty=format:%h)
perl .github/scripts/plugins-source.container.pl "${{ needs.get-plugins.outputs.plugins }}" "${{ needs.get-environment.outputs.version }} ($COMMIT)"
- uses: actions/cache/save@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ./build/
key: fatpacked-plugins-${{ github.sha }}-${{ github.run_id }}
package:
runs-on: ubuntu-24.04
needs: [get-environment, get-plugins, fatpacker]
strategy:
fail-fast: false
matrix:
include:
- package_extension: rpm
image: packaging-plugins-alma8
distrib: el7
- package_extension: rpm
image: packaging-plugins-alma8
distrib: el8
- package_extension: rpm
image: packaging-plugins-alma9
distrib: el9
- package_extension: deb
image: packaging-plugins-bullseye
distrib: bullseye
- package_extension: deb
image: packaging-plugins-bookworm
distrib: bookworm
- package_extension: deb
image: packaging-plugins-jammy
distrib: jammy
container:
image: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/${{ matrix.image }}
credentials:
username: ${{ secrets.HARBOR_CENTREON_PULL_USERNAME }}
password: ${{ secrets.HARBOR_CENTREON_PULL_TOKEN }}
name: "package ${{ matrix.distrib }}"
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ./build/
key: fatpacked-plugins-${{ github.sha }}-${{ github.run_id }}
fail-on-cache-miss: true
- run: |
PLUGINS="${{ needs.get-plugins.outputs.plugins }}"
for PLUGIN in $PLUGINS; do
PACKAGE_PATH=$PLUGIN
if [[ "$PLUGIN" =~ (.+)"=>"(.+) ]]; then
PACKAGE_PATH=$(echo ${BASH_REMATCH[1]})
PLUGIN=$(echo ${BASH_REMATCH[2]})
fi
PLUGIN_NAME_LOWER=$(echo "$PLUGIN" | tr '[:upper:]' '[:lower:]')
echo "::group::Preparing $PLUGIN_NAME_LOWER"
# Process package files
pkg_values=($(cat "packaging/$PACKAGE_PATH/pkg.json" | jq -r '.pkg_name,.plugin_name'))
pkg_summary=$(echo "${pkg_values[0]}")
plugin_name=$(echo "${pkg_values[1]}")
conflicts=$(cat "packaging/$PACKAGE_PATH/pkg.json" | jq -r '.conflicts // [] | join(",")')
replaces=$(cat "packaging/$PACKAGE_PATH/pkg.json" | jq -r '.replaces // [] | join(",")')
provides=$(cat "packaging/$PACKAGE_PATH/pkg.json" | jq -r '.provides // [] | join(",")')
deb_dependencies=$(cat "packaging/$PACKAGE_PATH/deb.json" | jq -r '.dependencies // [] | join(",")')
deb_conflicts=$(cat "packaging/$PACKAGE_PATH/deb.json" | jq -r '.conflicts // [] | join(",")')
deb_replaces=$(cat "packaging/$PACKAGE_PATH/deb.json" | jq -r '.replaces // [] | join(",")')
deb_provides=$(cat "packaging/$PACKAGE_PATH/deb.json" | jq -r '.provides // [] | join(",")')
rpm_dependencies=$(cat "packaging/$PACKAGE_PATH/rpm.json" | jq -r '.dependencies // [] | join(",")')
rpm_conflicts=$(cat "packaging/$PACKAGE_PATH/rpm.json" | jq -r '.conflicts // [] | join(",")')
rpm_replaces=$(cat "packaging/$PACKAGE_PATH/rpm.json" | jq -r '.replaces // [] | join(",")')
rpm_provides=$(cat "packaging/$PACKAGE_PATH/rpm.json" | jq -r '.provides // [] | join(",")')
sed -e "s/@PLUGIN_NAME@/$PLUGIN/g;" \
-e "s/@SUMMARY@/$pkg_summary/g" \
-e "s/@CONFLICTS@/$conflicts/g" \
-e "s/@REPLACES@/$replaces/g" \
-e "s/@PROVIDES@/$provides/g" \
-e "s/@DEB_DEPENDENCIES@/$deb_dependencies/g" \
-e "s/@DEB_CONFLICTS@/$deb_conflicts/g" \
-e "s/@DEB_REPLACES@/$deb_replaces/g" \
-e "s/@DEB_PROVIDES@/$deb_provides/g" \
-e "s/@RPM_DEPENDENCIES@/$rpm_dependencies/g" \
-e "s/@RPM_CONFLICTS@/$rpm_conflicts/g" \
-e "s/@RPM_REPLACES@/$rpm_replaces/g" \
-e "s/@RPM_PROVIDES@/$rpm_provides/g" \
< .github/packaging/centreon-plugin.yaml.template \
>> .github/packaging/$PLUGIN.yaml
if [ "${{ matrix.package_extension }}" = "rpm" ]; then
sed -i "s/@PACKAGE_NAME@/$PLUGIN/g" \
.github/packaging/$PLUGIN.yaml
else
sed -i "s/@PACKAGE_NAME@/$PLUGIN_NAME_LOWER/g" \
.github/packaging/$PLUGIN.yaml
fi
cat .github/packaging/$PLUGIN.yaml
echo "::endgroup::"
done
shell: bash
- uses: ./.github/actions/package-nfpm
with:
nfpm_file_pattern: ".github/packaging/*.yaml"
distrib: ${{ matrix.distrib }}
package_extension: ${{ matrix.package_extension }}
version: ${{ needs.get-environment.outputs.version }}
release: ${{ needs.get-environment.outputs.release }}
commit_hash: ${{ github.sha }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}
rpm_gpg_key: ${{ secrets.RPM_GPG_SIGNING_KEY }}
rpm_gpg_signing_key_id: ${{ secrets.RPM_GPG_SIGNING_KEY_ID }}
rpm_gpg_signing_passphrase: ${{ secrets.RPM_GPG_SIGNING_PASSPHRASE }}
stability: ${{ needs.get-environment.outputs.stability }}
test-plugins:
needs: [get-environment, get-plugins, package]
strategy:
fail-fast: false
matrix:
image: [testing-plugins-alma8, testing-plugins-alma9, testing-plugins-jammy, testing-plugins-bullseye, testing-plugins-bookworm]
include:
- runner_name: ubuntu-24.04
- package_extension: rpm
image: testing-plugins-alma8
distrib: el8
- package_extension: rpm
image: testing-plugins-alma9
distrib: el9
- package_extension: deb
image: testing-plugins-bullseye
distrib: bullseye
- package_extension: deb
image: testing-plugins-bookworm
distrib: bookworm
- package_extension: deb
image: testing-plugins-jammy
distrib: jammy
- package_extension: deb
image: testing-plugins-bullseye-arm64
distrib: bullseye
arch: arm64
runner_name: ["self-hosted", "collect-arm64"]
runs-on: ${{ matrix.runner_name }}
container:
image: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/${{ matrix.image }}
credentials:
username: ${{ secrets.HARBOR_CENTREON_PULL_USERNAME }}
password: ${{ secrets.HARBOR_CENTREON_PULL_TOKEN }}
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: ./.github/actions/test-plugins
with:
cache-key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}
package-extension: ${{ matrix.package_extension }}
plugin-list: ${{ needs.get-plugins.outputs.plugins }}
- name: Upload apt/dnf logs as artifacts if tests failed
if: failure()
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: plugin-installation-${{ matrix.distrib }}
path: /var/log/robot-plugins-installation-tests.log
retention-days: 1
deliver-packages:
needs: [get-environment, get-plugins, test-plugins]
if: |
needs.get-plugins.outputs.plugins != '' &&
(contains(fromJson('["testing", "unstable"]'), needs.get-environment.outputs.stability) || ( needs.get-environment.outputs.stability == 'stable' && github.event_name != 'workflow_dispatch')) &&
! cancelled() &&
! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled')
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- distrib: el7
package_extension: rpm
- distrib: el8
package_extension: rpm
- distrib: el9
package_extension: rpm
- distrib: bullseye
package_extension: deb
- distrib: bookworm
package_extension: deb
- distrib: jammy
package_extension: deb
name: deliver ${{ matrix.distrib }}
steps:
- name: Checkout sources
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: Delivery
uses: ./.github/actions/package-delivery
with:
module_name: plugins
distrib: ${{ matrix.distrib }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}
stability: ${{ needs.get-environment.outputs.stability }}
release_type: ${{ needs.get-environment.outputs.release_type }}
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
deliver-sources:
needs: [get-environment]
if: ${{ needs.get-environment.outputs.stability == 'stable' && github.event_name == 'push' }}
runs-on: [self-hosted, common]
steps:
- name: Checkout sources
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ./build/
key: fatpacked-plugins-${{ github.sha }}-${{ github.run_id }}
fail-on-cache-miss: true
- name: Deliver sources
uses: ./.github/actions/release-sources
with:
bucket_directory: centreon-plugins
module_directory: build
module_name: centreon-plugins
version: ${{ needs.get-environment.outputs.version }}
release: ${{ needs.get-environment.outputs.release }}
token_download_centreon_com: ${{ secrets.TOKEN_DOWNLOAD_CENTREON_COM }}
release-tag:
needs: [get-environment]
if: ${{ needs.get-environment.outputs.stability == 'stable' && github.event_name == 'push' }}
runs-on: ubuntu-24.04
steps:
- name: Checkout sources
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: Push git release tag
run: |
RELEASE=plugins-$(date '+%Y%m%d')
EXISTING_TAG=$(git tag --list "$RELEASE" | head -n 1)
git config --global user.email "release@centreon.com"
git config --global user.name "Centreon"
if [ -z "$EXISTING_TAG" ]; then
git tag -a "$RELEASE" -m "release $RELEASE"
git push --follow-tags
else
echo "::warning::Release tag $RELEASE already exists"
fi
shell: bash