From 0c3b3105a833be2b2d62152d678fb4e2aee7d401 Mon Sep 17 00:00:00 2001 From: Tristan Radisson Date: Mon, 17 Oct 2022 17:16:27 +0200 Subject: [PATCH] Correction on quarkus-platform job (#655) * Correction on quarkus-platform job * corrections * updates * update * correction * use shared lib for squash commits * corrected seed test script * update gha * test --- .ci/actions/dsl-tests/action.yml | 25 ++- .../Jenkinsfile.update-quarkus-platform | 146 +++++++++++++----- .ci/jenkins/dsl/jobs.groovy | 14 +- .github/workflows/jenkins-dsl-downstream.yml | 6 +- .github/workflows/jenkins-tests.yml | 5 +- dsl/config/branch.yaml | 3 + dsl/seed/scripts/seed_test.sh | 84 ++++++---- tools/update-quarkus-platform.sh | 11 +- 8 files changed, 198 insertions(+), 96 deletions(-) diff --git a/.ci/actions/dsl-tests/action.yml b/.ci/actions/dsl-tests/action.yml index 9e3e72bbe9d..6804b5c2683 100644 --- a/.ci/actions/dsl-tests/action.yml +++ b/.ci/actions/dsl-tests/action.yml @@ -4,9 +4,6 @@ inputs: repository: description: author/repository to test required: false - reference: - description: reference to test - required: false jobs-folder-path: description: folder path where to find the jobs.groovy file required: false @@ -14,14 +11,14 @@ inputs: main-config-file-repo: description: author/repository to find the main config file required: false - main-config-file-ref: - description: reference to find the main config file - required: false main-config-file-path: description: path to find the main config file required: false - branch-config-name: - description: branch config name to look for + branch-config-file-repo: + description: author/repository to find the branch config file + required: false + branch-config-file-path: + description: path to find the branch config file required: false base-branch: description: base branch for the checks @@ -72,15 +69,15 @@ runs: working-directory: dsl-tests-dir env: DSL_DEFAULT_TEST_REPO: ${{ inputs.repository }} - DSL_DEFAULT_TEST_REF: ${{ inputs.reference }} - DSL_DEFAULT_MAIN_CONFIG_FILE_REPO: ${{ inputs.main-config-file-repo }} - DSL_DEFAULT_MAIN_CONFIG_FILE_REF: ${{ inputs.main-config-file-ref }} DSL_DEFAULT_MAIN_CONFIG_FILE_PATH: ${{ inputs.main-config-file-path }} + DSL_DEFAULT_FALLBACK_MAIN_CONFIG_FILE_REPO: ${{ inputs.main-config-file-repo }} + + DSL_DEFAULT_BRANCH_CONFIG_NAME: ${{ github.base_ref }} + DSL_DEFAULT_BRANCH_CONFIG_FILE_PATH: ${{ inputs.branch-config-file-path }} + DSL_DEFAULT_FALLBACK_BRANCH_CONFIG_FILE_REPO: ${{ inputs.branch-config-file-repo }} - DSL_DEFAULT_BRANCH_CONFIG_NAME: ${{ inputs.branch-config-name }} - - DSL_DEFAULT_FALLBACK_PIPELINES_REF: ${{ env.BASE_BRANCH }} + DSL_DEFAULT_FALLBACK_SEED_REF: ${{ env.BASE_BRANCH }} DSL_DEFAULT_PIPELINES_TEST_DIR: ${{ env.PIPELINES_TEST_DIR }} DSL_DEFAULT_CURRENT_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }} diff --git a/.ci/jenkins/Jenkinsfile.update-quarkus-platform b/.ci/jenkins/Jenkinsfile.update-quarkus-platform index b9a1e19e68e..e880d513663 100644 --- a/.ci/jenkins/Jenkinsfile.update-quarkus-platform +++ b/.ci/jenkins/Jenkinsfile.update-quarkus-platform @@ -1,33 +1,33 @@ +import org.jenkinsci.plugins.workflow.libs.Library @Library('jenkins-pipeline-shared-libraries')_ -import org.jenkinsci.plugins.workflow.libs.Library import org.kie.jenkins.MavenCommand AGENT_LABEL="kie-rhel7 && kie-mem8g && !built-in" -MVN_TOOL="kie-maven-3.8.6" -JDK_TOOL="kie-jdk11" -VERSION="${params.KOGITO_VERSION}" -COMMAND="${params.COMMAND}" -PROJECT='kogito' -FORK_GIT_AUTOR='kie-ci' -pipelinesBaseBranch="${env.GIT_BRANCH_NAME}" -quarkusBaseBranch='main' kogitoPipelinesRepo="kogito-pipelines" quarkusPlatformRepo="quarkus-platform" +branchCreated = false pipeline { agent { - label "$AGENT_LABEL" + label "${AGENT_LABEL}" } options{ timestamps() + timeout(time: 60, unit: 'MINUTES') } tools { - maven "$MVN_TOOL" - jdk "$JDK_TOOL" + maven "${BUILD_MAVEN_TOOL}" + jdk "${BUILD_JDK_TOOL}" + } + + environment { + // Static env is defined into .jenkins/dsl/jobs.groovy file + + KOGITO_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}") } stages{ @@ -36,18 +36,25 @@ pipeline { cleanWs() } } - stage('clone kogito-pipelines') { + stage('Initialize') { steps{ script{ + sh 'printenv' + dir(kogitoPipelinesRepo){ - checkoutRepo(kogitoPipelinesRepo, 'kiegroup', pipelinesBaseBranch) + checkoutRepo(kogitoPipelinesRepo, 'kiegroup', getBuildBranch()) + } + + dir(quarkusPlatformRepo){ + checkoutRepo(quarkusPlatformRepo, 'quarkusio', getQuarkusPlatformBranch()) + githubscm.forkRepo("${FORK_GIT_AUTHOR_CREDS_ID}") } } } } - stage('clone quarkus-platform and update kogito version: stage') { + stage('stage') { when { - expression {COMMAND == 'stage'} + expression { getCommand() == 'stage' } } steps { script { @@ -55,49 +62,62 @@ pipeline { String commitMsg = getCommitMessage() String localBranch = getLocalBranchName() dir(quarkusPlatformRepo){ - checkoutRepo(quarkusPlatformRepo, 'quarkusio', quarkusBaseBranch) - githubscm.forkRepo() - githubscm.createBranch(localBranch) + branchCreated = getOrCreateGitBranch(localBranch, "${FORK_GIT_AUTHOR_CREDS_ID}") + // run update-quarkus-platform.sh with 'stage' - sh "../${kogitoPipelinesRepo}/tools/update-quarkus-platform.sh -s -v ${VERSION} -f ${FORK_GIT_AUTOR} -h ${localBranch} -n -r ${COMMAND}" + sh "${WORKSPACE}/${kogitoPipelinesRepo}/tools/update-quarkus-platform.sh -p ${getProjectName()} -s -v ${getNewVersion()} -f ${FORK_GIT_AUTHOR} -h ${localBranch} -n -r ${getCommand()}" + sh "git status" + // Add changed files, commit and open PR - prLink = commitAndCreatePR(commitMsg, { sh "git add --all" }, localBranch, quarkusBaseBranch) + def prBody = "Generated by Kogito pipelines" + + if (githubscm.isThereAnyChanges()) { + githubscm.commitChanges(commitMsg, { sh "git add --all" }) + githubscm.pushObject('origin', localBranch, "${FORK_GIT_AUTHOR_CREDS_ID}") + if (branchCreated) { + prLink = githubscm.createPrAsDraft(commitMsg, prBody, getQuarkusPlatformBranch(), "${FORK_GIT_AUTHOR_CREDS_ID}") + sendNotification("Draft PR was created with ${getProjectName()} to version ${getNewVersion()}.\nHere is the PR link: ${prLink}") + } else { + echo "Branch ${localBranch} was already created so assuming the PR exists alrerady ..." + sendNotification("Current PR was updated with ${getProjectName()} to version ${getNewVersion()}.") + } + } else { + println '[WARN] no changes to commit' + } } } } } - stage('update kogito version: finalize') { + stage('finalize') { when { - expression {COMMAND == 'finalize'} + expression { getCommand() == 'finalize' } } steps { script { String commitMsg = getCommitMessage() String localBranch = getLocalBranchName() dir(quarkusPlatformRepo){ - checkoutRepo(quarkusPlatformRepo, 'quarkusio', quarkusBaseBranch) - githubscm.forkRepo() sh "git fetch origin" sh "git checkout ${localBranch}" + // run update-quarkus-platform.sh with 'finalize' - sh "../${kogitoPipelinesRepo}/tools/update-quarkus-platform.sh -s -d -v ${VERSION} -f ${FORK_GIT_AUTOR} -h ${localBranch} -n -r ${COMMAND}" - // squash commits - branchName = sh (script: 'git rev-parse --abbrev-ref HEAD', returnStdout: true).trim() - mergeName = sh (script: "git merge-base main ${branchName}", returnStdout: true).trim() - sh "git reset ${mergeName}" - sh "git add -A" - sh "git commit -m \"${commitMsg}\" " - withCredentials([usernamePassword(credentialsId: ${FORK_GIT_AUTOR}, usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_TOKEN')]) { - githubscm.setUserConfig(FORK_GIT_AUTOR) - sh("git config --local credential.helper \"!f() { echo username=\\$GITHUB_USER; echo password=\\$GITHUB_TOKEN; }; f\"") - sh "git push --force-with-lease" - } + sh "${WORKSPACE}/${kogitoPipelinesRepo}/tools/update-quarkus-platform.sh -p ${getProjectName()} -s -d -v ${getNewVersion()} -f ${FORK_GIT_AUTHOR} -h ${localBranch} -n -r ${getCommand()}" + + githubscm.squashCommits(getQuarkusPlatformBranch(), commitMsg) + + githubscm.pushObject('--force-with-lease origin', localBranch, "${FORK_GIT_AUTHOR_CREDS_ID}") + sendNotification("PR was finalized with ${getProjectName()} to version ${getNewVersion()}.") } } } } } + post { + unsuccessful { + sendErrorNotification() + } + } } String commitAndCreatePR(String commitMsg, Closure precommit, String localBranch, String targetBranch) { @@ -107,16 +127,64 @@ String commitAndCreatePR(String commitMsg, Closure precommit, String localBranch return githubscm.createPrAsDraft(commitMsg, prBody, targetBranch) } +/** +* Return true if the branch was created +*/ +boolean getOrCreateGitBranch(String branch, String credentialsId) { + sh 'git fetch origin' + String branchRemoteResult = sh(script: "git ls-remote origin ${branch} | wc -l", returnStdout: true).trim() + if (Integer.parseInt(branchRemoteResult) > 0) { + echo "Branch ${branch} already exist ... will not create it. Checking out !" + sh "git checkout origin/${branch} -b ${branch}" + return false + } else { + echo "Branch ${branch} does not exist ... gonna create it" + githubscm.createBranch(branch) + githubscm.pushObject('origin', branch, credentialsId) + return true + } +} + void checkoutRepo(String repo, String GIT_AUTHOR, String branch) { checkout(githubscm.resolveRepository(repo, GIT_AUTHOR, branch, false)) // need to manually checkout branch since on a detached branch after checkout command sh "git checkout ${branch}" } +void sendNotification(String body) { + emailext body: "${body}", + subject: "[${getBuildBranch()}] Quarkus Platform update", + to: env.KOGITO_CI_EMAIL_TO +} + +void sendErrorNotification() { + sendNotification("Job #${BUILD_NUMBER} was: **${currentBuild.currentResult}**\nPlease look here: ${BUILD_URL}") +} + String getCommitMessage() { - return "bump up ${PROJECT} to ${VERSION}" + return "Bump up ${getProjectName()} to ${getNewVersion()}" } String getLocalBranchName() { - return "bump-${PROJECT}-${VERSION}" + return params.PR_BRANCH ?: "bump-${getProjectName()}-${getNewVersion()}" +} + +String getNewVersion() { + return params.NEW_VERSION } + +String getCommand() { + return params.COMMAND +} + +String getProjectName() { + return env.PROJECT_NAME +} + +String getBuildBranch() { + return env.BUILD_BRANCH_NAME +} + +String getQuarkusPlatformBranch() { + return env.QUARKUS_PLATFORM_BRANCH_NAME +} \ No newline at end of file diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index 652548bff8d..5f51c5421d5 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -183,14 +183,22 @@ void setupBuildOperatorNode() { void setupUpdateQuarkusPlatformJob() { def jobParams = KogitoJobUtils.getBasicJobParams(this, 'update-quarkus-platform', Folder.TOOLS, "${JENKINSFILE_PATH}/Jenkinsfile.update-quarkus-platform", 'Update kogito in quarkus-platform') + KogitoJobUtils.setupJobParamsDefaultMavenConfiguration(this, jobParams) jobParams.env.putAll([ JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}", - GIT_BRANCH_NAME: "${GIT_BRANCH}", + BUILD_BRANCH_NAME: "${GIT_BRANCH}", + QUARKUS_PLATFORM_BRANCH_NAME: 'main', + PROJECT_NAME: 'kogito', + FORK_GIT_AUTHOR: "${GIT_FORK_AUTHOR_NAME}", + FORK_GIT_AUTHOR_CREDS_ID: "${GIT_FORK_AUTHOR_CREDENTIALS_ID}", ]) KogitoJobTemplate.createPipelineJob(this, jobParams)?.with { parameters { - stringParam('KOGITO_VERSION', '', 'Kogito version to upgrade as Major.minor.micro.Final') + stringParam('NEW_VERSION', '', 'Which version to set ?') + + stringParam('PR_BRANCH', '', '(Optional) Which PR branch name to use ? If none given, a name will be generated automatically.') + choiceParam('COMMAND', ['stage', 'finalize'], 'Choose if you want to use staged artifacts or released artifacts.') } } -} \ No newline at end of file +} diff --git a/.github/workflows/jenkins-dsl-downstream.yml b/.github/workflows/jenkins-dsl-downstream.yml index bcd724477aa..a2d7621102a 100644 --- a/.github/workflows/jenkins-dsl-downstream.yml +++ b/.github/workflows/jenkins-dsl-downstream.yml @@ -165,9 +165,8 @@ jobs: with: repository: ${{ matrix.repository }} main-config-file-repo: kiegroup/kogito-pipelines - main-config-file-ref: main main-config-file-path: dsl/config/main.yaml - branch-config-name: ${{ github.base_ref }} + branch-config-file-repo: kiegroup/kogito-pipelines base-branch: ${{ env.BASE_BRANCH }} ############################################################################# @@ -328,7 +327,6 @@ jobs: with: repository: ${{ matrix.repository }} main-config-file-repo: kiegroup/optaplanner - main-config-file-ref: main main-config-file-path: .ci/jenkins/config/main.yaml - branch-config-name: ${{ github.base_ref }} + branch-config-file-repo: kiegroup/optaplanner base-branch: ${{ env.BASE_BRANCH }} diff --git a/.github/workflows/jenkins-tests.yml b/.github/workflows/jenkins-tests.yml index 4c8182209bd..e29e8716b04 100644 --- a/.github/workflows/jenkins-tests.yml +++ b/.github/workflows/jenkins-tests.yml @@ -51,5 +51,6 @@ jobs: uses: kiegroup/kogito-pipelines/.ci/actions/dsl-tests@main with: main-config-file-repo: kiegroup/kogito-pipelines - main-config-file-ref: main - main-config-file-path: dsl/config/main.yaml \ No newline at end of file + main-config-file-path: dsl/config/main.yaml + branch-config-file-repo: kiegroup/kogito-pipelines + \ No newline at end of file diff --git a/dsl/config/branch.yaml b/dsl/config/branch.yaml index c0dec1d8608..6cb7e9e0f31 100644 --- a/dsl/config/branch.yaml +++ b/dsl/config/branch.yaml @@ -40,6 +40,9 @@ git: bot_author: name: bsig-gh-bot credentials_id: bsig-gh-bot + fork_author: + name: kie-ci + credentials_id: kie-ci jenkins_config_path: .ci/jenkins maven: settings_file_id: kogito_release_settings diff --git a/dsl/seed/scripts/seed_test.sh b/dsl/seed/scripts/seed_test.sh index eacfdf00ab4..065173d0f01 100755 --- a/dsl/seed/scripts/seed_test.sh +++ b/dsl/seed/scripts/seed_test.sh @@ -11,7 +11,7 @@ # ${file} $@ script_dir_path=$(cd `dirname "${BASH_SOURCE[0]}"`; pwd -P) -GIT_SERVER='github.com' +GITHUB_SERVER='github.com' declare -A checkout_map usage() { @@ -21,35 +21,38 @@ usage() { echo 'Here is a list of those:' echo echo ' Main config file configuration:' - echo ' DSL_DEFAULT_MAIN_CONFIG_FILE_REPO Main config file repository (owner/repo)' - echo ' DSL_DEFAULT_MAIN_CONFIG_FILE_REF Main config file reference' - echo ' DSL_DEFAULT_MAIN_CONFIG_FILE_PATH Main config file path. Default is `dsl/config/main.yaml`' - echo ' DSL_DEFAULT_MAIN_CONFIG_FILE_LOCAL_PATH Main config file local path. If set, the other `DSL_DEFAULT_MAIN_CONFIG_FILE_*` envs will be ignored' - echo ' DSL_DEFAULT_FALLBACK_MAIN_CONFIG_FILE_REPO Fallback main config repository (owner/repo). Default is `kiegroup/kogito-pipelines`' - echo ' DSL_DEFAULT_FALLBACK_MAIN_CONFIG_FILE_REF Fallback main config reference. Default is `main`' + echo ' DSL_DEFAULT_MAIN_CONFIG_FILE_REPO Main config file repository (owner/repo)' + echo ' DSL_DEFAULT_MAIN_CONFIG_FILE_REF Main config file reference' + echo ' DSL_DEFAULT_MAIN_CONFIG_FILE_PATH Main config file path. Default is `dsl/config/main.yaml`' + echo ' DSL_DEFAULT_FALLBACK_MAIN_CONFIG_FILE_REPO Fallback main config repository (owner/repo). Default is `kiegroup/kogito-pipelines`' + echo ' DSL_DEFAULT_FALLBACK_MAIN_CONFIG_FILE_REF Fallback main config reference. Default is `main`' + echo ' DSL_DEFAULT_MAIN_CONFIG_FILE_LOCAL_PATH Main config file local path. If set, the other `DSL_DEFAULT_MAIN_CONFIG_FILE_*` envs will be ignored' echo echo ' Branch config file configuration:' - echo ' DSL_DEFAULT_BRANCH_CONFIG_NAME DSL branch config name. Corresponding to the match in the main config branch' - echo ' DSL_DEFAULT_BRANCH_CONFIG_FILE_PATH DSL local branch config file path. If that is set, the `DSL_DEFAULT_MAIN_CONFIG_*` and `DSL_DEFAULT_BRANCH_CONFIG_NAME` envs are ignored' + echo ' DSL_DEFAULT_BRANCH_CONFIG_NAME DSL branch config name. Corresponding to the match in the main config branch' + echo ' DSL_DEFAULT_BRANCH_CONFIG_FILE_REPO Branch config file repository (owner/repo). Override the branch config repo. Else it is read from main config.' + echo ' DSL_DEFAULT_BRANCH_CONFIG_FILE_REF Branch config file reference. Override the branch config ref. Else it is read from main config.' + echo ' DSL_DEFAULT_BRANCH_CONFIG_FILE_PATH Branch config file path. Override the branch config path. Else it is read from main config.' + echo ' DSL_DEFAULT_BRANCH_CONFIG_FILE_LOCAL_PATH DSL local branch config file path. If that is set, the `DSL_DEFAULT_MAIN_CONFIG_*` and other `DSL_DEFAULT_BRANCH_CONFIG_*` envs are ignored' echo echo ' Seed repository configuration:' - echo ' DSL_DEFAULT_SEED_REPO DSL seed repository (owner/repo). Else it will be calculated from the test repository.' - echo ' DSL_DEFAULT_SEED_REF DSL seed reference. Else it will be calculated from the branch config' - echo ' DSL_DEFAULT_SEED_REPO_LOCAL_PATH DSL seed repository local path. If set, the other `DSL_DEFAULT_SEED_*` envs will be ignored' - echo ' DSL_DEFAULT_FALLBACK_SEED_REPO Fallback seed repository (owner/repo). Default is `kiegroup/kogito-pipelines`' - echo ' DSL_DEFAULT_FALLBACK_SEED_REF Fallback seed reference. Default is `main`' + echo ' DSL_DEFAULT_SEED_REPO DSL seed repository (owner/repo). Else it will be calculated from the test repository.' + echo ' DSL_DEFAULT_SEED_REF DSL seed reference. Else it will be calculated from the branch config' + echo ' DSL_DEFAULT_SEED_REPO_LOCAL_PATH DSL seed repository local path. If set, the other `DSL_DEFAULT_SEED_*` envs will be ignored' + echo ' DSL_DEFAULT_FALLBACK_SEED_REPO Fallback seed repository (owner/repo). Default is `kiegroup/kogito-pipelines`' + echo ' DSL_DEFAULT_FALLBACK_SEED_REF Fallback seed reference. Default is `main`' echo echo ' Test repository configuration:' - echo ' DSL_DEFAULT_TEST_REPO Repository to test. Default will be handled from current folder' - echo ' DSL_DEFAULT_TEST_REF Repository reference to test. Default will be guessed from current folder' - echo ' DSL_DEFAULT_TEST_JOBS_PATH Path on repository where to find the jobs file. Default to `.ci/jenkins/dsl`' + echo ' DSL_DEFAULT_TEST_REPO Repository to test. Default will be handled from current folder' + echo ' DSL_DEFAULT_TEST_REF Repository reference to test. Default will be guessed from current folder' + echo ' DSL_DEFAULT_TEST_JOBS_PATH Path on repository where to find the jobs file. Default to `.ci/jenkins/dsl`' echo echo ' Current repository information:' - echo ' DSL_DEFAULT_CURRENT_REPOSITORY Force the current repository (owner/repo). Useful if the remote `origin` is not the needed one.' - echo ' DSL_DEFAULT_CURRENT_REF Force the current ref. Useful if the checkout was not done on a branch.' + echo ' DSL_DEFAULT_CURRENT_REPOSITORY Force the current repository (owner/repo). Useful if the remote `origin` is not the needed one.' + echo ' DSL_DEFAULT_CURRENT_REF Force the current ref. Useful if the checkout was not done on a branch.' echo echo ' Other configuration:' - echo ' DSL_DEFAULT_PIPELINES_TEST_DIR Where will be the pipelines test dir' + echo ' DSL_DEFAULT_PIPELINES_TEST_DIR Where will be the pipelines test dir' echo } @@ -122,9 +125,9 @@ fi git_server_url= if [[ "${git_url}" = https://* ]]; then - git_server_url="https://${GIT_SERVER}/" + git_server_url="https://${GITHUB_SERVER}/" elif [[ "${git_url}" = git@* ]]; then - git_server_url="git@${GIT_SERVER}:" + git_server_url="git@${GITHUB_SERVER}:" else echo "Unknown protocol for url ${git_url}" exit 1 @@ -167,10 +170,15 @@ main_config_file_path=${DSL_DEFAULT_MAIN_CONFIG_FILE_PATH:-'dsl/config/main.yaml main_config_file_local_path=${DSL_DEFAULT_MAIN_CONFIG_FILE_LOCAL_PATH} branch_config_name=${DSL_DEFAULT_BRANCH_CONFIG_NAME} -branch_config_file_path=${DSL_DEFAULT_BRANCH_CONFIG_FILE_PATH:-''} +branch_config_file_repo=${DSL_DEFAULT_BRANCH_CONFIG_FILE_REPO} +branch_config_file_ref=${DSL_DEFAULT_BRANCH_CONFIG_FILE_REF} +branch_config_file_path=${DSL_DEFAULT_BRANCH_CONFIG_FILE_PATH} +branch_config_file_local_path=${DSL_DEFAULT_BRANCH_CONFIG_FILE_LOCAL_PATH:-''} fallback_main_config_file_repo=${DSL_DEFAULT_FALLBACK_MAIN_CONFIG_FILE_REPO:-'kiegroup/kogito-pipelines'} fallback_main_config_file_ref=${DSL_DEFAULT_FALLBACK_MAIN_CONFIG_FILE_REF:-'main'} +fallback_branch_config_file_repo=${DSL_DEFAULT_FALLBACK_BRANCH_CONFIG_FILE_REPO:-'kiegroup/kogito-pipelines'} +fallback_branch_config_file_ref=${DSL_DEFAULT_FALLBACK_BRANCH_CONFIG_FILE_REF:-'main'} fallback_branch_config_name="${fallback_main_config_file_ref}" if [ -z "${main_config_file_repo}" ]; then @@ -233,34 +241,46 @@ if [ -z "${branch_config_file_local_path}" ]; then echo "Branch config name cannot be found. Fallback to default branch config name: ${fallback_branch_config_name}" fi + if [ -z "${branch_config_file_repo}" ]; then + branch_config_file_owner="$(echo "${DSL_DEFAULT_TEST_REPO:-${current_repository}}" | awk -F/ '{print $1}')" + branch_config_file_repo_name="$(echo "${fallback_branch_config_file_repo}" | awk -F/ '{print $2}')" + branch_config_file_repo="${branch_config_file_owner}/${branch_config_file_repo_name}" + fi + if [ -z "${branch_config_file_ref}" ]; then + branch_config_file_ref="${DSL_DEFAULT_TEST_REF:-${current_ref}}" + fi + echo "Retrieve branch config file information with branch config name ${branch_config_name}" - branch_config_file_ref="$(yq -e ".git.branches[] | select(.name == \"${branch_config_name}\") | .seed.config_file.git.branch" ${main_config_file_path} 2> /dev/null)" + fallback_branch_config_file_ref="$(yq -e ".git.branches[] | select(.name == \"${branch_config_name}\") | .seed.config_file.git.branch" ${main_config_file_path} 2> /dev/null)" if [ $? != 0 ]; then - branch_config_file_ref="${branch_config_name}" + fallback_branch_config_file_ref="${branch_config_name}" fi branch_config_file_git_repository="$(yq -e ".git.branches[] | select(.name == \"${branch_config_name}\") | .seed.config_file.git.repository" ${main_config_file_path} 2> /dev/null)" if [ $? != 0 ]; then branch_config_file_git_repository="$(yq '.seed.config_file.git.repository' ${main_config_file_path})" fi - branch_config_file_git_author="$(yq -e ".git.branches[] | select(.name == \"${branch_config_name}\") | .seed.config_file.git.author.name" ${main_config_file_path} 2> /dev/null)" if [ $? != 0 ]; then branch_config_file_git_author="$(yq '.seed.config_file.git.author.name' ${main_config_file_path})" fi + fallback_branch_config_file_repo="${branch_config_file_git_author}/${branch_config_file_git_repository}" - branch_config_file_path="$(yq -e ".git.branches[] | select(.name == \"${branch_config_name}\") | .seed.config_file.path" ${main_config_file_path} 2> /dev/null)" - if [ $? != 0 ]; then - branch_config_file_path="$(yq '.seed.config_file.path' ${main_config_file_path})" + if [ -z "${branch_config_file_path}" ]; then + branch_config_file_path="$(yq -e ".git.branches[] | select(.name == \"${branch_config_name}\") | .seed.config_file.path" ${main_config_file_path} 2> /dev/null)" + if [ $? != 0 ]; then + branch_config_file_path="$(yq '.seed.config_file.path' ${main_config_file_path})" + fi fi - branch_config_file_repo="${branch_config_file_git_author}/${branch_config_file_git_repository}" echo "-----------------------------------------------------------------" echo "-- BRANCH CONFIG FILE CONFIGURATION" echo '--' echo "-- branch_config_file_repo.............. ${branch_config_file_repo}" echo "-- branch_config_file_ref............... ${branch_config_file_ref}" echo "-- branch_config_file_path.............. ${branch_config_file_path}" + echo "-- fallback_branch_config_file_repo..... ${fallback_branch_config_file_repo}" + echo "-- fallback_branch_config_file_ref...... ${fallback_branch_config_file_ref}" echo "-----------------------------------------------------------------" branch_config_repo_path=${checkout_map["${branch_config_file_repo}/${branch_config_file_ref}"]} @@ -268,7 +288,7 @@ if [ -z "${branch_config_file_local_path}" ]; then echo 'Retrieve branch config file' branch_config_repo_path=$(mktemp -d) mkdir -p "${branch_config_repo_path}" - checkout_repository "${branch_config_repo_path}" "${branch_config_file_repo}" "${branch_config_file_ref}" + checkout_repository "${branch_config_repo_path}" "${branch_config_file_repo}" "${branch_config_file_ref}" "${fallback_branch_config_file_repo}" "${fallback_branch_config_file_ref}" else echo "Branch config file repository (${branch_config_file_repo}/${branch_config_file_ref}) already checked out. Using it ..." fi @@ -365,7 +385,7 @@ if [ $? != 0 ]; then fi fallback_test_ref="$(yq -e ".repositories[] | select(.name == \"${test_repo_name}\") | .branch" ${branch_config_file_path} 2> /dev/null)" if [ $? != 0 ]; then - fallback_test_ref="${main_config_file_ref}" + fallback_test_ref="${fallback_branch_config_file_ref}" fi echo "-----------------------------------------------------------------" diff --git a/tools/update-quarkus-platform.sh b/tools/update-quarkus-platform.sh index be864f4214a..08a9f7683c2 100755 --- a/tools/update-quarkus-platform.sh +++ b/tools/update-quarkus-platform.sh @@ -6,7 +6,7 @@ GITHUB_URL="https://github.com/" GITHUB_URL_SSH="git@github.com:" VERSION= -PROJECT=kogito +PROJECT= DRY_RUN=false BASE_BRANCH=main PR_BRANCH= @@ -19,7 +19,7 @@ usage() { echo echo 'Options:' echo ' -v $VERSION set version' - echo ' -p project `kogito` or `optaplanner`. Default is kogito.' + echo ' -p project `kogito` or `optaplanner`.' echo ' -f $FORK GH account where the branch should be pushed' echo ' -s Use SSH to connect to GitHub' echo ' -b $BASE_BRANCH Quarkus Platform branch (optional. Default is `main`)' @@ -87,6 +87,13 @@ in exit 2 esac +if [ -z "$PROJECT" ]; then + >&2 echo ERROR: no project specified. + usage + + exit 2 +fi + if [ -z "$VERSION" ]; then >&2 echo ERROR: no version specified. usage