Skip to content

Commit

Permalink
Ask koji to scratch-build pagure pull requests
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Srb <[email protected]>
  • Loading branch information
msrb committed Feb 9, 2024
1 parent 9d9a840 commit a3eb9ec
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 137 deletions.
54 changes: 27 additions & 27 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,41 +84,31 @@ pipeline {
environment {
KOJI_KEYTAB = credentials('fedora-keytab')
KRB_PRINCIPAL = 'bpeck/[email protected]'
REPO_FULL_NAME = "${params.REPO_FULL_NAME}"
SOURCE_REPO_FULL_NAME = "${sourceRepo}"
REPO_NAME = "${params.REPO_FULL_NAME.split('/')[1]}"
RELEASE_ID = "${releaseId}"
PR_ID = "${params.PR_ID}"
PR_UID = "${params.PR_UID}"
PR_COMMIT = "${params.PR_COMMIT}"
PR_COMMENT = "${params.PR_COMMENT}"
RAWHIDE_RELEASE_ID = "${FEDORA_CI_RAWHIDE_RELEASE_ID}"
}

steps {
script {
timeout(time: 240, unit: 'MINUTES') {
// lock buildroot
lock("${env.NODE_NAME}-mock-buildroot") {
def rc = sh(returnStatus: true, script: './pullRequest2scratchBuild.sh')
if (fileExists('koji_url')) {
kojiUrl = readFile("${env.WORKSPACE}/koji_url").trim()
}
if (fileExists('task_id')) {
taskId = readFile("${env.WORKSPACE}/task_id").trim()
}
if (!kojiUrl || !taskId) {
error('Failed to submit a scratch-build')
def rc = sh(returnStatus: true, script: "./scratch-build.sh koji ${releaseId}-candidate git+https://src.fedoraproject.org/${sourceRepo}.git#${params.PR_COMMIT}")
if (fileExists('koji_url')) {
kojiUrl = readFile("${env.WORKSPACE}/koji_url").trim()
}
if (fileExists('task_id')) {
taskId = readFile("${env.WORKSPACE}/task_id").trim()
}
catchError(buildResult: 'UNSTABLE') {
if (rc != 0) {
error('Failed to scratch build the pull request.')
}
}
}
sendMessage(type: 'running', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest(), runUrl: kojiUrl)
sendMessage(type: 'running', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest(), runUrl: kojiUrl)

// Wait for the scratch-build to finish
def rc = sh(returnStatus: true, script: "./wait-build.sh ${taskId}")
catchError(buildResult: 'UNSTABLE') {
if (rc != 0) {
error("Scratch-build failed in Koji")
// Wait for the scratch-build to finish
rc = sh(returnStatus: true, script: "./wait-build.sh ${taskId}")
catchError(buildResult: 'UNSTABLE') {
if (rc != 0) {
error("Scratch-build failed in Koji")
}
}
}
}
Expand All @@ -130,6 +120,16 @@ pipeline {
success {
sendMessage(type: 'complete', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest(), runUrl: kojiUrl)

// Run dist-git tests on the scratch build, and report results back to the pull request
build(
wait: false,
job: 'fedora-ci/dist-git-pipeline/master',
parameters: [
string(name: 'ARTIFACT_ID', value: "(koji-build:${taskId})->${artifactId}"),
string(name: 'TEST_PROFILE', value: releaseId)
]
)

// Run the installability test on the scratch build, and report results back to the pull request
build(
wait: false,
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# dist-git build pipeline

This pipeline is responsible for scratch-building dist-git pull requests.

It creates an SRPM and sends it to Koji where the actual magic happens.
This pipeline scratch-builds dist-git pull requests.
107 changes: 0 additions & 107 deletions pullRequest2scratchBuild.sh

This file was deleted.

48 changes: 48 additions & 0 deletions scratch-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Scratch-build pull requests in Koji.

# Required environment variables:
# KOJI_KEYTAB - path to the keytab that can be used to build packages in Koji
# KRB_PRINCIPAL - kerberos principal

workdir=${PWD}

if [ $# -ne 3 ]; then
echo "Usage: $0 <koji-profile> <target> <scm-url>"
exit 101
fi

koji_log=${workdir}/koji.log
koji_url=${workdir}/koji_url
task_id_file=${workdir}/task_id

set -e
set -x

rm -f ${koji_log}
rm -f ${koji_url}
rm -f ${task_id_file}

profile=${1}
target=${2}
source_url=${3}

if [ -z "${KOJI_KEYTAB}" ]; then
echo "Missing keytab, cannot continue..."
exit 101
fi

if [ -z "${KRB_PRINCIPAL}" ]; then
echo "Missing kerberos principal, cannot continue..."
exit 101
fi

kinit -k -t ${KOJI_KEYTAB} ${KRB_PRINCIPAL}

koji -p ${profile} build --scratch --fail-fast --nowait ${target} ${source_url} > ${koji_log}
cat ${koji_log}

cat ${koji_log} | grep '^Task info: ' | awk '{ print $3 }' > ${koji_url}

task_id=$(cat ${koji_log} | grep '^Created task: ' | awk '{ print $3 }' | tee ${task_id_file})

0 comments on commit a3eb9ec

Please sign in to comment.