Skip to content
Draft
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
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ unit-bs:
junit: test-report/unit-bs/*.xml
script:
- yarn
- ./scripts/test/ci-bs.sh test:unit
- node scripts/test/ci-bs.ts test:unit
after_script:
- node ./scripts/test/export-test-result.ts unit-bs

Expand All @@ -302,7 +302,7 @@ e2e-bs:
junit: test-report/e2e-bs/*.xml
script:
- yarn
- FORCE_COLOR=1 ./scripts/test/ci-bs.sh test:e2e:ci
- FORCE_COLOR=1 node scripts/test/ci-bs.ts test:e2e:ci
after_script:
- node ./scripts/test/export-test-result.ts e2e-bs

Expand Down
8 changes: 8 additions & 0 deletions scripts/lib/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ export function getChromeWebStoreRefreshToken(): string {
return getSecretKey('ci.browser-sdk.chrome_web_store.refresh_token')
}

export function getBrowserStackUsername(): string {
return getSecretKey('ci.browser-sdk.bs_username')
}

export function getBrowserStackAccessKey(): string {
return getSecretKey('ci.browser-sdk.bs_access_key')
}

function getSecretKey(name: string): string {
return command`
aws ssm get-parameter --region=us-east-1 --with-decryption --query=Parameter.Value --out=text --name=${name}
Expand Down
7 changes: 0 additions & 7 deletions scripts/test/ci-bs.sh

This file was deleted.

54 changes: 54 additions & 0 deletions scripts/test/ci-bs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { printLog, runMain } from '../lib/executionUtils.ts'
import { command } from '../lib/command.ts'
import { fetchPR, getLastCommonCommit, LOCAL_BRANCH } from '../lib/gitUtils.ts'
import { getBrowserStackUsername, getBrowserStackAccessKey } from '../lib/secrets.ts'

// Patterns that should trigger BrowserStack tests
const RELEVANT_FILE_PATTERNS = [
/^packages\//,
/^test\//,
/^developer-extension\//,
/^scripts\/test\//,
/^package\.json$/,
/^yarn\.lock$/,
/^tsconfig/,
/^webpack\.base\.ts$/,
]

runMain(async () => {
const testCommand = process.argv[2]
if (!testCommand) {
throw new Error('Usage: ci-bs.ts <test:unit|test:e2e:ci>')
}

const pr = await fetchPR(LOCAL_BRANCH!)
const baseBranch = pr?.base.ref ?? 'main'
const baseCommit = getLastCommonCommit(baseBranch)

console.log('pr', pr);
console.log('baseBranch', baseBranch);
console.log('baseCommit', baseCommit);


if (!hasRelevantChanges(baseCommit)) {
printLog('No code changes affecting browser behavior detected. Skipping BrowserStack tests.')
return
}

command`yarn ${testCommand}:bs`
.withEnvironment({
BS_USERNAME: getBrowserStackUsername(),
BS_ACCESS_KEY: getBrowserStackAccessKey(),
})
.withLogs()
.run()
})

function hasRelevantChanges(baseCommit: string): boolean {
const changedFiles = command`git diff --name-only ${baseCommit} HEAD`.run()

return changedFiles
.trim()
.split('\n')
.some((file) => RELEVANT_FILE_PATTERNS.some((pattern) => pattern.test(file)))
}