Skip to content

Commit

Permalink
Fix percy target branch for PRs (#43160)
Browse files Browse the repository at this point in the history
* Fix percy target branch for PRs

* Add debug logging

* Try diff branch name

* Use PR_TARGET_BRANCH instead

* renable visReg jobs

* parse target branch from `branch_specifier`

* rename debugging print out

* set `PERCY_BRANCH` and `PERCY_TARGET_BRANCH`

* log PERCY_TARGET_BRANCH

* cleanup error messages
  • Loading branch information
liza-mae authored Aug 14, 2019
1 parent 4acfc04 commit fcba9a6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .ci/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ JOB:
- kibana-ciGroup10
- kibana-ciGroup11
- kibana-ciGroup12
# - kibana-visualRegression
- kibana-visualRegression

# make sure all x-pack-ciGroups are listed in test/scripts/jenkins_xpack_ci_group.sh
- x-pack-firefoxSmoke
Expand All @@ -28,7 +28,7 @@ JOB:
- x-pack-ciGroup8
- x-pack-ciGroup9
- x-pack-ciGroup10
# - x-pack-visualRegression
- x-pack-visualRegression

# `~` is yaml for `null`
exclude: ~
31 changes: 30 additions & 1 deletion src/dev/ci_setup/get_percy_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,36 @@ const pkg = require('../../../package.json');
const { stdout: commit } = execa.sync('git', ['rev-parse', 'HEAD']);
const shortCommit = commit.slice(0, 8);

if (!process.env.JOB_NAME) {
throw new Error('getPercyEnv: [JOB_NAME] environment variable required');
}

const isPr = process.env.JOB_NAME.includes('elastic+kibana+pull-request');
if (isPr && !(process.env.PR_TARGET_BRANCH && process.env.PR_SOURCE_BRANCH)) {
throw new Error(
'getPercyEnv: Unable to determine percy environment in prs without [PR_TARGET_BRANCH] and [PR_SOURCE_BRANCH] environment variables'
);
}

let branch;
if (isPr) {
branch = process.env.PR_SOURCE_BRANCH;
} else {
if (!process.env.branch_specifier) {
throw new Error('getPercyEnv: [branch_specifier] environment variable required');
}

branch = process.env.branch_specifier.split('refs/heads/')[1];

if (!branch) {
throw new Error(
`getPercyEnv: [branch_specifier=${process.env.branch_specifier}] must start with 'refs/heads/'`
);
}
}

console.log(`export PERCY_PARALLEL_TOTAL=2;`);
console.log(`export PERCY_PARALLEL_NONCE="${shortCommit}/${isPr ? 'PR' : pkg.branch}/${process.env.BUILD_ID}";`);
console.log(`export PERCY_PARALLEL_NONCE="${shortCommit}/${isPr ? 'PR' : branch}/${process.env.BUILD_ID}";`);
console.log(`export PERCY_BRANCH="${branch}";`);
// percy snapshots always target pkg.branch, so that feature branches can be based on master/7.x/etc.
console.log(`export PERCY_TARGET_BRANCH="${isPr ? process.env.PR_TARGET_BRANCH : pkg.branch}";`);
2 changes: 2 additions & 0 deletions src/dev/ci_setup/setup_percy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export PUPPETEER_EXECUTABLE_PATH
eval "$(node ./src/dev/ci_setup/get_percy_env)"
echo " -- PERCY_PARALLEL_NONCE='$PERCY_PARALLEL_NONCE'"
echo " -- PERCY_PARALLEL_TOTAL='$PERCY_PARALLEL_TOTAL'"
echo " -- PERCY_BRANCH='$PERCY_BRANCH'"
echo " -- PERCY_TARGET_BRANCH='$PERCY_TARGET_BRANCH'"

0 comments on commit fcba9a6

Please sign in to comment.