From 1ca3e0ae56b22e3717a7aa98a2ec08fdc4988d7b Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Wed, 31 May 2023 22:41:31 -0400 Subject: [PATCH] Add RPM PR test job for Copr --- theforeman.org/pipelines/lib/copr.groovy | 19 ++ theforeman.org/pipelines/lib/obal.groovy | 4 +- .../foreman_packaging_rpm_release.groovy | 2 - .../pipelines/test/rpm_copr_packaging.groovy | 167 ++++++++++++++++++ .../foreman-packaging-rpm-pr-test.yaml | 20 +++ 5 files changed, 208 insertions(+), 4 deletions(-) create mode 100644 theforeman.org/pipelines/lib/copr.groovy create mode 100644 theforeman.org/pipelines/test/rpm_copr_packaging.groovy diff --git a/theforeman.org/pipelines/lib/copr.groovy b/theforeman.org/pipelines/lib/copr.groovy new file mode 100644 index 00000000..e6d3a562 --- /dev/null +++ b/theforeman.org/pipelines/lib/copr.groovy @@ -0,0 +1,19 @@ +def status_copr_links(repo) { + def build_urls = [] + if(fileExists('copr_build_urls')) { + build_urls = sh(returnStdout: true, script: "cat copr_build_urls", label: 'get Copr build URLs').trim().split() + } + + for (String build_id: build_urls) { + githubNotify( + credentialsId: 'github-login', + account: 'theforeman', + repo: repo, + sha: "${ghprbActualCommit}", + context: "copr/${build_package}", + description: "Copr build", + status: build_status, + targetUrl: build_url + ) + } +} diff --git a/theforeman.org/pipelines/lib/obal.groovy b/theforeman.org/pipelines/lib/obal.groovy index 0a55d448..37be9c90 100644 --- a/theforeman.org/pipelines/lib/obal.groovy +++ b/theforeman.org/pipelines/lib/obal.groovy @@ -51,10 +51,10 @@ def setup_obal() { poll: false, scm: [ $class: 'GitSCM', - branches: [[name: 'master']], + branches: [[name: 'refactor-copr']], extensions: [[$class: 'CleanCheckout']], userRemoteConfigs: [ - [url: 'https://github.com/theforeman/obal'] + [url: 'https://github.com/ehelms/obal'] ] ] ) diff --git a/theforeman.org/pipelines/release/foreman_packaging_rpm_release.groovy b/theforeman.org/pipelines/release/foreman_packaging_rpm_release.groovy index 43b5eea0..f5026d07 100644 --- a/theforeman.org/pipelines/release/foreman_packaging_rpm_release.groovy +++ b/theforeman.org/pipelines/release/foreman_packaging_rpm_release.groovy @@ -30,8 +30,6 @@ pipeline { } stage('Find packages') { steps { - copyArtifacts(projectName: env.JOB_NAME, optional: true) - script { if (fileExists('commit')) { diff --git a/theforeman.org/pipelines/test/rpm_copr_packaging.groovy b/theforeman.org/pipelines/test/rpm_copr_packaging.groovy new file mode 100644 index 00000000..4bc9241f --- /dev/null +++ b/theforeman.org/pipelines/test/rpm_copr_packaging.groovy @@ -0,0 +1,167 @@ +def packages_to_build +def packages = [:] +def VERCMP_NEWER = 12 +def VERCMP_OLDER = 11 +def VERCMP_EQUAL = 0 + +pipeline { + agent { label 'rpmbuild' } + + options { + timestamps() + timeout(time: 4, unit: 'HOURS') + ansiColor('xterm') + buildDiscarder(logRotator(daysToKeepStr: '7')) + } + + stages { + stage('Clone Packaging') { + steps { + + deleteDir() + ghprb_git_checkout() + setup_obal() + + } + } + + stage('Find Packages to Build') { + steps { + + script { + packages_to_build = find_changed_packages("origin/${ghprbTargetBranch}") + + update_build_description_from_packages(packages_to_build) + } + + } + } + + stage('Lint Spec') { + when { + expression { packages_to_build } + } + steps { + + script { + for(int i = 0; i < packages_to_build.size(); i++) { + def index = i + packages[packages_to_build[index]] = { + obal(action: "lint", packages: packages_to_build[index]) + } + } + + parallel packages + } + } + } + + stage("Verify version and release"){ + when { + expression { packages_to_build } + expression { ghprbTargetBranch == 'rpm/develop'} + } + steps { + script { + + for(int i = 0; i < packages_to_build.size(); i++) { + package_name = packages_to_build[i] + spec_pattern = "packages/**/${package_name}.spec" + + old_spec_path = find_deleted_files("origin/${env.ghprbTargetBranch}", spec_pattern) + if (! old_spec_path) { + old_spec_path = find_changed_files("origin/${env.ghprbTargetBranch}", spec_pattern) + } + + + if (old_spec_path) { + new_spec_path = find_added_or_changed_files("origin/${env.ghprbTargetBranch}", spec_pattern) + if (old_spec_path != new_spec_path) { + continue + } + + sh(script: "git checkout origin/${env.ghprbTargetBranch}", label: "git checkout target_branch") + old_version = query_rpmspec(old_spec_path, '%{VERSION}') + old_release = query_rpmspec(old_spec_path, '%{RELEASE}') + + sh(script: "git checkout -", label: "git checkout source_branch") + new_version = query_rpmspec(new_spec_path, '%{VERSION}') + new_release = query_rpmspec(new_spec_path, '%{RELEASE}') + + compare_version = sh( + script: "rpmdev-vercmp ${old_version} ${new_version}", + returnStatus: true, + label: "rpmdev-vercmp" + ) + + compare_release = sh( + script: "rpmdev-vercmp ${old_release} ${new_release}", + returnStatus: true, + label: "rpmdev-vercmp" + ) + + compare_new_to_one = sh( + script: "rpmdev-vercmp 1 ${new_release}", + returnStatus: true, + label: "rpmdev-vercmp" + ) + + if (compare_version != VERCMP_EQUAL && (compare_new_to_one == VERCMP_OLDER || compare_new_to_one == VERCMP_EQUAL)) { + echo "New version and release is reset to 1 for ${package_name}" + } else if (compare_version != VERCMP_EQUAL && compare_new_to_one == VERCMP_NEWER) { + // new version, but release was not reset + sh """ + echo 'Version updated but release was not reset back to 1 for ${package_name}"' + exit 1 + """ + } else if (compare_version == VERCMP_EQUAL && compare_release == VERCMP_NEWER) { + echo "Version remained the same and release is reset to 1 for ${package_name}" + } else { + sh """ + echo 'Version or release needs updating for ${package_name}"' + exit 1 + """ + } + } + } + } + } + } + + stage('Scratch Build Packages') { + when { + expression { packages_to_build } + } + steps { + + obal( + action: "scratch", + extraVars: [ + 'build_package_build_system': 'copr', + 'build_package_download_rpms': 'True', + 'build_package_archive_build_ids': 'True' + ], + packages: packages_to_build + ) + + } + } + + stage('Repoclosure') { + when { + expression { packages_to_build } + } + steps { + + obal(action: "repoclosure", packages: packages_to_build) + + } + } + } + + post { + always { + status_copr_links(ghprbGhRepository.split('/')[1]) + } + } +} diff --git a/theforeman.org/yaml/jobs/packaging/foreman-packaging-rpm-pr-test.yaml b/theforeman.org/yaml/jobs/packaging/foreman-packaging-rpm-pr-test.yaml index 55bdc4d2..6a3db077 100644 --- a/theforeman.org/yaml/jobs/packaging/foreman-packaging-rpm-pr-test.yaml +++ b/theforeman.org/yaml/jobs/packaging/foreman-packaging-rpm-pr-test.yaml @@ -18,3 +18,23 @@ - pipelines/lib/git.groovy - pipelines/lib/ansible.groovy - pipelines/lib/obal.groovy + +- job: + name: foreman-packaging-rpm-copr-pr-test + project-type: pipeline + concurrent: true + sandbox: true + properties: + - github: + url: https://github.com/theforeman/foreman-packaging + triggers: + - github_pr_rpm: + context: 'rpm-copr' + dsl: + !include-raw: + - pipelines/test/rpm_copr_packaging.groovy + - pipelines/lib/packaging.groovy + - pipelines/lib/copr.groovy + - pipelines/lib/git.groovy + - pipelines/lib/ansible.groovy + - pipelines/lib/obal.groovy