🎥 Make videos programmatically with React
Skills: Add timed PR workflow script
Jonny Burgerb6bbb93e4ce7
diff --git a/.agents/skills/pr/SKILL.md b/.agents/skills/pr/SKILL.mdindex 49936c3dd3..774b362491 100644--- a/.agents/skills/pr/SKILL.md+++ b/.agents/skills/pr/SKILL.md@@ -3,51 +3,35 @@ name: prdescription: Open a pull request for the current feature----Ensure we are not on the main branch, make a branch if necessary.-Check whether a PR already exists for the current branch with `gh pr status` or `gh pr view`. If one exists, update it with local changes.+Ensure we are not on the main branch; make a branch if necessary.Keep new agent-authored tests, including new test cases in existing files, out of the PR unless the user explicitly requested them. Updates to existing tests, fixtures, and snapshots are allowed when needed for the change. Review the diff and preserve pre-existing user changes.If the changes add a Remotion Element, read the [Element contribution guide](../../../packages/docs/elements/contributing.mdx) before continuing.-Run Oxfmt on the files or package directories affected by the current change. Pass their actual paths; do not assume that the repository root has a `src` directory. Include relevant root-level files, and do not format unrelated packages or the whole repository.+Use [`scripts/pr-workflow.ts`](scripts/pr-workflow.ts) for the repeatable PR steps. Pass every changed file explicitly with `--file`, including relevant root-level files. Pass only Oxfmt-supported changed files with `--format`; do not format unrelated packages or the whole repository. If none are supported, omit `--format`.For example:```-bunx oxfmt <changed-file-or-package-directory>... --write+bun .agents/skills/pr/scripts/pr-workflow.ts prepare \+ --file packages/example/src/Example.tsx \+ --format packages/example/src/Example.tsx```-If none of the changed files are supported by Oxfmt, skip this step. Inspect any formatter changes before committing.+`prepare` formats the listed files, runs `bun run build` and `bun run stylecheck`, checks the changed-file list, and prints timings and `REVIEWED_DIFF`. Inspect the full diff and the contents of untracked files, including formatter changes, before publishing. If anything changes afterward, run `prepare` and review again.-Then run+Choose the PR title according to the [`pr-name`](../pr-name/SKILL.md) skill. Write the PR body to a temporary Markdown file in the system temp directory. If the work is tied to a GitHub issue, include a closing keyword such as `Closes #1234`, preserving the issue number or URL the user provided.```-bun run build-bun run stylecheck+bun .agents/skills/pr/scripts/pr-workflow.ts publish \+ --file packages/example/src/Example.tsx \+ --reviewed <REVIEWED_DIFF> \+ --title 'Internal testbed: Describe the change' \+ --body-file /tmp/remotion-pr-body.md```-to ensure we compile and CI linting/formatting passes.--Commit the changes once. The title of the PR must be according to the [`pr-name`](../pr-name/SKILL.md) skill.--Push the changes to the remote branch once, using `git push -u origin HEAD`.--Never force push, unless users asks for it.--Use the `gh` CLI to create a pull request and use the same format as above for the title.--When creating the PR, do not pass the PR body inline through a shell command (for example, avoid `--body "..."` or heredocs in `bash`). Instead:--1. Write the PR body to a temporary Markdown file in the system temp directory (for example `/tmp/remotion-pr-body.md`, or a unique file created under `/tmp`).- - If the current work was started from, fixes, or is otherwise tied to a GitHub issue, include a closing keyword in the PR body such as `Closes #1234` or `Closes https://github.com/owner/repo/issues/1234`. Preserve the issue number or URL from the user's original request if they provided one.-2. Create the PR with `gh pr create --title "<title>" --body-file <path-to-temp-md-file>`.--Example:--```bash-gh pr create --title '`@remotion/package`: Add feature' --body-file /tmp/remotion-pr-body.md-```+`publish` verifies the reviewed diff, checks for an existing PR, commits once, pushes once with `git push -u origin HEAD`, and creates a PR with `gh pr create --body-file` if needed. It preserves an existing PR's title and body. Never force push unless the user asks. If publishing stops after a commit or push, inspect the branch and PR before retrying so those operations are not repeated blindly.## Link directly changed website pagesdiff --git a/.agents/skills/pr/scripts/pr-workflow.ts b/.agents/skills/pr/scripts/pr-workflow.tsnew file mode 100644index 0000000000..224b044c34--- /dev/null+++ b/.agents/skills/pr/scripts/pr-workflow.ts@@ -0,0 +1,260 @@+#!/usr/bin/env bun++import {spawnSync} from 'node:child_process';+import {createHash} from 'node:crypto';+import {existsSync, readFileSync} from 'node:fs';+import {relative, resolve, sep} from 'node:path';+import {performance} from 'node:perf_hooks';++const root = resolve(import.meta.dir, '../../../..');+const started = performance.now();+const phase = process.argv[2];+const files: string[] = [];+const format: string[] = [];+let title: string | null = null;+let bodyFile: string | null = null;+let reviewed: string | null = null;++const usage = () => {+ console.log(`Usage:+ bun .agents/skills/pr/scripts/pr-workflow.ts prepare --file <path>... [--format <path>...]+ bun .agents/skills/pr/scripts/pr-workflow.ts publish --file <path>... --reviewed <sha256> --title <title> --body-file <path>++Pass every changed repository file with --file. Pass only Oxfmt-supported files with --format.+Review the full diff after prepare, then pass its REVIEWED_DIFF value to publish.`);+};++const fail = (message: string): never => {+ throw new Error(message);+};++const repositoryPath = (value: string) => {+ const absolute = resolve(root, value);+ const path = relative(root, absolute);+ if (!path || path === '..' || path.startsWith(`..${sep}`)) {+ fail(`Expected a file path inside the repository: ${value}`);+ }++ return path;+};++const command = (label: string, executable: string, args: string[]) => {+ const before = performance.now();+ const result = spawnSync(executable, args, {cwd: root, stdio: 'inherit'});+ console.log(+ `[pr] ${label}: ${((performance.now() - before) / 1000).toFixed(2)}s`,+ );+ if (result.error) {+ fail(`${label}: ${result.error.message}`);+ }++ if (result.status !== 0) {+ fail(`${label} exited with ${result.signal ?? `status ${result.status}`}`);+ }+};++const capture = (executable: string, args: string[]) => {+ const result = spawnSync(executable, args, {+ cwd: root,+ encoding: 'utf8',+ stdio: ['ignore', 'pipe', 'pipe'],+ maxBuffer: 64 * 1024 * 1024,+ });+ if (result.error) {+ fail(`${executable}: ${result.error.message}`);+ }++ return result;+};++const git = (args: string[]) => {+ const result = capture('git', ['-c', 'core.fsmonitor=false', ...args]);+ if (result.status !== 0) {+ fail(`git ${args[0]}: ${result.stderr.trim()}`);+ }++ return result.stdout;+};++const changedFiles = () => {+ const tracked = git(['diff', 'HEAD', '--name-only', '-z']).split('\0');+ const untracked = git([+ 'ls-files',+ '--others',+ '--exclude-standard',+ '-z',+ ]).split('\0');+ return [...new Set([...tracked, ...untracked].filter(Boolean))].sort();+};++const assertFiles = () => {+ const actual = changedFiles();+ const expected = [...new Set(files)].sort();+ if (actual.join('\0') !== expected.join('\0')) {+ fail(+ `Changed files differ from --file arguments.\nExpected: ${expected.join(', ') || '(none)'}\nActual: ${actual.join(', ') || '(none)'}`,+ );+ }+};++const reviewDigest = () => {+ const hash = createHash('sha256');+ hash.update(git(['rev-parse', 'HEAD']));+ hash.update(git(['symbolic-ref', '--short', 'HEAD']));+ hash.update(git(['diff', 'HEAD', '--binary', '--no-ext-diff']));+ for (const file of files.sort()) {+ hash.update(file);+ const path = resolve(root, file);+ if (existsSync(path)) {+ hash.update(readFileSync(path));+ } else {+ hash.update('<deleted>');+ }+ }++ return hash.digest('hex');+};++try {+ if (phase === '--help' || phase === undefined) {+ usage();+ process.exit(phase === '--help' ? 0 : 1);+ }++ if (phase !== 'prepare' && phase !== 'publish') {+ fail(`Unknown phase: ${phase}`);+ }++ for (let i = 3; i < process.argv.length; i += 2) {+ const flag = process.argv[i];+ const value = process.argv[i + 1];+ if (!value || value.startsWith('--')) {+ fail(`Missing value for ${flag}`);+ }++ switch (flag) {+ case '--file':+ files.push(repositoryPath(value));+ break;+ case '--format':+ format.push(repositoryPath(value));+ break;+ case '--title':+ title = value;+ break;+ case '--body-file':+ bodyFile = resolve(root, value);+ break;+ case '--reviewed':+ reviewed = value;+ break;+ default:+ fail(`Unknown argument: ${flag}`);+ }+ }++ if (files.length === 0 || files.length !== new Set(files).size) {+ fail('Pass each changed file exactly once with --file.');+ }++ const branch = git(['symbolic-ref', '--short', 'HEAD']).trim();+ if (branch === 'main' || branch === 'master') {+ fail('Create a feature branch before running the PR workflow.');+ }++ assertFiles();++ if (phase === 'prepare') {+ if (title !== null || bodyFile !== null || reviewed !== null) {+ fail('Title, body file, and reviewed digest belong to publish.');+ }++ if (format.some((file) => !files.includes(file))) {+ fail('Every --format path must also be passed with --file.');+ }++ if (format.length > 0) {+ command('format', 'bunx', ['oxfmt', ...format, '--write']);+ }++ assertFiles();+ command('build', 'bun', ['run', 'build']);+ command('stylecheck', 'bun', ['run', 'stylecheck']);+ git(['diff', 'HEAD', '--check']);+ assertFiles();+ console.log(`REVIEWED_DIFF=${reviewDigest()}`);+ } else {+ if (format.length > 0) {+ fail('Formatting belongs to prepare.');+ }++ if (!title || !bodyFile || !reviewed || !existsSync(bodyFile)) {+ fail(+ 'Publish requires --title, an existing --body-file, and --reviewed.',+ );+ }++ if (reviewDigest() !== reviewed) {+ fail('The diff changed after prepare. Run prepare and review it again.');+ }++ const existing = capture('gh', [+ 'pr',+ 'view',+ '--json',+ 'url',+ '--jq',+ '.url',+ ]);+ if (+ existing.status !== 0 &&+ !existing.stderr.includes('no pull requests found')+ ) {+ fail(`Could not check for an existing PR: ${existing.stderr.trim()}`);+ }++ command('stage', 'git', ['add', '--', ...files]);+ if (git(['diff', '--cached', '--name-only']).trim() === '') {+ fail('No staged changes to commit.');+ }++ command('commit', 'git', ['commit', '-m', title]);+ if (changedFiles().length > 0) {+ fail(+ 'The commit hook left uncommitted changes. Review them before pushing.',+ );+ }++ command('push', 'git', ['push', '-u', 'origin', 'HEAD']);+ if (existing.status === 0) {+ console.log(`PR_URL=${existing.stdout.trim()}`);+ } else {+ const before = performance.now();+ const created = capture('gh', [+ 'pr',+ 'create',+ '--title',+ title,+ '--body-file',+ bodyFile,+ ]);+ console.log(+ `[pr] create: ${((performance.now() - before) / 1000).toFixed(2)}s`,+ );+ if (created.status !== 0) {+ fail(`Could not create PR: ${created.stderr.trim()}`);+ }++ console.log(`PR_URL=${created.stdout.trim()}`);+ }+ }++ console.log(+ `[pr] total: ${((performance.now() - started) / 1000).toFixed(2)}s`,+ );+} catch (error) {+ console.error(+ `[pr] ${error instanceof Error ? error.message : String(error)}`,+ );+ process.exit(1);+}