From 24a131c081c7e87a48debda047aac0137248c4f4 Mon Sep 17 00:00:00 2001 From: "Artem Viter (ardmn)" Date: Thu, 26 Nov 2026 01:33:49 +0400 Subject: [PATCH 1/2] ci: skip the macOS iOS build when the change cannot affect it GitHub's macOS arm64 runners are scarce: build-ios was cancelled with "not acquired" on main and on Dependabot PRs. A Linux job now decides from the changed files: build-ios is skipped only when every file is documentation, Android, the Kotlin converter, e2e flows or bot config; anything else, an unknown range or the merge queue builds iOS. A skipped job does not fail the run, so the release gate is unchanged, and a release commit changes package.json and always builds. Decision: paths-ignore on the workflow would also skip the Linux gates; the existing turbo cache skip still allocates a macOS runner. A small Linux decision job keeps everything else as it is. --- .github/workflows/ci.yml | 37 +++++++++++++++ scripts/__tests__/ios-affected.test.ts | 60 +++++++++++++++++++++++ scripts/ios-affected.ts | 66 ++++++++++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 scripts/__tests__/ios-affected.test.ts create mode 100644 scripts/ios-affected.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77ce16a..866703e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,41 @@ permissions: contents: read jobs: + # Decides whether the change can affect the iOS build, so build-ios (macOS: scarce, slow runners) + # runs only when it can. Conservative: see scripts/ios-affected.ts. A skipped job does not fail + # the run, so the release gate (CI passed for the tagged commit) is unaffected; a release commit + # changes package.json and always builds iOS. + changes: + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + ios: ${{ steps.ios.outputs.ios }} + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Setup Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .nvmrc + + - name: Can the change affect the iOS build? + id: ios + env: + EVENT: ${{ github.event_name }} + PR_BASE: ${{ github.event.pull_request.base.sha }} + PR_HEAD: ${{ github.event.pull_request.head.sha }} + PUSH_BEFORE: ${{ github.event.before }} + run: | + case "$EVENT" in + pull_request) node scripts/ios-affected.ts "$PR_BASE" "$PR_HEAD" ;; + push) node scripts/ios-affected.ts "$PUSH_BEFORE" "$GITHUB_SHA" ;; + *) echo "ios=true" | tee -a "$GITHUB_OUTPUT" ;; # merge queue and anything else: build + esac + lint: runs-on: ubuntu-latest @@ -343,6 +378,8 @@ jobs: yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --concurrency=1 build-ios: + needs: changes + if: needs.changes.outputs.ios == 'true' runs-on: macos-latest env: diff --git a/scripts/__tests__/ios-affected.test.ts b/scripts/__tests__/ios-affected.test.ts new file mode 100644 index 0000000..82ad90c --- /dev/null +++ b/scripts/__tests__/ios-affected.test.ts @@ -0,0 +1,60 @@ +import assert from 'node:assert/strict'; +import { execFileSync } from 'node:child_process'; +import { join } from 'node:path'; +import { test } from 'node:test'; +import { iosAffected } from '../ios-affected.ts'; +import { ROOT } from '../lib.ts'; + +await test('only documentation, Android and tooling changes skip the iOS build', () => { + assert.equal( + iosAffected([ + 'README.md', + 'docs/preview.jpg', + 'android/src/main/java/com/remotecompose/RemoteComposeViewManager.kt', + 'example/android/app/build.gradle', + 'tools/remote-compose-json/build.gradle.kts', + 'e2e/ios/flow.yaml', + '.github/dependabot.yml', + ]), + false + ); +}); + +await test('any file the iOS build may read runs it', () => { + for (const path of [ + 'ios/HostValue.swift', + 'ios/RemoteComposeView.mm', + 'RemoteCompose.podspec', + 'src/index.tsx', + 'package.json', + 'yarn.lock', + 'example/ios/Podfile.lock', + 'example/src/App.tsx', + 'example-shared/src/screens/Host.tsx', + 'example/assets/product_card.rc', + '.github/workflows/ci.yml', // a CI change must run the job it changes + 'app.plugin.js', + 'turbo.json', + ]) { + assert.equal(iosAffected(['README.md', path]), true, path); + } +}); + +await test('an empty change runs the build rather than skipping it', () => { + assert.equal(iosAffected([]), true); +}); + +await test('the CLI runs the build for an unknown range and writes the step output', () => { + const script = join(ROOT, 'scripts', 'ios-affected.ts'); + const run = (...args: string[]) => + execFileSync(process.execPath, [script, ...args], { + cwd: ROOT, + encoding: 'utf8', + }); + assert.match( + run('0000000000000000000000000000000000000000', 'HEAD'), + /^ios=true \(range/ + ); + assert.match(run('', ''), /^ios=true \(range/); + assert.match(run('HEAD', 'HEAD'), /^ios=true \(0 files\)/); +}); diff --git a/scripts/ios-affected.ts b/scripts/ios-affected.ts new file mode 100644 index 0000000..0ed6420 --- /dev/null +++ b/scripts/ios-affected.ts @@ -0,0 +1,66 @@ +/** + * Whether a change can affect the iOS build, so CI can skip the macOS job (scarce, slow runners) + * when it cannot. Conservative: the job is skipped only when EVERY changed file matches a path + * that the iOS build provably does not read; anything else, an empty list, or an unknown range + * runs it. + * + * node scripts/ios-affected.ts # prints ios=true|false, also to $GITHUB_OUTPUT + */ +import { execFileSync } from 'node:child_process'; +import { appendFileSync } from 'node:fs'; + +/** Paths the iOS example build and the Swift unit tests never read. */ +const IOS_IRRELEVANT: readonly RegExp[] = [ + /\.md$/, // documentation anywhere + /^docs\//, + /^android\//, // the library's Android module + /^example\/android\//, + /^example-expo\/android\//, + /^tools\//, // the Kotlin JSON -> .rc converter; generated documents are committed separately + /^e2e\//, // Maestro flows, run on devices, not in CI's iOS build + /^detekt\.yml$/, + /^LICENSE$/, + /^\.github\/dependabot\.yml$/, + /^\.github\/ISSUE_TEMPLATE\//, +]; + +/** True unless every path is known not to affect the iOS build. An empty list runs the build. */ +export function iosAffected(paths: readonly string[]): boolean { + if (paths.length === 0) return true; + return paths.some( + (path) => !IOS_IRRELEVANT.some((pattern) => pattern.test(path)) + ); +} + +/** A range git cannot resolve (a new branch's all-zero `before`) means "run the build". */ +function changedFiles(base: string, head: string): string[] | null { + if (!base || !head || /^0+$/.test(base)) return null; + try { + const out = execFileSync( + 'git', + ['diff', '--name-only', `${base}...${head}`], + { + encoding: 'utf8', + } + ); + return out.split('\n').filter(Boolean); + } catch { + return null; + } +} + +if (import.meta.main) { + const [base = '', head = ''] = process.argv.slice(2); + const files = changedFiles(base, head); + const affected = files === null ? true : iosAffected(files); + const line = `ios=${String(affected)}`; + console.log( + files === null + ? `${line} (range ${base}...${head} unknown)` + : `${line} (${files.length} files)` + ); + // unknown: process.env's values are `any` in this repository's TypeScript program. + const output: unknown = process.env.GITHUB_OUTPUT; + if (typeof output === 'string' && output !== '') + appendFileSync(output, `${line}\n`); +} From 43bf57be662af9fd1b3d4f677220d045b9908e37 Mon Sep 17 00:00:00 2001 From: "Artem Viter (ardmn)" Date: Thu, 26 Nov 2026 01:40:51 +0400 Subject: [PATCH 2/2] ci: build iOS on every push to main; skip only in pull requests Review: a quick second push to main cancelled the first run and skipped its iOS change, main could show green over a broken iOS build, and the release gate could pass on a tag whose commit skipped iOS (v0.1.0 was such a tag). Pushes and the merge queue now always build. Also: renames count both paths (--no-renames), only top-level Markdown is skipped, and a test fails if any tracked turbo build:ios input would be skipped. --- .github/workflows/ci.yml | 19 +++-- scripts/__tests__/ios-affected.test.ts | 103 +++++++++++++++++++++---- scripts/ios-affected.ts | 33 +++++--- 3 files changed, 116 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 866703e..7de1ed7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,10 +20,10 @@ permissions: contents: read jobs: - # Decides whether the change can affect the iOS build, so build-ios (macOS: scarce, slow runners) - # runs only when it can. Conservative: see scripts/ios-affected.ts. A skipped job does not fail - # the run, so the release gate (CI passed for the tagged commit) is unaffected; a release commit - # changes package.json and always builds iOS. + # Decides whether a pull request can affect the iOS build, so build-ios (macOS: scarce, slow + # runners) runs only when it can. Conservative: see scripts/ios-affected.ts. Every push to main + # builds iOS, so main's status, a run cancelled by a later push, and the release gate (CI passed + # for the tagged commit, which is on main) never rest on a skipped build. changes: runs-on: ubuntu-latest timeout-minutes: 5 @@ -47,13 +47,12 @@ jobs: EVENT: ${{ github.event_name }} PR_BASE: ${{ github.event.pull_request.base.sha }} PR_HEAD: ${{ github.event.pull_request.head.sha }} - PUSH_BEFORE: ${{ github.event.before }} run: | - case "$EVENT" in - pull_request) node scripts/ios-affected.ts "$PR_BASE" "$PR_HEAD" ;; - push) node scripts/ios-affected.ts "$PUSH_BEFORE" "$GITHUB_SHA" ;; - *) echo "ios=true" | tee -a "$GITHUB_OUTPUT" ;; # merge queue and anything else: build - esac + if [ "$EVENT" = pull_request ]; then + node scripts/ios-affected.ts "$PR_BASE" "$PR_HEAD" + else + echo "ios=true" | tee -a "$GITHUB_OUTPUT" # push to main, merge queue: always build + fi lint: runs-on: ubuntu-latest diff --git a/scripts/__tests__/ios-affected.test.ts b/scripts/__tests__/ios-affected.test.ts index 82ad90c..f033359 100644 --- a/scripts/__tests__/ios-affected.test.ts +++ b/scripts/__tests__/ios-affected.test.ts @@ -1,26 +1,60 @@ import assert from 'node:assert/strict'; import { execFileSync } from 'node:child_process'; -import { join } from 'node:path'; +import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { dirname, join } from 'node:path'; import { test } from 'node:test'; -import { iosAffected } from '../ios-affected.ts'; +import { changedFiles, iosAffected } from '../ios-affected.ts'; import { ROOT } from '../lib.ts'; +const git = (cwd: string, ...args: string[]) => + execFileSync('git', args, { cwd, encoding: 'utf8' }).trim(); + +/** A throwaway repository: one commit per `{path: text}` map; returns each commit's SHA. */ +function scratchRepo(...commits: Record[]): { + dir: string; + shas: string[]; +} { + const dir = mkdtempSync(join(tmpdir(), 'ios-affected-')); + git(dir, 'init', '-q', '-b', 'main'); + git(dir, 'config', 'user.email', 'test@example.com'); + git(dir, 'config', 'user.name', 'test'); + git(dir, 'config', 'commit.gpgsign', 'false'); + const shas: string[] = []; + for (const files of commits) { + for (const [path, text] of Object.entries(files)) { + if (text === null) { + git(dir, 'rm', '-q', path); + } else { + mkdirSync(dirname(join(dir, path)), { recursive: true }); + writeFileSync(join(dir, path), text); + git(dir, 'add', path); + } + } + git(dir, 'commit', '-q', '--no-verify', '-m', 'c'); + shas.push(git(dir, 'rev-parse', 'HEAD')); + } + return { dir, shas }; +} + await test('only documentation, Android and tooling changes skip the iOS build', () => { assert.equal( iosAffected([ 'README.md', + 'CONTRIBUTING.md', 'docs/preview.jpg', 'android/src/main/java/com/remotecompose/RemoteComposeViewManager.kt', 'example/android/app/build.gradle', + 'example-expo/android/app/build.gradle', 'tools/remote-compose-json/build.gradle.kts', - 'e2e/ios/flow.yaml', + 'e2e/flows/host-values.yaml', '.github/dependabot.yml', ]), false ); }); -await test('any file the iOS build may read runs it', () => { +await test('any file the iOS build may read runs it, including near misses', () => { for (const path of [ 'ios/HostValue.swift', 'ios/RemoteComposeView.mm', @@ -29,10 +63,13 @@ await test('any file the iOS build may read runs it', () => { 'package.json', 'yarn.lock', 'example/ios/Podfile.lock', + 'example-expo/ios/Podfile', // only example-expo/android is irrelevant + 'example/README.md', // a turbo build:ios input; only top-level Markdown is skipped + 'ios/Tests/NOTES.md', 'example/src/App.tsx', 'example-shared/src/screens/Host.tsx', - 'example/assets/product_card.rc', '.github/workflows/ci.yml', // a CI change must run the job it changes + '.github/actions/setup/action.yml', 'app.plugin.js', 'turbo.json', ]) { @@ -44,17 +81,49 @@ await test('an empty change runs the build rather than skipping it', () => { assert.equal(iosAffected([]), true); }); -await test('the CLI runs the build for an unknown range and writes the step output', () => { - const script = join(ROOT, 'scripts', 'ios-affected.ts'); - const run = (...args: string[]) => - execFileSync(process.execPath, [script, ...args], { - cwd: ROOT, - encoding: 'utf8', - }); - assert.match( - run('0000000000000000000000000000000000000000', 'HEAD'), - /^ios=true \(range/ +await test('no tracked file that turbo counts as a build:ios input is ever skipped', () => { + // turbo.json build:ios: the example apps' own files except android/, plus these root paths. + const turboInput = + /^(example|example-expo)\/(?!android\/)|^(package\.json|yarn\.lock|app\.plugin\.js|react-native\.config\.js|[^/]+\.podspec)$|^(src|plugin|example-shared|ios)\//; + const tracked = git(ROOT, 'ls-files').split('\n'); + const wronglySkipped = tracked.filter( + (path) => turboInput.test(path) && !iosAffected([path]) + ); + assert.deepEqual(wronglySkipped, []); +}); + +await test('a real range: docs only skips, a moved iOS file and an iOS edit build', () => { + const { dir, shas } = scratchRepo( + { 'README.md': 'a', 'ios/fixture.json': '{}' }, + { 'README.md': 'b' }, // docs only + { 'ios/fixture.json': null, 'docs/fixture.json': '{}' }, // moved out of ios/ + { 'ios/HostValue.swift': 'let x = 1' } // iOS edit ); - assert.match(run('', ''), /^ios=true \(range/); - assert.match(run('HEAD', 'HEAD'), /^ios=true \(0 files\)/); + const [first, docs, moved, edit] = shas as [string, string, string, string]; + assert.deepEqual(changedFiles(first, docs, dir), ['README.md']); + assert.equal(iosAffected(changedFiles(first, docs, dir) ?? []), false); + const movedFiles = changedFiles(docs, moved, dir) ?? []; + assert.ok(movedFiles.includes('ios/fixture.json'), movedFiles.join(',')); + assert.equal(iosAffected(movedFiles), true); + assert.equal(iosAffected(changedFiles(moved, edit, dir) ?? []), true); + assert.equal(changedFiles('0'.repeat(40), edit, dir), null); +}); + +await test('the CLI writes its decision to GITHUB_OUTPUT', () => { + const { dir, shas } = scratchRepo({ 'README.md': 'a' }, { 'README.md': 'b' }); + const output = join(dir, 'github-output'); + writeFileSync(output, ''); + const run = (...args: string[]) => + execFileSync( + process.execPath, + [join(ROOT, 'scripts', 'ios-affected.ts'), ...args], + { + cwd: dir, + encoding: 'utf8', + env: { ...process.env, GITHUB_OUTPUT: output }, + } + ); + assert.match(run(shas[0] ?? '', shas[1] ?? ''), /^ios=false \(1 files\)/); + assert.match(run('0'.repeat(40), 'HEAD'), /^ios=true \(range/); + assert.equal(readFileSync(output, 'utf8'), 'ios=false\nios=true\n'); }); diff --git a/scripts/ios-affected.ts b/scripts/ios-affected.ts index 0ed6420..3e720a1 100644 --- a/scripts/ios-affected.ts +++ b/scripts/ios-affected.ts @@ -1,17 +1,20 @@ /** - * Whether a change can affect the iOS build, so CI can skip the macOS job (scarce, slow runners) - * when it cannot. Conservative: the job is skipped only when EVERY changed file matches a path - * that the iOS build provably does not read; anything else, an empty list, or an unknown range - * runs it. + * Whether a pull request can affect the iOS build, so CI can skip the macOS job (scarce, slow + * runners) when it cannot. Conservative: the job is skipped only when EVERY changed file matches a + * path that the iOS build provably does not read; anything else, an empty list, or an unknown range + * builds. Pushes to main always build (see ci.yml), so main and every release are always proven. * * node scripts/ios-affected.ts # prints ios=true|false, also to $GITHUB_OUTPUT + * + * The iOS build reads what turbo.json's `build:ios` inputs list; a test checks that no tracked file + * those inputs cover is ever treated as irrelevant here. */ import { execFileSync } from 'node:child_process'; import { appendFileSync } from 'node:fs'; /** Paths the iOS example build and the Swift unit tests never read. */ -const IOS_IRRELEVANT: readonly RegExp[] = [ - /\.md$/, // documentation anywhere +export const IOS_IRRELEVANT: readonly RegExp[] = [ + /^[^/]+\.md$/, // top-level documentation (README, CONTRIBUTING, ...) /^docs\//, /^android\//, // the library's Android module /^example\/android\//, @@ -32,16 +35,22 @@ export function iosAffected(paths: readonly string[]): boolean { ); } -/** A range git cannot resolve (a new branch's all-zero `before`) means "run the build". */ -function changedFiles(base: string, head: string): string[] | null { +/** + * The files changed between the merge base of `base` and `head`, with both sides of a rename + * (`--no-renames`), so moving an iOS file into an ignored folder still counts. A range git cannot + * resolve (a new branch's all-zero `before`, history not fetched) means "run the build". + */ +export function changedFiles( + base: string, + head: string, + cwd?: string +): string[] | null { if (!base || !head || /^0+$/.test(base)) return null; try { const out = execFileSync( 'git', - ['diff', '--name-only', `${base}...${head}`], - { - encoding: 'utf8', - } + ['diff', '--name-only', '--no-renames', `${base}...${head}`], + { cwd, encoding: 'utf8' } ); return out.split('\n').filter(Boolean); } catch {