Skip to content

🎥 Make videos programmatically with React

Internal tests: Add affected monorepo CI suite (#10247)

Igor Samokhovets81cedad9c373
diff --git a/.github/scripts/ci.test.ts b/.github/scripts/ci.test.ts
index 1416ced181..bf880b8583 100644
--- a/.github/scripts/ci.test.ts
+++ b/.github/scripts/ci.test.ts
@@ -1,4 +1,13 @@
import {describe, expect, test} from 'bun:test';
+import {
+ mkdirSync,
+ mkdtempSync,
+ readFileSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import {tmpdir} from 'node:os';
+import path from 'node:path';
import {
createCiPlan,
FULL_BUILD_MATRIX,
@@ -51,6 +60,7 @@ const skippedResults = (): RequiredCiResults => ({
browser: 'skipped',
webrenderer: 'skipped',
ssr: 'skipped',
+ monorepo: 'skipped',
templates: 'skipped',
build_job: 'skipped',
});
@@ -95,6 +105,7 @@ describe('CI plan generation', () => {
['webrenderer', 'testwebrenderer'],
['webrenderer', 'testbrowserstudio'],
['ssr', 'testssr'],
+ ['monorepo', 'testmonorepo'],
['templates', 'testtemplates'],
['bundle_example', 'bundle-testbed'],
] as const)('maps %s from the %s task', (suite, task) => {
@@ -105,6 +116,7 @@ describe('CI plan generation', () => {
test('falls back to full CI after a Turborepo command failure', () => {
const plan = planFor({detectorError: 'turbo query affected exited 1'});
expect(plan.full_ci).toBe(true);
+ expect(plan.monorepo).toBe(true);
expect(plan.fallback_reason).toBe('turbo query affected exited 1');
});
@@ -138,6 +150,167 @@ describe('CI plan generation', () => {
});
});
+describe('Turborepo monorepo test inputs', () => {
+ test(
+ 'selects monorepo tests only for declared external inputs',
+ () => {
+ const root = path.resolve(__dirname, '..', '..');
+ const rootPackageJson = JSON.parse(
+ readFileSync(path.join(root, 'package.json'), 'utf8'),
+ ) as {
+ packageManager: string;
+ dependencies: {turbo: string};
+ };
+ const turboConfig = JSON.parse(
+ readFileSync(path.join(root, 'turbo.json'), 'utf8'),
+ ) as {
+ $schema: string;
+ tasks: Record<string, {dependsOn: string[]; inputs: string[]}>;
+ };
+ const monorepoTask = turboConfig.tasks['@remotion/it-tests#testmonorepo'];
+ if (!monorepoTask) {
+ throw new Error('Missing @remotion/it-tests#testmonorepo task');
+ }
+
+ const externalChanges = [
+ {directory: 'lambda-go', file: 'synthetic-input.txt'},
+ {directory: 'lambda-php', file: 'synthetic-input.txt'},
+ {directory: 'lambda-php-example', file: 'composer.json'},
+ {directory: 'lambda-python', file: 'synthetic-input.txt'},
+ {directory: 'lambda-ruby', file: 'synthetic-input.txt'},
+ ] as const;
+ for (const {directory} of externalChanges) {
+ expect(monorepoTask.inputs).toContain(
+ `$TURBO_ROOT$/packages/${directory}/**`,
+ );
+ }
+
+ const fixture = mkdtempSync(path.join(tmpdir(), 'remotion-ci-affected-'));
+ const turboBin = path.join(root, 'node_modules', 'turbo', 'bin', 'turbo');
+ const run = (command: string[], extraEnv: Record<string, string>) => {
+ const result = Bun.spawnSync(command, {
+ cwd: fixture,
+ env: {...process.env, ...extraEnv},
+ stdout: 'pipe',
+ stderr: 'pipe',
+ });
+ if (result.exitCode !== 0) {
+ throw new Error(
+ `${command.join(' ')} failed:\n${new TextDecoder().decode(result.stderr)}`,
+ );
+ }
+
+ return new TextDecoder().decode(result.stdout).trim();
+ };
+ const writeJson = (filePath: string, value: unknown) => {
+ writeFileSync(filePath, JSON.stringify(value, null, 2) + '\n');
+ };
+
+ try {
+ mkdirSync(path.join(fixture, 'packages', 'it-tests'), {
+ recursive: true,
+ });
+ writeJson(path.join(fixture, 'package.json'), {
+ private: true,
+ packageManager: rootPackageJson.packageManager,
+ workspaces: {packages: ['packages/*']},
+ dependencies: {turbo: rootPackageJson.dependencies.turbo},
+ });
+ writeJson(path.join(fixture, 'turbo.json'), {
+ $schema: turboConfig.$schema,
+ tasks: {'@remotion/it-tests#testmonorepo': monorepoTask},
+ });
+ writeJson(path.join(fixture, 'packages', 'it-tests', 'package.json'), {
+ name: '@remotion/it-tests',
+ version: '1.0.0',
+ private: true,
+ scripts: {testmonorepo: 'echo test'},
+ });
+ for (const {directory, file} of externalChanges) {
+ const sdkDirectory = path.join(fixture, 'packages', directory);
+ mkdirSync(sdkDirectory, {recursive: true});
+ if (directory !== 'lambda-php-example') {
+ writeJson(path.join(sdkDirectory, 'package.json'), {
+ name: `@remotion/${directory}`,
+ version: '1.0.0',
+ private: true,
+ });
+ }
+ writeFileSync(path.join(sdkDirectory, file), 'baseline\n');
+ }
+ const unrelatedDirectory = path.join(fixture, 'packages', 'unrelated');
+ mkdirSync(path.join(unrelatedDirectory, 'src'), {recursive: true});
+ writeJson(path.join(unrelatedDirectory, 'package.json'), {
+ name: '@remotion/unrelated',
+ version: '1.0.0',
+ private: true,
+ });
+ writeFileSync(
+ path.join(unrelatedDirectory, 'src', 'unrelated.ts'),
+ 'baseline\n',
+ );
+ writeFileSync(path.join(fixture, '.gitignore'), '.turbo\n');
+
+ run(['git', 'init', '--quiet'], {});
+ run(['git', 'config', 'user.email', '[email protected]'], {});
+ run(['git', 'config', 'user.name', 'CI Test'], {});
+ run(['git', 'add', '.'], {});
+ run(['git', 'commit', '--quiet', '-m', 'baseline'], {});
+ const base = run(['git', 'rev-parse', 'HEAD'], {});
+
+ const affectedForChange = (relativePath: string) => {
+ writeFileSync(path.join(fixture, relativePath), 'changed\n');
+ run(['git', 'add', relativePath], {});
+ run(['git', 'commit', '--quiet', '-m', `Change ${relativePath}`], {});
+ const head = run(['git', 'rev-parse', 'HEAD'], {});
+ expect(run(['git', 'diff', '--name-only', base, head], {})).toBe(
+ relativePath,
+ );
+ const affectedJson = run(
+ [
+ process.execPath,
+ turboBin,
+ 'query',
+ 'affected',
+ '--no-update-notifier',
+ ],
+ {TURBO_SCM_BASE: base, TURBO_SCM_HEAD: head},
+ );
+ run(['git', 'reset', '--hard', '--quiet', base], {});
+ return affectedJson;
+ };
+
+ for (const {directory, file} of externalChanges) {
+ const affectedJson = affectedForChange(
+ `packages/${directory}/${file}`,
+ );
+ const query = JSON.parse(affectedJson) as {
+ data: {affectedTasks: {items: Array<{fullName: string}>}};
+ };
+ expect(
+ query.data.affectedTasks.items.map((task) => task.fullName),
+ ).toContain('@remotion/it-tests#testmonorepo');
+ expect(planFor({affectedJson}).monorepo).toBe(true);
+ }
+
+ const unrelatedJson = affectedForChange(
+ 'packages/unrelated/src/unrelated.ts',
+ );
+ const unrelatedQuery = JSON.parse(unrelatedJson) as {
+ data: {affectedTasks: {items: Array<{fullName: string}>}};
+ };
+ expect(
+ unrelatedQuery.data.affectedTasks.items.map((task) => task.fullName),
+ ).not.toContain('@remotion/it-tests#testmonorepo');
+ expect(planFor({affectedJson: unrelatedJson}).monorepo).toBe(false);
+ } finally {
+ rmSync(fixture, {force: true, recursive: true});
+ }
+ },
+ {timeout: 30000},
+ );
+});
+
describe('Required CI result validation', () => {
const lambdaPlan = () => planFor({tasks: [{name: 'testlambda'}]});
@@ -173,6 +346,26 @@ describe('Required CI result validation', () => {
},
);
+ test('requires a selected monorepo job to succeed', () => {
+ const plan = planFor({tasks: [{name: 'testmonorepo'}]});
+ const results = skippedResults();
+ results.monorepo = 'success';
+ expect(() => validateRequiredCi(plan, results)).not.toThrow();
+
+ results.monorepo = 'failure';
+ expect(() => validateRequiredCi(plan, results)).toThrow(
+ 'Selected suite monorepo concluded with failure',
+ );
+ });
+
+ test('requires an unselected monorepo job to be skipped', () => {
+ const results = skippedResults();
+ results.monorepo = 'success';
+ expect(() => validateRequiredCi(planFor(), results)).toThrow(
+ 'Unselected suite monorepo concluded with success',
+ );
+ });
+
test('rejects an unselected successful build', () => {
const results = skippedResults();
results.build_job = 'success';
diff --git a/.github/scripts/ci.ts b/.github/scripts/ci.ts
index b306c80bf6..a916ec1814 100644
--- a/.github/scripts/ci.ts
+++ b/.github/scripts/ci.ts
@@ -1,6 +1,6 @@
import {appendFileSync, readFileSync} from 'node:fs';
-export const CI_PLAN_SCHEMA_VERSION = 1;
+export const CI_PLAN_SCHEMA_VERSION = 2;
export type BuildMatrix = {
include: Array<{
@@ -28,6 +28,7 @@ const TASKS_BY_SUITE = {
browser: ['testwebcodecs', 'teste2e'],
webrenderer: ['testwebrenderer', 'testbrowserstudio'],
ssr: ['testssr'],
+ monorepo: ['testmonorepo'],
templates: ['testtemplates'],
build: ['build', 'make', 'test'],
bundle_example: ['bundle-testbed'],
@@ -40,19 +41,21 @@ const BOOLEAN_PLAN_KEYS = [
'browser',
'webrenderer',
'ssr',
+ 'monorepo',
'templates',
'build',
'bundle_example',
] as const;
export type CiPlan = {
- schema_version: 1;
+ schema_version: 2;
full_ci: boolean;
lambda: boolean;
nextjs: boolean;
browser: boolean;
webrenderer: boolean;
ssr: boolean;
+ monorepo: boolean;
templates: boolean;
build: boolean;
bundle_example: boolean;
@@ -85,6 +88,7 @@ const fullPlan = (
browser: true,
webrenderer: true,
ssr: true,
+ monorepo: true,
templates: true,
build: true,
bundle_example: true,
@@ -225,6 +229,7 @@ export const createCiPlan = (input: PlannerInput): CiPlan => {
browser: selected('browser'),
webrenderer: selected('webrenderer'),
ssr: selected('ssr'),
+ monorepo: selected('monorepo'),
templates: selected('templates'),
build,
bundle_example: bundleExample,
@@ -245,6 +250,7 @@ const getSelectedSuites = (plan: CiPlan) => ({
browser: plan.browser,
webrenderer: plan.webrenderer,
ssr: plan.ssr,
+ monorepo: plan.monorepo,
templates: plan.templates,
build_job: plan.build || plan.bundle_example,
});
@@ -259,6 +265,7 @@ export type RequiredCiResults = {
browser: string;
webrenderer: string;
ssr: string;
+ monorepo: string;
templates: string;
build_job: string;
};
@@ -325,6 +332,7 @@ const appendPlanOutputs = (
`browser=${plan.browser}`,
`webrenderer=${plan.webrenderer}`,
`ssr=${plan.ssr}`,
+ `monorepo=${plan.monorepo}`,
`templates=${plan.templates}`,
`build=${plan.build}`,
`bundle_example=${plan.bundle_example}`,
diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml
index ab7f59d41a..5a5a0c392f 100644
--- a/.github/workflows/push.yml
+++ b/.github/workflows/push.yml
@@ -28,6 +28,7 @@ jobs:
browser: ${{ steps.query.outputs.browser }}
webrenderer: ${{ steps.query.outputs.webrenderer }}
ssr: ${{ steps.query.outputs.ssr }}
+ monorepo: ${{ steps.query.outputs.monorepo }}
templates: ${{ steps.query.outputs.templates }}
build: ${{ steps.query.outputs.build }}
build_matrix: ${{ steps.query.outputs.build_matrix }}
@@ -154,7 +155,7 @@ jobs:
if: ${{ needs.affected.outputs.ssr == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 30
- name: SSR + Monorepo tests
+ name: SSR tests
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
@@ -165,6 +166,30 @@ jobs:
bun-version: 1.3.3
- name: Install
run: bun ci
+ - name: Cache Turbo
+ uses: rharkor/[email protected]
+ - name: Test SSR
+ timeout-minutes: 15
+ run: |
+ bun run testssr
+ monorepo-tests:
+ needs: affected
+ if: ${{ needs.affected.outputs.monorepo == 'true' }}
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ name: Monorepo tests
+ steps:
+ - uses: actions/checkout@v6
+ - uses: actions/setup-node@v6
+ with:
+ node-version: 16
+ - uses: oven-sh/[email protected]
+ with:
+ bun-version: 1.3.3
+ - name: Setup Go
+ uses: actions/setup-go@v6
+ with:
+ go-version-file: packages/lambda-go/go.mod
- name: Setup Python
uses: actions/setup-python@v6
with:
@@ -177,17 +202,16 @@ jobs:
with:
php-version: '8.4'
tools: none
- - run: pip install pylint boto3 pytest
+ - name: Install Python dependencies
+ run: pip install pylint boto3 pytest
+ - name: Install
+ run: bun ci
- name: Cache Turbo
uses: rharkor/[email protected]
- - name: Test SSR
- timeout-minutes: 15
- run: |
- bun run testssr
- name: Monorepo checks
timeout-minutes: 10
run: |
- cd packages/it-tests && bun test src/monorepo --run --timeout 40000
+ bun run testmonorepo
template-tests:
name: Template integration on ${{ matrix.os }}
needs: affected
@@ -317,6 +341,7 @@ jobs:
- browser-tests
- webrenderer-tests
- ssr-tests
+ - monorepo-tests
- template-tests
runs-on: ubuntu-latest
timeout-minutes: 5
@@ -329,5 +354,5 @@ jobs:
env:
CI_PLAN: ${{ needs.affected.outputs.plan }}
CI_RESULTS: >-
- {"detector":"${{ needs.affected.result }}","lint":"${{ needs.lint.result }}","build_job":"${{ needs.build.result }}","lambda":"${{ needs.lambda-tests.result }}","nextjs":"${{ needs.nextjs-tests.result }}","browser":"${{ needs.browser-tests.result }}","webrenderer":"${{ needs.webrenderer-tests.result }}","ssr":"${{ needs.ssr-tests.result }}","templates":"${{ needs.template-tests.result }}"}
+ {"detector":"${{ needs.affected.result }}","lint":"${{ needs.lint.result }}","build_job":"${{ needs.build.result }}","lambda":"${{ needs.lambda-tests.result }}","nextjs":"${{ needs.nextjs-tests.result }}","browser":"${{ needs.browser-tests.result }}","webrenderer":"${{ needs.webrenderer-tests.result }}","ssr":"${{ needs.ssr-tests.result }}","monorepo":"${{ needs.monorepo-tests.result }}","templates":"${{ needs.template-tests.result }}"}
run: bun .github/scripts/ci.ts validate
diff --git a/package.json b/package.json
index 40a8934ffc..0907a639b2 100644
--- a/package.json
+++ b/package.json
@@ -12,6 +12,7 @@
"build": "turbo run make --no-update-notifier",
"build-docs": "TURBO_TELEMETRY_DISABLED=1 turbo run build-docs --no-update-notifier",
"testssr": "turbo run testssr --no-update-notifier",
+ "testmonorepo": "turbo run testmonorepo --no-update-notifier",
"testtemplates": "turbo run testtemplates --no-update-notifier",
"teste2e": "turbo run teste2e --no-update-notifier",
"testwebcodecs": "turbo run testwebcodecs --no-update-notifier",
diff --git a/packages/it-tests/package.json b/packages/it-tests/package.json
index b028848cca..10c247fa45 100644
--- a/packages/it-tests/package.json
+++ b/packages/it-tests/package.json
@@ -7,7 +7,8 @@
"license": "SEE LICENSE IN LICENSE.md",
"scripts": {
"test": " node --test src/node-version/media-parser.mjs && bun test src/rendering --run --timeout 60000",
- "testssr": "bun test src/ssr src/bundle src/webcodecs src/monorepo --timeout 40000",
+ "testssr": "bun test src/ssr src/bundle src/webcodecs --timeout 40000",
+ "testmonorepo": "bun test src/monorepo --run --timeout 40000",
"testtemplates": "bun test src/templates --timeout 400000",
"testlambda": "exit 0",
"lint": "tsc -d",
diff --git a/turbo.json b/turbo.json
index 49093ab1a5..06bce72515 100644
--- a/turbo.json
+++ b/turbo.json
@@ -15,6 +15,32 @@
"testssr": {
"dependsOn": ["^make", "@remotion/example#bundle"]
},
+ "@remotion/it-tests#testmonorepo": {
+ "dependsOn": ["^make"],
+ "inputs": [
+ "$TURBO_DEFAULT$",
+ "$TURBO_ROOT$/.gitignore",
+ "$TURBO_ROOT$/LICENSE.md",
+ "$TURBO_ROOT$/package.json",
+ "$TURBO_ROOT$/packages/*/.gitignore",
+ "$TURBO_ROOT$/packages/*/.npmignore",
+ "$TURBO_ROOT$/packages/*/LICENSE.md",
+ "$TURBO_ROOT$/packages/*/README.md",
+ "$TURBO_ROOT$/packages/*/package.json",
+ "$TURBO_ROOT$/packages/STATS.md",
+ "$TURBO_ROOT$/packages/cli/src/list-of-remotion-packages.ts",
+ "$TURBO_ROOT$/packages/create-video/src/list-of-remotion-packages.ts",
+ "$TURBO_ROOT$/packages/docs/docs/contributing/index.mdx",
+ "$TURBO_ROOT$/packages/lambda-client/src/aws-provider.ts",
+ "$TURBO_ROOT$/packages/lambda/src/api/create-function.ts",
+ "$TURBO_ROOT$/packages/lambda-go/**",
+ "$TURBO_ROOT$/packages/lambda-php/**",
+ "$TURBO_ROOT$/packages/lambda-php-example/**",
+ "$TURBO_ROOT$/packages/lambda-python/**",
+ "$TURBO_ROOT$/packages/lambda-ruby/**",
+ "$TURBO_ROOT$/packages/studio-shared/src/release-package-policy.ts"
+ ]
+ },
"testtemplates": {
"dependsOn": ["^make", "@remotion/example#bundle"],
"inputs": [