Skip to content

Commit

Permalink
split cpan-libraries workflow with "test-cpan-libs" action
Browse files Browse the repository at this point in the history
  • Loading branch information
sdepassio committed Feb 12, 2025
1 parent af0a793 commit 0db4365
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 110 deletions.
125 changes: 125 additions & 0 deletions .github/actions/test-cpan-libs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: "test-cpan-libs"
description: "Test packaged CPAN libraries"
inputs:
package_extension:
description: "The package extension (deb or rpm)"
required: true
distrib:
description: "The distribution name"
required: true
arch:
description: "The architecture (amd64 or arm64)"
required: true

runs:
using: "composite"
steps:

- if: ${{ inputs.package_extension == 'rpm' }}
name: Install zstd, perl and Centreon repositories
run: |
dnf install -y zstd perl epel-release 'dnf-command(config-manager)'
dnf config-manager --set-enabled powertools || true # alma 8
dnf config-manager --set-enabled crb || true # alma 9
# Import Centreon GPG key
GPG_KEY_URL="https://yum-gpg.centreon.com/RPM-GPG-KEY-CES"
curl -sSL $GPG_KEY_URL -o RPM-GPG-KEY-CES
rpm --import RPM-GPG-KEY-CES
shell: bash

- if: ${{ inputs.package_extension == 'deb' }}
name: Install zstd, perl and Centreon repositories
run: |
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y zstd perl wget gpg apt-utils procps
wget -O- https://apt-key.centreon.com | gpg --dearmor | tee /etc/apt/trusted.gpg.d/centreon.gpg > /dev/null 2>&1
# Avoid apt to clean packages cache directory
rm -f /etc/apt/apt.conf.d/docker-clean
apt-get update
shell: bash

