Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👷 add job to merge main into next major feature branch (v6) #2935

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ variables:
CI_IMAGE: '$BUILD_STABLE_REGISTRY/ci/$APP:$CURRENT_CI_IMAGE'
GIT_REPOSITORY: '[email protected]:DataDog/browser-sdk.git'
MAIN_BRANCH: 'main'
NEXT_MAJOR_BRANCH: 'v6'
CHROME_PACKAGE_VERSION: 127.0.6533.72-1

cache:
Expand Down Expand Up @@ -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
Expand Down
31 changes: 0 additions & 31 deletions scripts/staging-ci/merge-into-staging.js

This file was deleted.

61 changes: 61 additions & 0 deletions scripts/update-branch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict'

const { parseArgs } = require('node:util')
const { printLog, runMain, fetchHandlingError } = require('./lib/execution-utils')
const { command } = require('./lib/command')

const REPOSITORY = process.env.APP
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 })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 praise: ‏TIL! This is great :)

const [branch] = args.positionals

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
const message = jsonResponse.state.feedbacks[0].message

if (!isSuccess) {
throw new Error(message)
}

return message
}

function getDevFlowURLSearchParams(options) {
const params = new URLSearchParams({
repository: REPOSITORY,
...options,
})

return params.toString()
}