feat(ci): move to github actions (#4134)

This commit is contained in:
Kevin Duret 2023-01-17 11:47:42 +01:00 committed by GitHub
parent a869dd7380
commit d3085b55e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 113 additions and 121 deletions

View File

@ -4,9 +4,6 @@ inputs:
distrib: distrib:
description: "The distribution used for packaging" description: "The distribution used for packaging"
required: true required: true
major_version:
description: "The major version"
required: true
artifactory_username: artifactory_username:
description: The artifactory username description: The artifactory username
required: true required: true
@ -37,28 +34,14 @@ runs:
- name: Publish DEBS to Nexus - name: Publish DEBS to Nexus
run: | run: |
set -e for MAJOR in "22.04" "22.10"; do
FILES="centreon-plugin-operatingsystems-linux-*.deb" echo "Delivering to $MAJOR ${{ inputs.stability }}"
VERSION="${{ inputs.version }}" FOLDER_SUFFIX="-${{ inputs.stability }}"
RELEASE="${{ inputs.release }}" if [[ "${{ inputs.stability }}" == "stable" ]]; then
REPOTYPE="${{ inputs.stability }}" FOLDER_SUFFIX=""
PROJECT="plugins" fi
PROJECT_PATH="standard"
find -name "*.deb" -print0 | xargs -0 -t -I % -P 2 curl -u "${{ inputs.artifactory_username }}":"${{ inputs.artifactory_password }}" -H "Content-Type: multipart/form-data" --data-binary "@%" https://apt.centreon.com/repository/${{ inputs.major_version }}-$REPOTYPE/ find -name "*.deb" -print0 | xargs -0 -t -I % -P 2 curl -u "${{ inputs.artifactory_username }}":"${{ inputs.artifactory_password }}" -H "Content-Type: multipart/form-data" --data-binary "@%" https://apt.centreon.com/repository/$MAJOR$FOLDER_SUFFIX/
done
#for MAJOR in "22.04" "22.10"; do
# echo "Delivering to $MAJOR $REPOTYPE"
# find -name "*.deb" -print0 | xargs -0 -t -I % -P 2 curl -u "${{ inputs.artifactory_username }}":"${{ inputs.artifactory_password }}" -H "Content-Type: multipart/form-data" --data-binary "@%" https://apt.centreon.com/repository/$MAJOR-$REPOTYPE/
# for FILE in $FILES; do
# echo "::group::Delivering $FILE"
#curl -v -u "${{ inputs.artifactory_username }}":"${{ inputs.artifactory_password }}" -H "Content-Type: multipart/form-data" --data-binary "@./$FILE" https://apt.centreon.com/repository/$MAJOR-$REPOTYPE/
# echo "::endgroup::"
# done
#done
shell: bash shell: bash

View File

@ -5,7 +5,7 @@ inputs:
description: The package extension (deb or rpm) description: The package extension (deb or rpm)
required: true required: true
image_name: image_name:
description: The action matrix description: The docker image name
required: true required: true
script_name: script_name:
description: The packaging script name description: The packaging script name
@ -35,7 +35,6 @@ runs:
using: composite using: composite
steps: steps:
- name: Login to Registry - name: Login to Registry
uses: docker/login-action@v2 uses: docker/login-action@v2
with: with:
@ -63,6 +62,13 @@ runs:
artifactory_username: ${{ inputs.artifactory_username }} artifactory_username: ${{ inputs.artifactory_username }}
artifactory_password: ${{ inputs.artifactory_password }} artifactory_password: ${{ inputs.artifactory_password }}
- name: Upload package artifacts
uses: actions/upload-artifact@v3
with:
name: packages-${{ inputs.package_extension }}
path: ./*.${{ inputs.package_extension }}
retention-days: 1
- name: Cache packaged files - name: Cache packaged files
uses: actions/cache@v3 uses: actions/cache@v3
with: with:

View File

@ -83,9 +83,9 @@ runs:
scp -o StrictHostKeyChecking=no ./*.rpm "${{ inputs.yum_repo_address }}:$TARGET" scp -o StrictHostKeyChecking=no ./*.rpm "${{ inputs.yum_repo_address }}:$TARGET"
# Cleanup is done on unstable repository only # Cleanup is done on unstable repository only
if [ "$REPOTYPE" == "unstable" ]; then #if [ "$REPOTYPE" == "unstable" ]; then
ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" "ls -drc $PROJECT_LOCATION/* 2>&- | head -n -1 | xargs rm -rf" # ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" "ls -drc $PROJECT_LOCATION/* 2>&- | head -n -1 | xargs rm -rf"
fi #fi
# Update repository metadata # Update repository metadata
METADATAS="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH" METADATAS="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH"

View File

@ -3,17 +3,18 @@
import json import json
from sys import argv from sys import argv
package_name = argv[1] package_path = argv[1]
package_version = argv[2] package_name = argv[2]
package_release = argv[3] package_version = argv[3]
package_release = argv[4]
with open('.github/packaging/rpm/plugin.spectemplate', 'r') as rfile: with open('.github/packaging/rpm/plugin.spectemplate', 'r') as rfile:
specfile = rfile.read() specfile = rfile.read()
with open('packaging/%s/pkg.json' % package_name, 'r') as rfile: with open('packaging/%s/pkg.json' % package_path, 'r') as rfile:
plugincfg = json.load(rfile) plugincfg = json.load(rfile)
with open('packaging/%s/rpm.json' % package_name, 'r') as rfile: with open('packaging/%s/rpm.json' % package_path, 'r') as rfile:
pluginrpm = json.load(rfile) pluginrpm = json.load(rfile)
specfile = specfile.replace('@NAME@', package_name) specfile = specfile.replace('@NAME@', package_name)

View File

@ -14,9 +14,13 @@ mv centreon-plugins/debian/control.head.template centreon-plugins/debian/control
for PLUGIN in $PLUGINS; do for PLUGIN in $PLUGINS; do
if [[ "$PLUGIN" =~ (.*)"=>".* ]]; then PACKAGE_PATH=$PLUGIN
PLUGIN=$(echo ${BASH_REMATCH[1]})
if [[ "$PLUGIN" =~ (.+)"=>"(.+) ]]; then
PACKAGE_PATH=$(echo ${BASH_REMATCH[1]})
PLUGIN=$(echo ${BASH_REMATCH[2]})
fi fi
PLUGIN_NAME_LOWER=$(echo "$PLUGIN" | tr '[:upper:]' '[:lower:]') PLUGIN_NAME_LOWER=$(echo "$PLUGIN" | tr '[:upper:]' '[:lower:]')
echo "::group::Preparing $PLUGIN_NAME_LOWER" echo "::group::Preparing $PLUGIN_NAME_LOWER"
@ -25,10 +29,10 @@ for PLUGIN in $PLUGINS; do
cp -R build/$PLUGIN/*.pl centreon-plugins/plugins/$PLUGIN cp -R build/$PLUGIN/*.pl centreon-plugins/plugins/$PLUGIN
# Process package files # Process package files
pkg_values=($(cat "packaging/$PLUGIN/pkg.json" | jq -r '.pkg_name,.plugin_name')) pkg_values=($(cat "packaging/$PACKAGE_PATH/pkg.json" | jq -r '.pkg_name,.plugin_name'))
pkg_summary=$(echo "${pkg_values[0]}") pkg_summary=$(echo "${pkg_values[0]}")
plugin_name=$(echo "${pkg_values[1]}") plugin_name=$(echo "${pkg_values[1]}")
deb_dependencies=$(cat "packaging/$PLUGIN/deb.json" | jq -r '.dependencies | join(",\\n ")') deb_dependencies=$(cat "packaging/$PACKAGE_PATH/deb.json" | jq -r '.dependencies | join(",\\n ")')
sed -e "s/@NAME@/$PLUGIN_NAME_LOWER/g" -e "s/@SUMMARY@/$pkg_summary/g" -e "s/@REQUIRES@/$deb_dependencies/g" < centreon-plugins/debian/control.body.template >> centreon-plugins/debian/control sed -e "s/@NAME@/$PLUGIN_NAME_LOWER/g" -e "s/@SUMMARY@/$pkg_summary/g" -e "s/@REQUIRES@/$deb_dependencies/g" < centreon-plugins/debian/control.body.template >> centreon-plugins/debian/control

View File

@ -7,14 +7,18 @@ RELEASE="$2"
PLUGINS="$3" PLUGINS="$3"
for PLUGIN_NAME in $PLUGINS; do for PLUGIN_NAME in $PLUGINS; do
echo "::group::Packaging $PLUGIN_NAME"
if [[ "$PLUGIN_NAME" =~ (.*)"=>".* ]]; then PACKAGE_PATH=$PLUGIN_NAME
PLUGIN_NAME=$(echo ${BASH_REMATCH[1]})
if [[ "$PLUGIN_NAME" =~ (.+)"=>"(.+) ]]; then
PACKAGE_PATH=$(echo ${BASH_REMATCH[1]})
PLUGIN_NAME=$(echo ${BASH_REMATCH[2]})
fi fi
# Process specfile # Process specfile
rm -f plugin.specfile rm -f plugin.specfile
python3 .github/scripts/create-spec-file.py "$PLUGIN_NAME" "$VERSION" "$RELEASE" python3 .github/scripts/create-spec-file.py "$PACKAGE_PATH" "$PLUGIN_NAME" "$VERSION" "$RELEASE"
rm -rf $HOME/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} rm -rf $HOME/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
mkdir -p $HOME/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} mkdir -p $HOME/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
@ -29,4 +33,5 @@ for PLUGIN_NAME in $PLUGINS; do
cd - cd -
echo "::endgroup::"
done done

View File

@ -44,17 +44,19 @@ foreach my $plugin (@plugins) {
chdir($packaging_dir); chdir($packaging_dir);
# Load plugin configuration file. # Load plugin configuration file.
if (! -f $plugin . '/pkg.json') { my $package_path = $plugin;
if ($plugin =~ /(.*)=>/) { if (! -f $package_path . '/pkg.json') {
$plugin = $1; if ($package_path =~ /(.+)=>(.+)/) {
$package_path = $1;
$plugin = $2;
} }
} }
print "::group::Processing $plugin...";
if (-f $plugin . '/pkg.json') { if (-f $package_path . '/pkg.json') {
my $plugin_build_dir = $build_dir . '/' . $plugin; my $plugin_build_dir = $build_dir . '/' . $plugin;
File::Path::make_path($plugin_build_dir); File::Path::make_path($plugin_build_dir);
open($fh, '<', $plugin . '/pkg.json'); open($fh, '<', $package_path . '/pkg.json');
my $json_content = do { local $/; <$fh> }; my $json_content = do { local $/; <$fh> };
close($fh); close($fh);
$config = JSON::decode_json($json_content); $config = JSON::decode_json($json_content);
@ -89,7 +91,6 @@ foreach my $plugin (@plugins) {
'centreon/plugins/templates/hardware.pm' 'centreon/plugins/templates/hardware.pm'
); );
foreach my $file ((@common_files, @{$config->{files}})) { foreach my $file ((@common_files, @{$config->{files}})) {
print " - $file\n";
if (-f $file) { if (-f $file) {
File::Copy::Recursive::fcopy($file, 'lib/' . $file); File::Copy::Recursive::fcopy($file, 'lib/' . $file);
} elsif (-d $file) { } elsif (-d $file) {
@ -107,5 +108,4 @@ foreach my $plugin (@plugins) {
close($fh); close($fh);
chmod 0755, "$plugin_build_dir/$config->{plugin_name}"; # Add execution permission chmod 0755, "$plugin_build_dir/$config->{plugin_name}"; # Add execution permission
} }
print "::endgroup::";
} }

View File

@ -6,47 +6,51 @@ import os
import json import json
common = argv[1] == 'true' common = argv[1] == 'true'
packages = argv[2]
plugins = argv[3]
list_plugins_dir = set() n = len(argv[2])
a = argv[2][1:n-1]
input_packages = a.split(',')
packages = set()
for package in input_packages:
packages.add(package.strip('"/').removeprefix('centreon-plugins/'))
n = len(argv[3])
a = argv[3][1:n-1]
input_plugins = a.split(',')
plugins = set()
for plugin in input_plugins:
plugins.add(plugin.strip('"/').removeprefix('centreon-plugins/'))
list_plugins = set()
list_packages = set() list_packages = set()
if not common: for plugin in plugins:
for plugin in plugins.split(' '): list_plugins.add(plugin)
try: try:
found = re.search('(.*)\/mode\/.*', plugin).group(1) found = re.search('(.*)\/(?:plugin\.pm|mode\/.+)', plugin).group(1)
list_plugins_dir.add(found) list_plugins.add(found)
except AttributeError:
try:
found = re.search('(.*)\/plugin.pm', plugin).group(1)
list_plugins_dir.add(found)
except AttributeError: except AttributeError:
pass pass
updated_packages = packages.split(' ')
for filepath in os.popen('find packaging -type f -name pkg.json').read().split('\n')[0:-1]: for filepath in os.popen('find packaging -type f -name pkg.json').read().split('\n')[0:-1]:
packaging_file = open(filepath) packaging_file = open(filepath)
packaging = json.load(packaging_file) packaging = json.load(packaging_file)
packaging_file.close() packaging_file.close()
packaging_path = re.search('.*\/(centreon-plugin-.*)\/pkg.json', filepath).group(1) packaging_path = re.search('.*\/(centreon-plugin-.*)\/pkg.json', filepath).group(1)
if not packaging_path == packaging["pkg_name"]: if not packaging_path == packaging["pkg_name"]:
packaging_path = packaging_path + "=>" + packaging["pkg_name"] packaging_path = packaging_path + "=>" + packaging["pkg_name"]
if common or filepath in updated_packages:
directory_path = re.search('^(.+)\/pkg.json', filepath).group(1)
if common:
list_packages.add(packaging_path)
elif directory_path in packages:
list_packages.add(packaging_path) list_packages.add(packaging_path)
else: else:
for pkg_file in packaging["files"]: for pkg_file in packaging["files"]:
pkg_file_dir = pkg_file pkg_file_dir = pkg_file.strip('/').removeprefix('centreon-plugins/')
try: if pkg_file_dir in list_plugins:
found = re.search('(.*)\/mode\/.*', pkg_file).group(1)
pkg_file_dir = found
except AttributeError:
try:
found = re.search('(.*)\/plugin.pm', pkg_file).group(1)
pkg_file_dir = found
except AttributeError:
pass
if pkg_file_dir in list_plugins_dir:
list_packages.add(packaging_path) list_packages.add(packaging_path)
print(*list_packages) print(*list_packages)

View File

@ -6,16 +6,16 @@ concurrency:
on: on:
workflow_dispatch: workflow_dispatch:
# push: push:
# branches: branches:
# - develop - develop
# paths: paths:
# - ".github/workflows/docker-builder-packaging-plugins.yml" - ".github/workflows/docker-builder-packaging-plugins.yml"
# - ".github/docker/*" - ".github/docker/*"
# pull_request: pull_request:
# paths: paths:
# - ".github/workflows/docker-builder-packaging-plugins.yml" - ".github/workflows/docker-builder-packaging-plugins.yml"
# - ".github/docker/*" - ".github/docker/*"
jobs: jobs:
create-and-push-docker: create-and-push-docker:

View File

@ -13,15 +13,13 @@ on:
jobs: jobs:
get-version: get-version:
runs-on: [self-hosted, common] runs-on: ubuntu-22.04
outputs: outputs:
stability: ${{ steps.get_environment.outputs.stability }} stability: ${{ steps.get_environment.outputs.stability }}
version: ${{ steps.get_environment.outputs.version }} version: ${{ steps.get_environment.outputs.version }}
release: ${{ steps.get_environment.outputs.release }} release: ${{ steps.get_environment.outputs.release }}
steps: steps:
#- uses: actions/checkout@v3
- id: get_environment - id: get_environment
run: | run: |
case "$BRANCHNAME" in case "$BRANCHNAME" in
@ -39,9 +37,6 @@ jobs:
;; ;;
esac esac
# @todo remove next line
STABILITY="unstable"
echo "stability=$STABILITY" >> $GITHUB_OUTPUT echo "stability=$STABILITY" >> $GITHUB_OUTPUT
VERSION=`date '+%Y%m%d'` VERSION=`date '+%Y%m%d'`

View File

@ -59,9 +59,7 @@ jobs:
runs-on: [self-hosted, common] runs-on: [self-hosted, common]
strategy: strategy:
matrix: matrix:
major_version: ["22.04", "22.10"] distrib: [bullseye]
include:
- distrib: bullseye
steps: steps:
- name: Checkout sources - name: Checkout sources
@ -71,7 +69,6 @@ jobs:
uses: ./.github/actions/deb-delivery uses: ./.github/actions/deb-delivery
with: with:
distrib: ${{ matrix.distrib }} distrib: ${{ matrix.distrib }}
major_version: ${{ matrix.major_version }}
version: ${{ inputs.version }} version: ${{ inputs.version }}
release: ${{ inputs.release }} release: ${{ inputs.release }}
artifactory_username: ${{ secrets.artifactory_username }} artifactory_username: ${{ secrets.artifactory_username }}

View File

@ -47,16 +47,11 @@ jobs:
list-files: shell list-files: shell
filters: | filters: |
common: common:
- added|deleted|modified: - added|deleted|modified: centreon-plugins/centreon/**
- 'centreon-plugins/centreon/**'
- 'packaging/rpm/**'
- 'packaging/debian/**'
packages: packages:
- added|modified: - added|modified: packaging/**
- 'packaging/centreon-**'
plugins: plugins:
- added|modified: - added|modified: centreon-plugins/**
- 'centreon-plugins/**'
- name: transform to directories - name: transform to directories
id: transform id: transform
@ -70,14 +65,14 @@ jobs:
unique_folders=($(printf "%s\n" "${folders[@]}" | sort -u | tr '\n' ' ')) unique_folders=($(printf "%s\n" "${folders[@]}" | sort -u | tr '\n' ' '))
echo "package_directories=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${unique_folders[@]})" >> $GITHUB_OUTPUT echo "package_directories=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${unique_folders[@]})" >> $GITHUB_OUTPUT
folders=() files=()
for f in ${{ steps.filter.outputs.plugins_files }}; \ for f in ${{ steps.filter.outputs.plugins_files }}; \
do \ do \
echo "Adding $(dirname $f) to folders"; \ echo "Adding $f to files"; \
folders+=($(dirname $f)); \ files+=($f); \
done done
unique_folders=($(printf "%s\n" "${folders[@]}" | sort -u | tr '\n' ' ')) unique_files=($(printf "%s\n" "${files[@]}" | sort -u | tr '\n' ' '))
echo "plugin_directories=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${unique_folders[@]})" >> $GITHUB_OUTPUT echo "plugins=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${unique_files[@]})" >> $GITHUB_OUTPUT
- name: Get plugins for build - name: Get plugins for build
id: get_plugins id: get_plugins
@ -86,9 +81,11 @@ jobs:
PLUGINS="$(python3 .github/scripts/process-plugins.py \ PLUGINS="$(python3 .github/scripts/process-plugins.py \
'${{ steps.filter.outputs.common == 'true' }}' \ '${{ steps.filter.outputs.common == 'true' }}' \
'${{ steps.transform.outputs.package_directories }}' \ '${{ steps.transform.outputs.package_directories }}' \
'${{ steps.filter.outputs.plugin_directories }}' \ '${{ steps.transform.outputs.plugins }}' \
)" )"
echo "plugins=$(echo $PLUGINS)" >> $GITHUB_OUTPUT echo "plugins=$(echo $PLUGINS)" >> $GITHUB_OUTPUT
if [ "$PLUGINS" == '' ]; then if [ "$PLUGINS" == '' ]; then
echo "::notice::There are no modifications to the plugins packages" echo "::notice::There are no modifications to the plugins packages"
fi fi