- name: Restore packages from cache
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: ./*.${{ inputs.package_extension }}
key: ${{ github.sha }}-${{ github.run_id }}-${{ inputs.package_extension }}-${{ inputs.distrib }}
fail-on-cache-miss: true

- if: ${{ inputs.package_extension == 'rpm' }}
name: Install packages
run: |
error_log="install_error_${{ inputs.distrib }}_${{ inputs.arch }}.log"
for package in ./*.rpm; do
echo "Installing package: $package"
# List dependencies, and remove version and comparison operators
dependencies=$(rpm -qpR $package | sed 's/ [0-9.-]*\(\s\|$\)/ /g' | sed 's/ [<>!=]*\(\s\|$\)/ /g')
for dependency in $dependencies; do
# Skip non-perl dependencies
if [[ $dependency != perl* ]]; then
continue
else
echo "Check dependency: $dependency"
# Update the dependency name to match the package name
dependency=$(echo $dependency | sed 's/(/-/g' | sed 's/)//g' | sed 's/::/-/g')
fi
# If the dependency has been built in the same workflow, install it
if [[ -n $(find . -maxdepth 1 -regex "\.\/$dependency-[0-9v].*\.rpm") ]]; then
echo "Installing dependency: $dependency"
error_output=$(dnf install -y ./$dependency*.rpm 2>&1) || { echo "$error_output" >> $error_log; echo "Error during installation of the dependency $dependency" >> $error_log; true; }
fi
done
# Install package, then uninstall it with all his dependencies
echo "Package installation..."
error_output=$(dnf install -y $package 2>&1) || { echo "$error_output" >> $error_log; echo "Error during installation of the package $package" >> $error_log; true; }
echo "Package installation done."
echo "Package uninstallation..."
error_output=$(dnf autoremove --setopt=keepcache=True -y $(echo $package | sed 's/_[0-9].*\.rpm//' | sed 's/.\///') 2>&1) || { echo "$error_output" >> $error_log; echo "Error during autoremove of the package $package" >> $error_log; true; }
echo "Package uninstallation done."
done
# If the file error_log exists and is not empty, the workflow is in error
if [[ -s $error_log ]]; then
cat $error_log
exit 1
fi
shell: bash

- if: ${{ inputs.package_extension == 'deb' }}
name: Install packages
run: |
error_log="install_error_${{ inputs.distrib }}_${{ inputs.arch }}.log"
for package in ./*.deb; do
# If the debian package name ends with amd64 or arm64, we only install it if the tested architecture is the same, otherwise we skip it
if [[ $package == *amd64.deb && ${{ inputs.arch }} != "amd64" || $package == *arm64.deb && ${{ inputs.arch }} != "arm64" ]]; then
continue
fi
echo "Installing package: $package"
# List dependencies
dependencies=$(dpkg-deb -I $package | grep Depends | sed 's/Depends: //' | sed 's/,//g' | sed 's/(\(.*\)//g') || { echo "$error_output" >> $error_log; echo "Error while listing dependencies of the package $package" >> $error_log; true; }
for dependency in $dependencies; do
# If the dependency exists in the Debian repository, don't check the local dependencies
dependency_info=$(apt-cache policy $dependency)
if [[ -n $dependency_info ]]; then
echo "Dependency $dependency exists in debian repository."
else
# If the dependency has been built in the same workflow, install it
for dependency_package in $(find . -maxdepth 1 -regex "\.\/${dependency}_[0-9].*all\.deb" -o -regex "\.\/${dependency}_[0-9].*${{ inputs.arch }}\.deb"); do
echo "Installing dependency: $dependency_package"
error_output=$(apt-get install -y ./$dependency_package 2>&1) || { echo "$error_output" >> $error_log; echo "Error during installation of the dependency $dependency" >> $error_log; true; }
done
fi
done
# Install package, then uninstall it with all his dependencies
echo "Package installation..."
error_output=$(apt-get install -y $package 2>&1) || { echo "$error_output" >> $error_log; echo "Error during installation of the package $package" >> $error_log; true; }
echo "Package installation done."
echo "Package uninstallation..."
error_output=$(apt-get autoremove -y --purge $(echo $package | sed 's/_[0-9].*\.deb//' | sed 's/.\///') 2>&1) || { echo "$error_output" >> $error_log; echo "Error during autoremove of the package $package" >> $error_log; true; }
echo "Package uninstallation done."
done
# If the file error_log exists and is not empty, the workflow is in error
if [[ -s $error_log ]]; then
cat $error_log
exit 1
fi
shell: bash
119 changes: 9 additions & 110 deletions .github/workflows/perl-new-cpan-libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- rpm_provides: ""
- version: ""
- spec_file: ""
- no-auto-depends: false
- no-auto-depends: "false"
- preinstall_cpanlibs: ""
- distrib: el8
package_extension: rpm
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
done
fi
if [ ! -z "${{ matrix.no-auto-depends }}" ]; then
if [ "${{ matrix.no-auto-depends }}" == "true" ]; then
PACKAGE_DEPENDENCIES="$PACKAGE_DEPENDENCIES --no-auto-depends"
fi
Expand Down Expand Up @@ -247,7 +247,7 @@ jobs:
- rpm_provides: ""
- version: ""
- use_dh_make_perl: "true"
- no-auto-depends: false
- no-auto-depends: "false"
- preinstall_cpanlibs: ""
- build_name: bullseye-amd64
distrib: bullseye
Expand Down Expand Up @@ -350,7 +350,7 @@ jobs:
PACKAGE_DEPENDENCIES="$PACKAGE_DEPENDENCIES --depends $PACKAGE_DEPENDENCY"
done
fi
if [ ! -z "${{ matrix.no-auto-depends }}" ]; then
if [ "${{ matrix.no-auto-depends }}" == "true" ]; then
PACKAGE_DEPENDENCIES="$PACKAGE_DEPENDENCIES --no-auto-depends"
fi
Expand Down Expand Up @@ -488,114 +488,13 @@ jobs:

name: Test perl CPAN libs packages on ${{ matrix.package_extension }} ${{ matrix.distrib }} ${{ matrix.arch }}
steps:
- if: ${{ matrix.package_extension == 'rpm' }}
name: Install zstd, perl and Centreon repositories
run: |
dnf install -y zstd perl epel-release 'dnf-command(config-manager)'
dnf config-manager --set-enabled powertools || true # alma 8
dnf config-manager --set-enabled crb || true # alma 9
# Import Centreon GPG key
GPG_KEY_URL="https://yum-gpg.centreon.com/RPM-GPG-KEY-CES"
curl -sSL $GPG_KEY_URL -o RPM-GPG-KEY-CES
rpm --import RPM-GPG-KEY-CES
shell: bash

- if: ${{ matrix.package_extension == 'deb' }}
name: Install zstd, perl and Centreon repositories
run: |
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y zstd perl wget gpg apt-utils procps
wget -O- https://apt-key.centreon.com | gpg --dearmor | tee /etc/apt/trusted.gpg.d/centreon.gpg > /dev/null 2>&1
# Avoid apt to clean packages cache directory
rm -f /etc/apt/apt.conf.d/docker-clean
apt-get update
shell: bash

- name: Restore packages from cache
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
- name: Test packaged libs
uses: ./.github/actions/test-cpan-libs
with:
path: ./*.${{ matrix.package_extension }}
key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}
fail-on-cache-miss: true

- if: ${{ matrix.package_extension == 'rpm' }}
name: Install packages
run: |
error_log="install_error_${{ matrix.distrib }}_${{ matrix.arch }}.log"
for package in ./*.rpm; do
echo "Installing package: $package"
# List dependencies, and remove version and comparison operators
dependencies=$(rpm -qpR $package | sed 's/ [0-9.-]*\(\s\|$\)/ /g' | sed 's/ [<>!=]*\(\s\|$\)/ /g')
for dependency in $dependencies; do
# Skip non-perl dependencies
if [[ $dependency != perl* ]]; then
continue
else
echo "Check dependency: $dependency"
# Update the dependency name to match the package name
dependency=$(echo $dependency | sed 's/(/-/g' | sed 's/)//g' | sed 's/::/-/g')
fi
# If the dependency has been built in the same workflow, install it
if [[ -n $(find . -maxdepth 1 -regex "\.\/$dependency-[0-9v].*\.rpm") ]]; then
echo "Installing dependency: $dependency"
error_output=$(dnf install -y ./$dependency*.rpm 2>&1) || { echo "$error_output" >> $error_log; echo "Error during installation of the dependency $dependency" >> $error_log; true; }
fi
done
# Install package, then uninstall it with all his dependencies
echo "Package installation..."
error_output=$(dnf install -y $package 2>&1) || { echo "$error_output" >> $error_log; echo "Error during installation of the package $package" >> $error_log; true; }
echo "Package installation done."
echo "Package uninstallation..."
error_output=$(dnf autoremove --setopt=keepcache=True -y $(echo $package | sed 's/_[0-9].*\.rpm//' | sed 's/.\///') 2>&1) || { echo "$error_output" >> $error_log; echo "Error during autoremove of the package $package" >> $error_log; true; }
echo "Package uninstallation done."
done
# If the file error_log exists and is not empty, the workflow is in error
if [[ -s $error_log ]]; then
cat $error_log
exit 1
fi
shell: bash

- if: ${{ matrix.package_extension == 'deb' }}
name: Install packages
run: |
error_log="install_error_${{ matrix.distrib }}_${{ matrix.arch }}.log"
for package in ./*.deb; do
# If the debian package name ends with amd64 or arm64, we only install it if the tested architecture is the same, otherwise we skip it
if [[ $package == *amd64.deb && ${{ matrix.arch }} != "amd64" || $package == *arm64.deb && ${{ matrix.arch }} != "arm64" ]]; then
continue
fi
echo "Installing package: $package"
# List dependencies
dependencies=$(dpkg-deb -I $package | grep Depends | sed 's/Depends: //' | sed 's/,//g' | sed 's/(\(.*\)//g') || { echo "$error_output" >> $error_log; echo "Error while listing dependencies of the package $package" >> $error_log; true; }
for dependency in $dependencies; do
# If the dependency exists in the Debian repository, don't check the local dependencies
dependency_info=$(apt-cache policy $dependency)
if [[ -n $dependency_info ]]; then
echo "Dependency $dependency exists in debian repository."
else
# If the dependency has been built in the same workflow, install it
for dependency_package in $(find . -maxdepth 1 -regex "\.\/${dependency}_[0-9].*all\.deb" -o -regex "\.\/${dependency}_[0-9].*${{ matrix.arch }}\.deb"); do
echo "Installing dependency: $dependency_package"
error_output=$(apt-get install -y ./$dependency_package 2>&1) || { echo "$error_output" >> $error_log; echo "Error during installation of the dependency $dependency" >> $error_log; true; }
done
fi
done
# Install package, then uninstall it with all his dependencies
echo "Package installation..."
error_output=$(apt-get install -y $package 2>&1) || { echo "$error_output" >> $error_log; echo "Error during installation of the package $package" >> $error_log; true; }
echo "Package installation done."
echo "Package uninstallation..."
error_output=$(apt-get autoremove -y --purge $(echo $package | sed 's/_[0-9].*\.deb//' | sed 's/.\///') 2>&1) || { echo "$error_output" >> $error_log; echo "Error during autoremove of the package $package" >> $error_log; true; }
echo "Package uninstallation done."
done
# If the file error_log exists and is not empty, the workflow is in error
if [[ -s $error_log ]]; then
cat $error_log
exit 1
fi
shell: bash
package_extension: ${{ matrix.package_extension }}
distrib: ${{ matrix.distrib }}
arch: ${{ matrix.arch }}

- name: Upload error log
if: failure()
Expand Down

0 comments on commit 0db4365

Please # to comment.