|
| 1 | +name: "test-cpan-libs" |
| 2 | +description: "Test packaged CPAN libraries" |
| 3 | +inputs: |
| 4 | + package_extension: |
| 5 | + description: "The package extension (deb or rpm)" |
| 6 | + required: true |
| 7 | + distrib: |
| 8 | + description: "The distribution name" |
| 9 | + required: true |
| 10 | + arch: |
| 11 | + description: "The architecture (amd64 or arm64)" |
| 12 | + required: true |
| 13 | + |
| 14 | +runs: |
| 15 | + using: "composite" |
| 16 | + steps: |
| 17 | + |
| 18 | + - if: ${{ inputs.package_extension == 'rpm' }} |
| 19 | + name: Install zstd, perl and Centreon repositories |
| 20 | + run: | |
| 21 | + dnf install -y zstd perl epel-release 'dnf-command(config-manager)' perl-App-cpanminus |
| 22 | + dnf config-manager --set-enabled powertools || true # alma 8 |
| 23 | + dnf config-manager --set-enabled crb || true # alma 9 |
| 24 | + # Import Centreon GPG key |
| 25 | + GPG_KEY_URL="https://yum-gpg.centreon.com/RPM-GPG-KEY-CES" |
| 26 | + curl -sSL $GPG_KEY_URL -o RPM-GPG-KEY-CES |
| 27 | + rpm --import RPM-GPG-KEY-CES |
| 28 | + shell: bash |
| 29 | + |
| 30 | + - if: ${{ inputs.package_extension == 'deb' }} |
| 31 | + name: Install zstd, perl and Centreon repositories |
| 32 | + run: | |
| 33 | + export DEBIAN_FRONTEND=noninteractive |
| 34 | + apt-get update |
| 35 | + apt-get install -y zstd perl wget gpg apt-utils procps build-essential cpanminus |
| 36 | + wget -O- https://apt-key.centreon.com | gpg --dearmor | tee /etc/apt/trusted.gpg.d/centreon.gpg > /dev/null 2>&1 |
| 37 | + # Avoid apt to clean packages cache directory |
| 38 | + rm -f /etc/apt/apt.conf.d/docker-clean |
| 39 | + apt-get update |
| 40 | + shell: bash |
| 41 | + |
| 42 | + - name: Restore packages from cache |
| 43 | + uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 |
| 44 | + with: |
| 45 | + path: ./*.${{ inputs.package_extension }} |
| 46 | + key: ${{ github.sha }}-${{ github.run_id }}-${{ inputs.package_extension }}-${{ inputs.distrib }} |
| 47 | + fail-on-cache-miss: true |
| 48 | + |
| 49 | + - if: ${{ inputs.package_extension == 'rpm' }} |
| 50 | + name: Check packages installation / uninstallation |
| 51 | + run: | |
| 52 | + error_log="install_error_${{ inputs.distrib }}_${{ inputs.arch }}.log" |
| 53 | + for package in ./*.rpm; do |
| 54 | + echo "Installing package: $package" |
| 55 | + # List dependencies, and remove version and comparison operators |
| 56 | + dependencies=$(rpm -qpR $package | sed 's/ [0-9.-]*\(\s\|$\)/ /g' | sed 's/ [<>!=]*\(\s\|$\)/ /g') |
| 57 | + for dependency in $dependencies; do |
| 58 | + # Skip non-perl dependencies |
| 59 | + if [[ $dependency != perl* ]]; then |
| 60 | + continue |
| 61 | + else |
| 62 | + echo "Check dependency: $dependency" |
| 63 | + # Update the dependency name to match the package name |
| 64 | + dependency=$(echo $dependency | sed 's/(/-/g' | sed 's/)//g' | sed 's/::/-/g') |
| 65 | + fi |
| 66 | + # If the dependency has been built in the same workflow, install it |
| 67 | + if [[ -n $(find . -maxdepth 1 -regex "\.\/$dependency-[0-9v].*\.rpm") ]]; then |
| 68 | + echo "Installing dependency: $dependency" |
| 69 | + 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; } |
| 70 | + fi |
| 71 | + done |
| 72 | + # Install package, then uninstall it with all his dependencies |
| 73 | + echo "Package installation..." |
| 74 | + error_output=$(dnf install -y $package 2>&1) || { echo "$error_output" >> $error_log; echo "Error during installation of the package $package" >> $error_log; true; } |
| 75 | + echo "Package installation done." |
| 76 | + script_name=$(echo $package | tr '[:upper:]' '[:lower:]' | sed 's/\.\/perl-//' | sed 's/-[0-9\.-]*.el[0-9]..*.rpm//') |
| 77 | + if [[ -f ./tests/cpan-libraries/$script_name.pl ]]; then |
| 78 | + echo "Testing package..." |
| 79 | + error_output=$(perl tests/cpan-libraries/$script_name.pl 2>&1) || { echo "$error_output" >> $error_log; echo "Error during the usage test of the package $package" >> $error_log; true; } |
| 80 | + echo "Testing done." |
| 81 | + else |
| 82 | + echo "No test script found for the package $package" |
| 83 | + fi |
| 84 | + echo "Package uninstallation..." |
| 85 | + 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; } |
| 86 | + echo "Package uninstallation done." |
| 87 | + done |
| 88 | + # If the file error_log exists and is not empty, the workflow is in error |
| 89 | + if [[ -s $error_log ]]; then |
| 90 | + cat $error_log |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + shell: bash |
| 94 | + |
| 95 | + - if: ${{ inputs.package_extension == 'deb' }} |
| 96 | + name: Check packages installation / uninstallation |
| 97 | + run: | |
| 98 | + error_log="install_error_${{ inputs.distrib }}_${{ inputs.arch }}.log" |
| 99 | + for package in ./*.deb; do |
| 100 | + # 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 |
| 101 | + if [[ $package == *amd64.deb && ${{ inputs.arch }} != "amd64" || $package == *arm64.deb && ${{ inputs.arch }} != "arm64" ]]; then |
| 102 | + continue |
| 103 | + fi |
| 104 | + echo "Installing package: $package" |
| 105 | + # List dependencies |
| 106 | + 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; } |
| 107 | + for dependency in $dependencies; do |
| 108 | + # If the dependency exists in the Debian repository, don't check the local dependencies |
| 109 | + dependency_info=$(apt-cache policy $dependency) |
| 110 | + if [[ -n $dependency_info ]]; then |
| 111 | + echo "Dependency $dependency exists in debian repository." |
| 112 | + else |
| 113 | + # If the dependency has been built in the same workflow, install it |
| 114 | + for dependency_package in $(find . -maxdepth 1 -regex "\.\/${dependency}_[0-9].*all\.deb" -o -regex "\.\/${dependency}_[0-9].*${{ inputs.arch }}\.deb"); do |
| 115 | + echo "Installing dependency: $dependency_package" |
| 116 | + 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; } |
| 117 | + done |
| 118 | + fi |
| 119 | + done |
| 120 | + # Install package, then uninstall it with all his dependencies |
| 121 | + echo "Package installation..." |
| 122 | + 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; } |
| 123 | + echo "Package installation done." |
| 124 | + script_name=$(echo $package | sed 's/.\/lib//' | sed 's/-perl_[0-9\.-]*-deb.*\.deb//') |
| 125 | + if [[ -f ./tests/cpan-libraries/$script_name.pl ]]; then |
| 126 | + echo "Testing package..." |
| 127 | + error_output=$(perl tests/cpan-libraries/$script_name.pl 2>&1) || { echo "$error_output" >> $error_log; echo "Error during the usage test of the package $package" >> $error_log; true; } |
| 128 | + echo "Testing done." |
| 129 | + else |
| 130 | + echo "No test script found for the package $package" |
| 131 | + fi |
| 132 | + echo "Package uninstallation..." |
| 133 | + 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; } |
| 134 | + echo "Package uninstallation done." |
| 135 | + done |
| 136 | + # If the file error_log exists and is not empty, the workflow is in error |
| 137 | + if [[ -s $error_log ]]; then |
| 138 | + cat $error_log |
| 139 | + exit 1 |
| 140 | + fi |
| 141 | + shell: bash |
0 commit comments