From cd12a4ace111fbc4889cf9be185102fa7832c7f6 Mon Sep 17 00:00:00 2001 From: Thomas Lebeau Date: Fri, 30 Jan 2026 11:06:43 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20skip=20BrowserStack=20tests=20fo?= =?UTF-8?q?r=20non-code=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Skip unit-bs and e2e-bs jobs when changes only affect files that don't impact browser behavior (CI config, scripts, docs, etc.). This saves BrowserStack resources (limited to 5 seats) and reduces pipeline duration for PRs that only touch infrastructure files. Jobs will still run when changes affect: - packages/**/* (SDK source code) - test/**/* (test files) - developer-extension/**/* (devtools extension) - package.json, yarn.lock (dependencies) - tsconfig*.json, webpack.base.ts (build config) --- .gitlab-ci.yml | 4 +-- scripts/lib/secrets.ts | 8 ++++++ scripts/test/ci-bs.sh | 7 ------ scripts/test/ci-bs.ts | 57 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 9 deletions(-) delete mode 100755 scripts/test/ci-bs.sh create mode 100644 scripts/test/ci-bs.ts diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eb1c6d30a9..6bc230d8d7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 @@ -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 diff --git a/scripts/lib/secrets.ts b/scripts/lib/secrets.ts index b5f7ef27db..8f9583b50d 100644 --- a/scripts/lib/secrets.ts +++ b/scripts/lib/secrets.ts @@ -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} diff --git a/scripts/test/ci-bs.sh b/scripts/test/ci-bs.sh deleted file mode 100755 index 44ebfc5b7b..0000000000 --- a/scripts/test/ci-bs.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -export BS_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.browser-sdk.bs_username --with-decryption --query "Parameter.Value" --out text) -export BS_ACCESS_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.browser-sdk.bs_access_key --with-decryption --query "Parameter.Value" --out text) -yarn "$1":bs diff --git a/scripts/test/ci-bs.ts b/scripts/test/ci-bs.ts new file mode 100644 index 0000000000..63f7ca9f18 --- /dev/null +++ b/scripts/test/ci-bs.ts @@ -0,0 +1,57 @@ +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 ') + } + + const pr = await fetchPR(LOCAL_BRANCH!) + const baseBranch = pr?.base.ref ?? 'main' + const baseCommit = getLastCommonCommit(baseBranch) + + 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() + + const files = changedFiles.trim().split('\n') + + for (const file of files) { + for (const pattern of RELEVANT_FILE_PATTERNS) { + if (pattern.test(file)) { + printLog(`Matched file: ${file} (pattern: ${pattern})`) + return true + } + } + } + + return false +}