240 lines
8.8 KiB
YAML
240 lines
8.8 KiB
YAML
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'
|
|
- 'src/**'
|
|
- 'packaging/**'
|
|
push:
|
|
branches:
|
|
- develop
|
|
- master
|
|
paths:
|
|
- '.github/workflows/plugins.yml'
|
|
- '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@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- uses: actions/setup-python@v4
|
|
with:
|
|
python-version: '3.9'
|
|
|
|
- uses: dorny/paths-filter@v2
|
|
id: filter
|
|
with:
|
|
base: ${{ github.ref }}
|
|
list-files: shell
|
|
filters: |
|
|
common:
|
|
- added|deleted|modified: src/centreon/**
|
|
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
|
|
|
|
fatpacker:
|
|
if: ${{ needs.get-plugins.outputs.plugins != '' }}
|
|
needs: [get-environment, get-plugins]
|
|
runs-on: ubuntu-22.04
|
|
steps:
|
|
- name: Checkout sources
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Prepare FatPacker
|
|
uses: shogo82148/actions-setup-perl@v1
|
|
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@v3
|
|
with:
|
|
path: ./build/
|
|
key: fatpacked-plugins-${{ github.sha }}-${{ github.run_id }}
|
|
|
|
package:
|
|
runs-on: ubuntu-22.04
|
|
needs: [get-environment, get-plugins, fatpacker]
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- package_extension: rpm
|
|
image: packaging-plugins-centos7
|
|
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
|
|
|
|
container:
|
|
image: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/${{ matrix.image }}
|
|
credentials:
|
|
username: ${{ secrets.DOCKER_REGISTRY_ID }}
|
|
password: ${{ secrets.DOCKER_REGISTRY_PASSWD }}
|
|
|
|
name: "package ${{ matrix.distrib }}"
|
|
|
|
steps:
|
|
- name: Checkout sources
|
|
if: ${{ matrix.distrib == 'el7' }}
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Checkout sources
|
|
if: ${{ matrix.distrib != 'el7' }}
|
|
uses: actions/checkout@v4
|
|
|
|
- uses: actions/cache/restore@v3
|
|
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
|
|
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 }}
|
|
|
|
deliver:
|
|
needs: [get-environment, package]
|
|
if: ${{ contains(fromJson('["stable", "testing", "unstable"]'), needs.get-environment.outputs.stability) }}
|
|
uses: ./.github/workflows/plugin-delivery.yml
|
|
with:
|
|
version: ${{ needs.get-environment.outputs.version }}
|
|
release: ${{ needs.get-environment.outputs.release }}
|
|
stability: ${{ needs.get-environment.outputs.stability }}
|
|
secrets:
|
|
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
|
|
token_download_centreon_com: ${{ secrets.TOKEN_DOWNLOAD_CENTREON_COM }}
|