mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-04-07 20:35:27 +02:00
feat(ci): move to github actions (#4134)
This commit is contained in:
parent
a869dd7380
commit
d3085b55e4
33
.github/actions/deb-delivery/action.yml
vendored
33
.github/actions/deb-delivery/action.yml
vendored
@ -4,9 +4,6 @@ inputs:
|
||||
distrib:
|
||||
description: "The distribution used for packaging"
|
||||
required: true
|
||||
major_version:
|
||||
description: "The major version"
|
||||
required: true
|
||||
artifactory_username:
|
||||
description: The artifactory username
|
||||
required: true
|
||||
@ -37,28 +34,14 @@ runs:
|
||||
|
||||
- name: Publish DEBS to Nexus
|
||||
run: |
|
||||
set -e
|
||||
FILES="centreon-plugin-operatingsystems-linux-*.deb"
|
||||
for MAJOR in "22.04" "22.10"; do
|
||||
echo "Delivering to $MAJOR ${{ inputs.stability }}"
|
||||
|
||||
VERSION="${{ inputs.version }}"
|
||||
RELEASE="${{ inputs.release }}"
|
||||
REPOTYPE="${{ inputs.stability }}"
|
||||
PROJECT="plugins"
|
||||
PROJECT_PATH="standard"
|
||||
FOLDER_SUFFIX="-${{ inputs.stability }}"
|
||||
if [[ "${{ inputs.stability }}" == "stable" ]]; then
|
||||
FOLDER_SUFFIX=""
|
||||
fi
|
||||
|
||||
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/
|
||||
|
||||
#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
|
||||
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
|
||||
shell: bash
|
||||
|
10
.github/actions/package/action.yml
vendored
10
.github/actions/package/action.yml
vendored
@ -5,7 +5,7 @@ inputs:
|
||||
description: The package extension (deb or rpm)
|
||||
required: true
|
||||
image_name:
|
||||
description: The action matrix
|
||||
description: The docker image name
|
||||
required: true
|
||||
script_name:
|
||||
description: The packaging script name
|
||||
@ -35,7 +35,6 @@ runs:
|
||||
using: composite
|
||||
|
||||
steps:
|
||||
|
||||
- name: Login to Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
@ -63,6 +62,13 @@ runs:
|
||||
artifactory_username: ${{ inputs.artifactory_username }}
|
||||
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
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
|
6
.github/actions/rpm-delivery/action.yml
vendored
6
.github/actions/rpm-delivery/action.yml
vendored
@ -83,9 +83,9 @@ runs:
|
||||
scp -o StrictHostKeyChecking=no ./*.rpm "${{ inputs.yum_repo_address }}:$TARGET"
|
||||
|
||||
# Cleanup is done on unstable repository only
|
||||
if [ "$REPOTYPE" == "unstable" ]; then
|
||||
ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" "ls -drc $PROJECT_LOCATION/* 2>&- | head -n -1 | xargs rm -rf"
|
||||
fi
|
||||
#if [ "$REPOTYPE" == "unstable" ]; then
|
||||
# ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" "ls -drc $PROJECT_LOCATION/* 2>&- | head -n -1 | xargs rm -rf"
|
||||
#fi
|
||||
|
||||
# Update repository metadata
|
||||
METADATAS="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH"
|
||||
|
11
.github/scripts/create-spec-file.py
vendored
11
.github/scripts/create-spec-file.py
vendored
@ -3,17 +3,18 @@
|
||||
import json
|
||||
from sys import argv
|
||||
|
||||
package_name = argv[1]
|
||||
package_version = argv[2]
|
||||
package_release = argv[3]
|
||||
package_path = argv[1]
|
||||
package_name = argv[2]
|
||||
package_version = argv[3]
|
||||
package_release = argv[4]
|
||||
|
||||
with open('.github/packaging/rpm/plugin.spectemplate', 'r') as rfile:
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
specfile = specfile.replace('@NAME@', package_name)
|
||||
|
12
.github/scripts/plugin-packaging-deb.sh
vendored
12
.github/scripts/plugin-packaging-deb.sh
vendored
@ -14,9 +14,13 @@ mv centreon-plugins/debian/control.head.template centreon-plugins/debian/control
|
||||
|
||||
for PLUGIN in $PLUGINS; do
|
||||
|
||||
if [[ "$PLUGIN" =~ (.*)"=>".* ]]; then
|
||||
PLUGIN=$(echo ${BASH_REMATCH[1]})
|
||||
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"
|
||||
@ -25,10 +29,10 @@ for PLUGIN in $PLUGINS; do
|
||||
cp -R build/$PLUGIN/*.pl centreon-plugins/plugins/$PLUGIN
|
||||
|
||||
# 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]}")
|
||||
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
|
||||
|
||||
|
11
.github/scripts/plugin-packaging-rpm.sh
vendored
11
.github/scripts/plugin-packaging-rpm.sh
vendored
@ -7,14 +7,18 @@ RELEASE="$2"
|
||||
PLUGINS="$3"
|
||||
|
||||
for PLUGIN_NAME in $PLUGINS; do
|
||||
echo "::group::Packaging $PLUGIN_NAME"
|
||||
|
||||
if [[ "$PLUGIN_NAME" =~ (.*)"=>".* ]]; then
|
||||
PLUGIN_NAME=$(echo ${BASH_REMATCH[1]})
|
||||
PACKAGE_PATH=$PLUGIN_NAME
|
||||
|
||||
if [[ "$PLUGIN_NAME" =~ (.+)"=>"(.+) ]]; then
|
||||
PACKAGE_PATH=$(echo ${BASH_REMATCH[1]})
|
||||
PLUGIN_NAME=$(echo ${BASH_REMATCH[2]})
|
||||
fi
|
||||
|
||||
# Process 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}
|
||||
mkdir -p $HOME/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
|
||||
@ -29,4 +33,5 @@ for PLUGIN_NAME in $PLUGINS; do
|
||||
|
||||
cd -
|
||||
|
||||
echo "::endgroup::"
|
||||
done
|
||||
|
16
.github/scripts/plugins-source.container.pl
vendored
16
.github/scripts/plugins-source.container.pl
vendored
@ -44,17 +44,19 @@ foreach my $plugin (@plugins) {
|
||||
chdir($packaging_dir);
|
||||
|
||||
# Load plugin configuration file.
|
||||
if (! -f $plugin . '/pkg.json') {
|
||||
if ($plugin =~ /(.*)=>/) {
|
||||
$plugin = $1;
|
||||
my $package_path = $plugin;
|
||||
if (! -f $package_path . '/pkg.json') {
|
||||
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;
|
||||
File::Path::make_path($plugin_build_dir);
|
||||
|
||||
open($fh, '<', $plugin . '/pkg.json');
|
||||
open($fh, '<', $package_path . '/pkg.json');
|
||||
my $json_content = do { local $/; <$fh> };
|
||||
close($fh);
|
||||
$config = JSON::decode_json($json_content);
|
||||
@ -89,7 +91,6 @@ foreach my $plugin (@plugins) {
|
||||
'centreon/plugins/templates/hardware.pm'
|
||||
);
|
||||
foreach my $file ((@common_files, @{$config->{files}})) {
|
||||
print " - $file\n";
|
||||
if (-f $file) {
|
||||
File::Copy::Recursive::fcopy($file, 'lib/' . $file);
|
||||
} elsif (-d $file) {
|
||||
@ -107,5 +108,4 @@ foreach my $plugin (@plugins) {
|
||||
close($fh);
|
||||
chmod 0755, "$plugin_build_dir/$config->{plugin_name}"; # Add execution permission
|
||||
}
|
||||
print "::endgroup::";
|
||||
}
|
||||
|
78
.github/scripts/process-plugins.py
vendored
78
.github/scripts/process-plugins.py
vendored
@ -6,47 +6,51 @@ import os
|
||||
import json
|
||||
|
||||
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()
|
||||
|
||||
if not common:
|
||||
for plugin in plugins.split(' '):
|
||||
try:
|
||||
found = re.search('(.*)\/mode\/.*', plugin).group(1)
|
||||
list_plugins_dir.add(found)
|
||||
except AttributeError:
|
||||
try:
|
||||
found = re.search('(.*)\/plugin.pm', plugin).group(1)
|
||||
list_plugins_dir.add(found)
|
||||
except AttributeError:
|
||||
pass
|
||||
updated_packages = packages.split(' ')
|
||||
for plugin in plugins:
|
||||
list_plugins.add(plugin)
|
||||
try:
|
||||
found = re.search('(.*)\/(?:plugin\.pm|mode\/.+)', plugin).group(1)
|
||||
list_plugins.add(found)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
for filepath in os.popen('find packaging -type f -name pkg.json').read().split('\n')[0:-1]:
|
||||
packaging_file = open(filepath)
|
||||
packaging = json.load(packaging_file)
|
||||
packaging_file.close()
|
||||
packaging_path = re.search('.*\/(centreon-plugin-.*)\/pkg.json', filepath).group(1)
|
||||
if not packaging_path == packaging["pkg_name"]:
|
||||
packaging_path = packaging_path + "=>" + packaging["pkg_name"]
|
||||
if common or filepath in updated_packages:
|
||||
list_packages.add(packaging_path)
|
||||
else:
|
||||
for pkg_file in packaging["files"]:
|
||||
pkg_file_dir = pkg_file
|
||||
try:
|
||||
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)
|
||||
packaging_file = open(filepath)
|
||||
packaging = json.load(packaging_file)
|
||||
packaging_file.close()
|
||||
packaging_path = re.search('.*\/(centreon-plugin-.*)\/pkg.json', filepath).group(1)
|
||||
|
||||
if not packaging_path == packaging["pkg_name"]:
|
||||
packaging_path = packaging_path + "=>" + packaging["pkg_name"]
|
||||
|
||||
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)
|
||||
else:
|
||||
for pkg_file in packaging["files"]:
|
||||
pkg_file_dir = pkg_file.strip('/').removeprefix('centreon-plugins/')
|
||||
if pkg_file_dir in list_plugins:
|
||||
list_packages.add(packaging_path)
|
||||
|
||||
print(*list_packages)
|
||||
|
@ -6,16 +6,16 @@ concurrency:
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
# push:
|
||||
# branches:
|
||||
# - develop
|
||||
# paths:
|
||||
# - ".github/workflows/docker-builder-packaging-plugins.yml"
|
||||
# - ".github/docker/*"
|
||||
# pull_request:
|
||||
# paths:
|
||||
# - ".github/workflows/docker-builder-packaging-plugins.yml"
|
||||
# - ".github/docker/*"
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
paths:
|
||||
- ".github/workflows/docker-builder-packaging-plugins.yml"
|
||||
- ".github/docker/*"
|
||||
pull_request:
|
||||
paths:
|
||||
- ".github/workflows/docker-builder-packaging-plugins.yml"
|
||||
- ".github/docker/*"
|
||||
|
||||
jobs:
|
||||
create-and-push-docker:
|
||||
|
7
.github/workflows/get-environment.yml
vendored
7
.github/workflows/get-environment.yml
vendored
@ -13,15 +13,13 @@ on:
|
||||
|
||||
jobs:
|
||||
get-version:
|
||||
runs-on: [self-hosted, common]
|
||||
runs-on: ubuntu-22.04
|
||||
outputs:
|
||||
stability: ${{ steps.get_environment.outputs.stability }}
|
||||
version: ${{ steps.get_environment.outputs.version }}
|
||||
release: ${{ steps.get_environment.outputs.release }}
|
||||
|
||||
steps:
|
||||
#- uses: actions/checkout@v3
|
||||
|
||||
- id: get_environment
|
||||
run: |
|
||||
case "$BRANCHNAME" in
|
||||
@ -39,9 +37,6 @@ jobs:
|
||||
;;
|
||||
esac
|
||||
|
||||
# @todo remove next line
|
||||
STABILITY="unstable"
|
||||
|
||||
echo "stability=$STABILITY" >> $GITHUB_OUTPUT
|
||||
|
||||
VERSION=`date '+%Y%m%d'`
|
||||
|
5
.github/workflows/plugin-delivery.yml
vendored
5
.github/workflows/plugin-delivery.yml
vendored
@ -59,9 +59,7 @@ jobs:
|
||||
runs-on: [self-hosted, common]
|
||||
strategy:
|
||||
matrix:
|
||||
major_version: ["22.04", "22.10"]
|
||||
include:
|
||||
- distrib: bullseye
|
||||
distrib: [bullseye]
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
@ -71,7 +69,6 @@ jobs:
|
||||
uses: ./.github/actions/deb-delivery
|
||||
with:
|
||||
distrib: ${{ matrix.distrib }}
|
||||
major_version: ${{ matrix.major_version }}
|
||||
version: ${{ inputs.version }}
|
||||
release: ${{ inputs.release }}
|
||||
artifactory_username: ${{ secrets.artifactory_username }}
|
||||
|
25
.github/workflows/plugins.yml
vendored
25
.github/workflows/plugins.yml
vendored
@ -47,16 +47,11 @@ jobs:
|
||||
list-files: shell
|
||||
filters: |
|
||||
common:
|
||||
- added|deleted|modified:
|
||||
- 'centreon-plugins/centreon/**'
|
||||
- 'packaging/rpm/**'
|
||||
- 'packaging/debian/**'
|
||||
- added|deleted|modified: centreon-plugins/centreon/**
|
||||
packages:
|
||||
- added|modified:
|
||||
- 'packaging/centreon-**'
|
||||
- added|modified: packaging/**
|
||||
plugins:
|
||||
- added|modified:
|
||||
- 'centreon-plugins/**'
|
||||
- added|modified: centreon-plugins/**
|
||||
|
||||
- name: transform to directories
|
||||
id: transform
|
||||
@ -70,14 +65,14 @@ jobs:
|
||||
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
|
||||
|
||||
folders=()
|
||||
files=()
|
||||
for f in ${{ steps.filter.outputs.plugins_files }}; \
|
||||
do \
|
||||
echo "Adding $(dirname $f) to folders"; \
|
||||
folders+=($(dirname $f)); \
|
||||
echo "Adding $f to files"; \
|
||||
files+=($f); \
|
||||
done
|
||||
unique_folders=($(printf "%s\n" "${folders[@]}" | sort -u | tr '\n' ' '))
|
||||
echo "plugin_directories=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${unique_folders[@]})" >> $GITHUB_OUTPUT
|
||||
unique_files=($(printf "%s\n" "${files[@]}" | sort -u | tr '\n' ' '))
|
||||
echo "plugins=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${unique_files[@]})" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Get plugins for build
|
||||
id: get_plugins
|
||||
@ -86,9 +81,11 @@ jobs:
|
||||
PLUGINS="$(python3 .github/scripts/process-plugins.py \
|
||||
'${{ steps.filter.outputs.common == 'true' }}' \
|
||||
'${{ steps.transform.outputs.package_directories }}' \
|
||||
'${{ steps.filter.outputs.plugin_directories }}' \
|
||||
'${{ steps.transform.outputs.plugins }}' \
|
||||
)"
|
||||
|
||||
echo "plugins=$(echo $PLUGINS)" >> $GITHUB_OUTPUT
|
||||
|
||||
if [ "$PLUGINS" == '' ]; then
|
||||
echo "::notice::There are no modifications to the plugins packages"
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user