Skip to content

Commit a6187b3

Browse files
👷 sign chrome-bump commits with commit-headless (#4838)
1 parent 6589a4c commit a6187b3

5 files changed

Lines changed: 44 additions & 2 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
issuer: https://gitlab.ddbuild.io
2+
3+
subject_pattern: 'project_path:DataDog/browser-sdk:ref_type:branch:ref:main'
4+
5+
claim_pattern:
6+
project_path: 'DataDog/browser-sdk'
7+
ref_type: 'branch'
8+
ref: 'main'
9+
10+
permissions:
11+
contents: write

‎Dockerfile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o
7676
# DD Octo STS to get security token
7777
COPY --from=registry.ddbuild.io/dd-octo-sts:v1.8.1@sha256:eb2895829cdcb1f41cc4fc9d1f3f329c7d8f6fa72b0e8bb915d8195717e02bfa /usr/local/bin/dd-octo-sts /usr/local/bin/dd-octo-sts
7878

79+
# Commit Headless to create signed (Verified) commits from CI bots
80+
COPY --from=registry.ddbuild.io/commit-headless /commit-headless /usr/local/bin/commit-headless
81+
7982
RUN apt-get update && apt-get install -y jq
8083

8184
# Webdriverio deps

‎scripts/lib/gitUtils.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getGithubReadToken,
77
getGithubReleaseToken,
88
getGithubPullRequestToken,
9+
getGithubCommitToken,
910
type OctoStsToken,
1011
} from './secrets.ts'
1112
import { FetchError, fetchHandlingError, findError } from './executionUtils.ts'
@@ -74,6 +75,26 @@ export function createPullRequest(mainBranch: string, labels?: string[]) {
7475
return pullRequestUrl.trim()
7576
}
7677

78+
/**
79+
* Push the current HEAD commit to a new remote branch as a signed (Verified) commit, using
80+
* commit-headless to create it through the GitHub API instead of a plain `git push`. Since the
81+
* remote commit is re-signed, its SHA differs from the local one: `--reset` resets the local
82+
* branch to it, so callers (e.g. `gh pr create`) see it as fully pushed and don't attempt an
83+
* unsigned push of their own.
84+
*/
85+
export function pushSignedCommit(branch: string): void {
86+
// `--create-branch` has no default branch point, so `--head-sha` must be given explicitly: the
87+
// parent of HEAD, i.e. the commit the local branch was created from.
88+
const headSha = command`git rev-parse HEAD^`.run().trim()
89+
90+
using token = getGithubCommitToken()
91+
command`commit-headless push -T DataDog/browser-sdk --branch ${branch} --create-branch --head-sha ${headSha} --reset`
92+
.withEnvironment({ GITHUB_TOKEN: token.value })
93+
.withLogs()
94+
.run()
95+
command`git branch --set-upstream-to=origin/${branch} ${branch}`.run()
96+
}
97+
7798
export function getLastCommonCommit(baseBranch: string): string {
7899
try {
79100
command`git fetch --depth=100 origin ${baseBranch}`.run()

‎scripts/lib/secrets.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ export function getGithubReadToken() {
3434
return new OctoStsToken('read')
3535
}
3636

37+
/**
38+
* This token is scoped to main branch only.
39+
*/
40+
export function getGithubCommitToken() {
41+
return new OctoStsToken('commit')
42+
}
43+
3744
export function getOrg2ApiKey(): string {
3845
return getSecretKey('ci.browser-sdk.datadog_ci_api_key')
3946
}

‎scripts/test/bump-chrome-version.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'node:fs'
22
import { printLog, runMain, fetchHandlingError } from '../lib/executionUtils.ts'
33
import { command } from '../lib/command.ts'
44
import { CI_FILE, replaceCiFileVariable } from '../lib/filesUtils.ts'
5-
import { initGitConfig, createPullRequest } from '../lib/gitUtils.ts'
5+
import { initGitConfig, createPullRequest, pushSignedCommit } from '../lib/gitUtils.ts'
66

77
const REPOSITORY = process.env.GIT_REPOSITORY
88
const MAIN_BRANCH = process.env.MAIN_BRANCH
@@ -51,7 +51,7 @@ runMain(async () => {
5151

5252
command`git add ${CI_FILE}`.run()
5353
command`git commit -m ${commitMessage}`.run()
54-
command`git push origin ${chromeVersionBranch}`.run()
54+
pushSignedCommit(chromeVersionBranch)
5555

5656
printLog('Create PR...')
5757

0 commit comments

Comments
 (0)