From b5e4791e8aa8eeba2f214fee71e2eff3bd8c6233 Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 19 May 2020 08:53:32 -0700 Subject: [PATCH] ensure that checkoutInfo.branch is defined and consistent --- .../run_failed_tests_reporter_cli.ts | 3 +-- src/dev/ci_setup/checkout_sibling_es.sh | 2 +- src/dev/ci_setup/extract_bootstrap_cache.sh | 2 +- vars/getCheckoutInfo.groovy | 16 +++++++++++++--- vars/workers.groovy | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts b/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts index 9324f9eb42aa5f..4b88b0d818dc27 100644 --- a/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts +++ b/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts @@ -49,8 +49,7 @@ export function runFailedTestsReporterCli() { } const isPr = !!process.env.ghprbPullId; - const isMasterOrVersion = - branch.match(/^(origin\/){0,1}master$/) || branch.match(/^(origin\/){0,1}\d+\.(x|\d+)$/); + const isMasterOrVersion = branch === 'master' || branch.match(/^\d+\.(x|\d+)$/); if (!isMasterOrVersion || isPr) { log.info('Failure issues only created on master/version branch jobs'); updateGithub = false; diff --git a/src/dev/ci_setup/checkout_sibling_es.sh b/src/dev/ci_setup/checkout_sibling_es.sh index 2eec99a690134f..915759d4214f9a 100755 --- a/src/dev/ci_setup/checkout_sibling_es.sh +++ b/src/dev/ci_setup/checkout_sibling_es.sh @@ -43,7 +43,7 @@ function checkout_sibling { fi cloneAuthor="elastic" - cloneBranch="${PR_SOURCE_BRANCH:-${GIT_BRANCH#*/}}" # GIT_BRANCH starts with the repo, i.e., origin/master + cloneBranch="$GIT_BRANCH" if clone_target_is_valid ; then return 0 fi diff --git a/src/dev/ci_setup/extract_bootstrap_cache.sh b/src/dev/ci_setup/extract_bootstrap_cache.sh index 4a5977a68169eb..fdd8bb6b904060 100755 --- a/src/dev/ci_setup/extract_bootstrap_cache.sh +++ b/src/dev/ci_setup/extract_bootstrap_cache.sh @@ -2,7 +2,7 @@ set -e -targetBranch="${PR_TARGET_BRANCH:-${GIT_BRANCH#*/}}" +targetBranch="${PR_TARGET_BRANCH:-$GIT_BRANCH}" bootstrapCache="$HOME/.kibana/bootstrap_cache/$targetBranch.tar" ### diff --git a/vars/getCheckoutInfo.groovy b/vars/getCheckoutInfo.groovy index 3d63c5b0ee4926..7a3a7a9d2eccc7 100644 --- a/vars/getCheckoutInfo.groovy +++ b/vars/getCheckoutInfo.groovy @@ -1,10 +1,20 @@ -def call() { - +def call(branchOverride) { def repoInfo = [ - branch: env.ghprbSourceBranch ?: params.branch_specifier ?: null, + branch: branchOverride ?: env.ghprbSourceBranch, targetBranch: env.ghprbTargetBranch, ] + if (repoInfo.branch == null) { + if (!(params.branch_specifier instanceof String)) { + throw new Exception( + "Unable to determine branch automatically, either pass a branch name to getCheckoutInfo() or use the branch_specifier param." + ) + } + + // strip prefix from the branch specifier to make it consistent with ghprbSourceBranch + repoInfo.branch = params.branch_specifier.replaceFirst(/^(refs\/heads\/|origin\/)/, "") + } + repoInfo.commit = sh( script: "git rev-parse HEAD", label: "determining checked out sha", diff --git a/vars/workers.groovy b/vars/workers.groovy index 9ddcecfde99c0a..d2cc19787bc5f8 100644 --- a/vars/workers.groovy +++ b/vars/workers.groovy @@ -78,7 +78,7 @@ def base(Map params, Closure closure) { "PR_TARGET_BRANCH=${env.ghprbTargetBranch ?: ''}", "PR_AUTHOR=${env.ghprbPullAuthorLogin ?: ''}", "TEST_BROWSER_HEADLESS=1", - "GIT_BRANCH=${checkoutInfo.branch ?: ''}", + "GIT_BRANCH=${checkoutInfo.branch}", ]) { withCredentials([ string(credentialsId: 'vault-addr', variable: 'VAULT_ADDR'),