From e54d0f8821dc005f13f99b647e964f13c3bf3959 Mon Sep 17 00:00:00 2001 From: Aymeric Date: Tue, 5 Jul 2022 10:43:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Bump=20chrome=20version=20refine?= =?UTF-8?q?=20notifications=20(#1620)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Check if bump branch already exists * Only notify when PR created --- .gitlab-ci.yml | 11 ++++++++++- scripts/bump-chrome-driver-version.js | 17 ++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9bfba0a7ad..d760d7f532 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -434,15 +434,22 @@ bump-chrome-version-scheduled: - eval $(ssh-agent -s) script: - node scripts/bump-chrome-driver-version.js + artifacts: + reports: + dotenv: build.env bump-chrome-version-scheduled-success: extends: .prepare_notification only: variables: - $TARGET_TASK_NAME == "bump-chrome-version-scheduled" + before_script: + - '[ -z "$BUMP_CHROME_PULL_REQUEST_URL" ] && exit' script: - - 'MESSAGE_TEXT=":chrome: [*$CI_PROJECT_NAME*] New Chrome version available on ."' + - 'MESSAGE_TEXT=":chrome: [*$CI_PROJECT_NAME*] New Chrome version available on <$BUMP_CHROME_PULL_REQUEST_URL|PR>."' - postmessage "#browser-sdk-deploy" "$MESSAGE_TEXT" + dependencies: + - bump-chrome-version-scheduled bump-chrome-version-scheduled-failure: extends: .prepare_notification @@ -453,3 +460,5 @@ bump-chrome-version-scheduled-failure: script: - 'MESSAGE_TEXT=":x: [*$CI_PROJECT_NAME*] Chrome version bumped failed on pipeline <$BUILD_URL|$COMMIT_MESSAGE>."' - postmessage "#browser-sdk-deploy" "$MESSAGE_TEXT" + dependencies: + - bump-chrome-version-scheduled diff --git a/scripts/bump-chrome-driver-version.js b/scripts/bump-chrome-driver-version.js index b7c8ad3c48..dfb85b78de 100644 --- a/scripts/bump-chrome-driver-version.js +++ b/scripts/bump-chrome-driver-version.js @@ -38,11 +38,18 @@ async function main() { if (majorPackageVersion !== getMajor(driverVersion)) { printError(`No driver available for chrome ${packageVersion}.`) - process.exit(1) + process.exit() } const chromeVersionBranch = `bump-chrome-version-to-${driverVersion}` const commitMessage = `👷 Bump chrome to ${packageVersion}` + + const isBranchAlreadyCreated = await executeCommand(`git ls-remote --heads ${REPOSITORY} ${chromeVersionBranch}`) + if (isBranchAlreadyCreated) { + printLog('Bump chrome branch already created.') + process.exit() + } + await executeCommand(`git checkout -b ${chromeVersionBranch}`) printLog('Update versions...') @@ -55,9 +62,12 @@ async function main() { await executeCommand(`git push origin ${chromeVersionBranch}`) printLog('Create PR...') - await createPullRequest() + const pullRequestUrl = await createPullRequest() printLog(`Chrome version bump PR created (from ${CURRENT_PACKAGE_VERSION} to ${packageVersion}).`) + + // used to share the pull request url to the notification jobs + await executeCommand(`echo "BUMP_CHROME_PULL_REQUEST_URL=${pullRequestUrl}" >> build.env`) } async function getPackageVersion() { @@ -85,7 +95,8 @@ function getMajor(version) { async function createPullRequest() { const githubAccessToken = await getSecretKey('ci.browser-sdk.github_access_token') await executeCommand(`echo "${githubAccessToken}" | gh auth login --with-token`) - await executeCommand(`gh pr create --fill --base ${MAIN_BRANCH}`) + const pullRequestUrl = await executeCommand(`gh pr create --fill --base ${MAIN_BRANCH}`) + return pullRequestUrl.trim() } main().catch(logAndExit)