From ef1ea328bb6719f631786357916a0587d59c900e Mon Sep 17 00:00:00 2001 From: Thomas Lebeau Date: Tue, 13 Aug 2024 14:24:37 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=91=B7=20add=20job=20to=20merge=20mai?= =?UTF-8?q?n=20into=20next=20major=20feature=20branch=20(v6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 14 +++++++++++++- .../merge-into-staging.js => update-branch.js} | 11 +++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) rename scripts/{staging-ci/merge-into-staging.js => update-branch.js} (73%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d53720b698..88b37a1b20 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,6 +6,7 @@ variables: CI_IMAGE: '$BUILD_STABLE_REGISTRY/ci/$APP:$CURRENT_CI_IMAGE' GIT_REPOSITORY: 'git@github.com:DataDog/browser-sdk.git' MAIN_BRANCH: 'main' + NEXT_MAJOR_BRANCH: 'v6' CHROME_PACKAGE_VERSION: 127.0.6533.72-1 cache: @@ -433,7 +434,18 @@ merge-into-staging: - eval $(ssh-agent -s) script: - yarn - - node scripts/staging-ci/merge-into-staging.js + - node scripts/update-branch.js $CURRENT_STAGING + +merge-into-next-major: + stage: pre-deploy + extends: + - .base-configuration + - .main + before_script: + - eval $(ssh-agent -s) + script: + - yarn + - node scripts/update-branch.js $NEXT_MAJOR_BRANCH check-staging-merge: stage: test diff --git a/scripts/staging-ci/merge-into-staging.js b/scripts/update-branch.js similarity index 73% rename from scripts/staging-ci/merge-into-staging.js rename to scripts/update-branch.js index 49d0c27558..c9c371bc38 100644 --- a/scripts/staging-ci/merge-into-staging.js +++ b/scripts/update-branch.js @@ -1,17 +1,20 @@ 'use strict' -const { printLog, runMain, fetchHandlingError } = require('../lib/execution-utils') -const { command } = require('../lib/command') +const { parseArgs } = require('node:util') +const { printLog, runMain, fetchHandlingError } = require('./lib/execution-utils') +const { command } = require('./lib/command') const REPOSITORY = process.env.APP -const CURRENT_STAGING = process.env.CURRENT_STAGING const DEVFLOW_AUTH_TOKEN = command`authanywhere --audience sdm --raw`.run() const DEVFLOW_API_URL = 'https://devflow-api.us1.ddbuild.io/internal/api/v2/devflow/execute/' const SUCESS_FEEDBACK_LEVEL = 'FEEDBACK_LEVEL_INFO' runMain(async () => { + const args = parseArgs({ allowPositionals: true }) + const [branch] = args.positionals + const rawResponse = await fetchHandlingError( - `${DEVFLOW_API_URL}/update-branch?repository=${REPOSITORY}&branch=${CURRENT_STAGING}`, + `${DEVFLOW_API_URL}/update-branch?repository=${REPOSITORY}&branch=${branch}`, { headers: { Authorization: `Bearer ${DEVFLOW_AUTH_TOKEN}`, From 067ce91c272ba03dee1927a825d7dff4267eac8b Mon Sep 17 00:00:00 2001 From: Thomas Lebeau Date: Wed, 14 Aug 2024 14:13:59 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=91=B7=20trigger=20ci=20after=20updat?= =?UTF-8?q?ing=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/update-branch.js | 47 +++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/scripts/update-branch.js b/scripts/update-branch.js index c9c371bc38..97a1cf4898 100644 --- a/scripts/update-branch.js +++ b/scripts/update-branch.js @@ -13,14 +13,32 @@ runMain(async () => { const args = parseArgs({ allowPositionals: true }) const [branch] = args.positionals - const rawResponse = await fetchHandlingError( - `${DEVFLOW_API_URL}/update-branch?repository=${REPOSITORY}&branch=${branch}`, - { - headers: { - Authorization: `Bearer ${DEVFLOW_AUTH_TOKEN}`, - }, - } - ) + await updateBranch(branch) + + // `update-branch` allways skips CI, so we need to trigger it manually + await triggerCi(branch) +}) + +async function updateBranch(branch) { + const message = await devFlow('update-branch', { branch }) + + printLog(message) +} + +async function triggerCi(branch) { + const message = await devFlow('trigger-ci', { ref: branch }) + + printLog(message) +} + +async function devFlow(action, options) { + const params = getDevFlowURLSearchParams(options) + const rawResponse = await fetchHandlingError(`${DEVFLOW_API_URL}/${action}?${params}`, { + headers: { + Authorization: `Bearer ${DEVFLOW_AUTH_TOKEN}`, + }, + }) + const jsonResponse = await rawResponse.json() const isSuccess = jsonResponse.state.feedbacks[0].level === SUCESS_FEEDBACK_LEVEL @@ -30,5 +48,14 @@ runMain(async () => { throw new Error(message) } - printLog(message) -}) + return message +} + +function getDevFlowURLSearchParams(options) { + const params = new URLSearchParams({ + repository: REPOSITORY, + ...options, + }) + + return params.toString() +}