From 48834769b799fe31ad0b4757982ba901e3633598 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Thu, 19 Nov 2026 11:20:00 +0000 Subject: [PATCH] [CI] Reuse iOS template app builds across E2E retries --- .../__tests__/template-app-ci-state-test.js | 277 ++++++++++++++++++ .../workflow-scripts/template-app-ci-state.js | 131 +++++++++ .github/workflows/build-ios-templateapp.yml | 149 ++++++++++ .github/workflows/e2e-ios-templateapp.yml | 167 +++++------ .github/workflows/test-all.yml | 51 +++- 5 files changed, 673 insertions(+), 102 deletions(-) create mode 100644 .github/workflow-scripts/__tests__/template-app-ci-state-test.js create mode 100644 .github/workflow-scripts/template-app-ci-state.js create mode 100644 .github/workflows/build-ios-templateapp.yml diff --git a/.github/workflow-scripts/__tests__/template-app-ci-state-test.js b/.github/workflow-scripts/__tests__/template-app-ci-state-test.js new file mode 100644 index 00000000000..7868340994d --- /dev/null +++ b/.github/workflow-scripts/__tests__/template-app-ci-state-test.js @@ -0,0 +1,277 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @noflow + * @format + */ + +const { + configurationResults, + prepareTestState, + recordConfigurationResult, + reportConfigurationResults, +} = require('../template-app-ci-state'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); + +const bothFlavors = ['Debug', 'Release']; + +function results(outputs, flavors = bothFlavors, previousResults = {}) { + return configurationResults({outputs, flavors, previousResults}); +} + +describe('template app configuration retries', () => { + it('does not retry when both configurations pass', () => { + expect( + results({'debug-result': 'passed', 'release-result': 'passed'}), + ).toEqual({ + results: {Debug: 'passed', Release: 'passed'}, + failedFlavors: [], + status: 'success', + }); + }); + + it.each(bothFlavors)('retries only the failed %s configuration', flavor => { + const outputs = {'debug-result': 'passed', 'release-result': 'passed'}; + outputs[`${flavor.toLowerCase()}-result`] = 'failed'; + expect(results(outputs).failedFlavors).toEqual([flavor]); + }); + + it('retains a successful build while retrying the other configuration', () => { + const first = results({ + 'debug-result': 'passed', + 'release-result': 'failed', + }); + const second = results( + {'release-result': 'passed'}, + first.failedFlavors, + first.results, + ); + expect(second.status).toBe('success'); + expect(second.results).toEqual({Debug: 'passed', Release: 'passed'}); + }); + + it('keeps a configuration retryable after its result step is lost', () => { + const first = results({'debug-result': 'passed'}); + const second = results({}, first.failedFlavors, first.results); + expect(second).toEqual({ + results: {Debug: 'passed', Release: 'failed'}, + failedFlavors: ['Release'], + status: 'failure', + }); + }); + + it('does not reuse an old pass for a configuration attempted again', () => { + expect( + results({}, ['Debug'], {Debug: 'passed', Release: 'passed'}), + ).toEqual({ + results: {Debug: 'failed', Release: 'passed'}, + failedFlavors: ['Debug'], + status: 'failure', + }); + }); + + it('never treats an omitted configuration without an earlier pass as passed', () => { + expect( + results({'release-result': 'passed'}, ['Release']).failedFlavors, + ).toEqual(['Debug']); + }); + + it.each([[], ['Debug', 'Debug'], ['Profile'], 'Debug'])( + 'rejects an invalid retry matrix %p', + flavors => { + expect(() => results({}, flavors)).toThrow('unique Debug/Release'); + }, + ); + + it('writes independent outputs for both matrix legs', () => { + const core = {setOutput: jest.fn()}; + recordConfigurationResult({core, flavor: 'Release', passed: false}); + recordConfigurationResult({core, flavor: 'Debug', passed: true}); + expect(core.setOutput.mock.calls).toEqual([ + ['release-result', 'failed'], + ['debug-result', 'passed'], + ]); + }); + + it('rejects an unknown configuration when recording results', () => { + expect(() => + recordConfigurationResult({ + core: {setOutput: jest.fn()}, + flavor: 'Profile', + passed: true, + }), + ).toThrow('Unknown template app configuration'); + }); +}); + +describe('template app final reporting', () => { + function core() { + const result = { + setOutput: jest.fn(), + setFailed: jest.fn(), + warning: jest.fn(), + summary: {addRaw: jest.fn(), write: jest.fn().mockResolvedValue()}, + }; + result.summary.addRaw.mockReturnValue(result.summary); + return result; + } + + async function report(jobResult, outputs, failOnError = false) { + const result = core(); + await reportConfigurationResults({ + context: { + serverUrl: 'https://github.com', + repo: {owner: 'react', repo: 'react-native'}, + runId: 1, + }, + core: result, + needs: {test: {result: jobResult, outputs}}, + job: 'test', + flavors: ['Release'], + previousResults: {Debug: 'passed', Release: 'failed'}, + failOnError, + attempt: 1, + }); + return result; + } + + it('reports success after the previously unsuccessful lane passes', async () => { + const result = await report('success', {'release-result': 'passed'}, true); + expect(result.setOutput).toHaveBeenCalledWith('status', 'success'); + expect(result.setOutput).toHaveBeenCalledWith('failed-flavors', '[]'); + expect(result.setFailed).not.toHaveBeenCalled(); + }); + + it('reports intermediate failures without failing the report job', async () => { + const result = await report('success', {'release-result': 'failed'}); + expect(result.setOutput).toHaveBeenCalledWith('status', 'failure'); + expect(result.setOutput).toHaveBeenCalledWith( + 'failed-flavors', + '["Release"]', + ); + expect(result.setFailed).not.toHaveBeenCalled(); + expect(result.warning).toHaveBeenCalled(); + }); + + it('fails the final attempt when a configuration still has not passed', async () => { + const result = await report('success', {'release-result': 'failed'}, true); + expect(result.setFailed).toHaveBeenCalled(); + }); + + it.each(['failure', 'cancelled', 'skipped'])( + 'does not hide a %s matrix job behind a passed result output', + async jobResult => { + const result = await report( + jobResult, + {'release-result': 'passed'}, + true, + ); + expect(result.setOutput).toHaveBeenCalledWith('status', 'failure'); + expect(result.setOutput).toHaveBeenCalledWith( + 'failed-flavors', + '["Release"]', + ); + expect(result.setFailed).toHaveBeenCalled(); + }, + ); + + it('treats missing app/setup results as failure on the final attempt', async () => { + const result = await report('failure', {}, true); + expect(result.setFailed).toHaveBeenCalledWith( + expect.stringContaining('job failure'), + ); + }); +}); + +describe('template app per-flow state', () => { + let directory; + let flowsDirectory; + let statePath; + let first; + let second; + + beforeEach(() => { + directory = fs.mkdtempSync(path.join(os.tmpdir(), 'template-app-ci-test-')); + flowsDirectory = path.join(directory, 'flows'); + fs.mkdirSync(flowsDirectory); + first = path.join(flowsDirectory, 'first.yml'); + second = path.join(flowsDirectory, 'second.yaml'); + fs.writeFileSync(first, 'appId: x\n---\n- launchApp\n'); + fs.writeFileSync(second, 'appId: x\n---\n- launchApp\n'); + statePath = path.join(directory, 'results.json'); + }); + + afterEach(() => { + fs.rmSync(directory, {recursive: true, force: true}); + }); + + function writeState(states) { + const flows = Object.fromEntries( + states.map(([flow, status]) => [ + path.relative(process.cwd(), flow).split(path.sep).join('/'), + {status, attempts: 1}, + ]), + ); + fs.writeFileSync(statePath, JSON.stringify({version: 1, flows})); + } + + it('runs the flows when the state artifact is missing', () => { + expect(prepareTestState(statePath, flowsDirectory)).toBe(true); + }); + + it('skips execution only when every expected flow has passed', () => { + writeState([ + [first, 'passed'], + [second, 'passed'], + ]); + expect(prepareTestState(statePath, flowsDirectory)).toBe(false); + }); + + it.each(['failed', 'pending'])( + 'runs unfinished flows with status %s', + status => { + writeState([ + [first, 'passed'], + [second, status], + ]); + expect(prepareTestState(statePath, flowsDirectory)).toBe(true); + }, + ); + + it('does not skip a flow missing from an otherwise successful state', () => { + writeState([[first, 'passed']]); + expect(prepareTestState(statePath, flowsDirectory)).toBe(true); + }); + + it('ignores helper flows, which are not independently executed', () => { + const helpers = path.join(flowsDirectory, 'helpers'); + fs.mkdirSync(helpers); + fs.writeFileSync(path.join(helpers, 'fragment.yml'), '- tapOn: x'); + writeState([ + [first, 'passed'], + [second, 'passed'], + ]); + expect(prepareTestState(statePath, flowsDirectory)).toBe(false); + }); + + it.each(['{invalid', 'null', '{"version":2,"flows":{}}'])( + 'discards invalid downloaded state %s before executing Maestro', + state => { + fs.writeFileSync(statePath, state); + expect(prepareTestState(statePath, flowsDirectory)).toBe(true); + expect(fs.existsSync(statePath)).toBe(false); + }, + ); + + it('does not interpret an empty flow directory as successful coverage', () => { + fs.unlinkSync(first); + fs.unlinkSync(second); + writeState([]); + expect(prepareTestState(statePath, flowsDirectory)).toBe(true); + }); +}); diff --git a/.github/workflow-scripts/template-app-ci-state.js b/.github/workflow-scripts/template-app-ci-state.js new file mode 100644 index 00000000000..f93ec4b3d15 --- /dev/null +++ b/.github/workflow-scripts/template-app-ci-state.js @@ -0,0 +1,131 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @noflow + * @format + */ + +const {collectFlows, loadState} = require('./maestro-ios'); +const {reportTestResults} = require('./report-test-results'); +const fs = require('node:fs'); +const path = require('node:path'); + +const FLAVORS = ['Debug', 'Release']; + +function recordConfigurationResult({core, flavor, passed}) { + if (!FLAVORS.includes(flavor)) { + throw new Error(`Unknown template app configuration: ${flavor}`); + } + // Each matrix leg writes only its own result, so a passing leg cannot + // overwrite the failure of another configuration. + core.setOutput( + `${flavor.toLowerCase()}-result`, + passed ? 'passed' : 'failed', + ); +} + +function configurationResults({flavors, previousResults, outputs}) { + if ( + !Array.isArray(flavors) || + flavors.length === 0 || + flavors.some(flavor => !FLAVORS.includes(flavor)) || + new Set(flavors).size !== flavors.length + ) { + throw new Error( + 'Expected a non-empty array of unique Debug/Release configurations', + ); + } + + const results = Object.fromEntries( + FLAVORS.map(flavor => { + const result = flavors.includes(flavor) + ? outputs[`${flavor.toLowerCase()}-result`] + : previousResults[flavor]; + // Missing results include runner/setup/reporting failures. They must + // remain eligible for another attempt rather than becoming a pass. + return [flavor, result === 'passed' ? 'passed' : 'failed']; + }), + ); + const failedFlavors = FLAVORS.filter(flavor => results[flavor] !== 'passed'); + return { + results, + failedFlavors, + status: failedFlavors.length === 0 ? 'success' : 'failure', + }; +} + +async function reportConfigurationResults({ + context, + core, + needs, + job, + flavors, + previousResults, + failOnError, + attempt, +}) { + const current = needs[job]; + const result = configurationResults({ + flavors, + previousResults, + outputs: current.outputs ?? {}, + }); + // A failed matrix job also needs a retry if its final result step was lost. + // Configuration results remain authoritative for omitted successful legs. + if (current.result !== 'success' && result.status === 'success') { + for (const flavor of flavors) { + result.results[flavor] = 'failed'; + } + result.failedFlavors = FLAVORS.filter( + flavor => result.results[flavor] !== 'passed', + ); + result.status = 'failure'; + } + core.setOutput('results', JSON.stringify(result.results)); + core.setOutput('failed-flavors', JSON.stringify(result.failedFlavors)); + await reportTestResults({ + context, + core, + needs: { + [job]: { + ...current, + outputs: {...current.outputs, status: result.status}, + }, + }, + failOnError, + attempt, + }); +} + +function prepareTestState(statePath, flowPath) { + let state; + try { + state = loadState(statePath); + } catch { + // A missing/invalid state download is recoverable: execute the flows + // again, and replace malformed JSON before the Maestro runner reads it. + fs.rmSync(statePath, {force: true}); + return true; + } + const flows = collectFlows(flowPath); + return !( + flows.length > 0 && + flows.every(flow => { + const key = path + .relative(process.cwd(), path.resolve(flow)) + .split(path.sep) + .join('/'); + return state.flows[key]?.status === 'passed'; + }) + ); +} + +module.exports = { + configurationResults, + prepareTestState, + recordConfigurationResult, + reportConfigurationResults, +}; diff --git a/.github/workflows/build-ios-templateapp.yml b/.github/workflows/build-ios-templateapp.yml new file mode 100644 index 00000000000..8285dc22af5 --- /dev/null +++ b/.github/workflows/build-ios-templateapp.yml @@ -0,0 +1,149 @@ +name: Build iOS Template App + +permissions: + contents: read + actions: read + +on: + workflow_call: + inputs: + flavors: + description: 'JSON array of configurations to build' + type: string + default: '["Debug", "Release"]' + previous-results: + description: 'Results retained from an earlier build attempt in this run' + type: string + default: '{}' + fail-on-error: + type: boolean + default: false + outputs: + status: + description: 'Whether both configurations have built successfully' + value: ${{ jobs.report.outputs.status }} + results: + description: 'Build results for both configurations, including earlier attempts' + value: ${{ jobs.report.outputs.results }} + failed-flavors: + description: 'JSON array of configurations that still need a successful build' + value: ${{ jobs.report.outputs.failed-flavors }} + +jobs: + build: + runs-on: macos-26 + outputs: + debug-result: ${{ steps.report-status.outputs.debug-result }} + release-result: ${{ steps.report-status.outputs.release-result }} + failure-debug: ${{ steps.report-status.outputs.failure-debug }} + failure-release: ${{ steps.report-status.outputs.failure-release }} + strategy: + fail-fast: false + matrix: + flavor: ${{ fromJSON(inputs.flavors) }} + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Setup node.js + uses: ./.github/actions/setup-node + - name: Run yarn + uses: ./.github/actions/yarn-install + - name: Download React Native Package + uses: ./.github/actions/download-artifact + with: + name: react-native-package + path: /tmp/react-native-tmp + - name: Print /tmp folder + run: ls -lR /tmp/react-native-tmp + - name: Configure git + shell: bash + run: | + git config --global user.email "react-native-bot@meta.com" + git config --global user.name "React Native Bot" + - name: Create the app + run: | + REACT_NATIVE_PKG=$(find /tmp/react-native-tmp -type f -name "*.tgz") + echo "React Native tgs is $REACT_NATIVE_PKG" + + # For stable branches, we want to use the stable branch of the template + # In all the other cases, we want to use "main" + BRANCH=${{ github.ref_name }} + if ! [[ $BRANCH == *-stable* ]]; then + BRANCH=main + fi + + node ./scripts/e2e/init-project-e2e.js --projectName RNTestProject --currentBranch $BRANCH --directory /tmp/RNTestProject --pathToLocalReactNative $REACT_NATIVE_PKG + - name: Download the XCFrameworks built in this run + uses: ./.github/actions/setup-spm-artifacts + with: + working-directory: /tmp/RNTestProject/ios + - name: Convert the app to SwiftPM + working-directory: /tmp/RNTestProject/ios + run: RN_STRICT_API=1 npx react-native spm add --deintegrate --artifacts /tmp/spm-artifacts --download skip + - name: Build the app + working-directory: /tmp/RNTestProject/ios + run: | + xcodebuild \ + -scheme "RNTestProject" \ + -project RNTestProject.xcodeproj \ + -configuration "${{ matrix.flavor }}" \ + -sdk "iphonesimulator" \ + -destination "generic/platform=iOS Simulator" \ + -derivedDataPath "/tmp/RNTestProject" + - name: Verify app supports the arm64 simulator + run: lipo /tmp/RNTestProject/Build/Products/${{ matrix.flavor }}-iphonesimulator/RNTestProject.app/RNTestProject -verify_arch arm64 + - name: Upload app + uses: ./.github/actions/upload-artifact + with: + name: RNTestProject-${{ matrix.flavor }} + overwrite: true + path: /tmp/RNTestProject/Build/Products/${{ matrix.flavor }}-iphonesimulator/RNTestProject.app + - name: Report status + id: report-status + if: always() + uses: actions/github-script@v8 + env: + STEP_RESULTS: ${{ toJSON(steps) }} + JOB_STATUS: ${{ job.status }} + TEST_FLAVOR: ${{ matrix.flavor }} + with: + script: | + const {recordJobFailure} = require('./.github/workflow-scripts/report-test-results'); + const {recordConfigurationResult} = require('./.github/workflow-scripts/template-app-ci-state'); + recordConfigurationResult({core, flavor: process.env.TEST_FLAVOR, + passed: process.env.JOB_STATUS === 'success'}); + await recordJobFailure({github, context, core, + steps: JSON.parse(process.env.STEP_RESULTS), + flavor: process.env.TEST_FLAVOR, + runnerName: process.env.RUNNER_NAME, + jobStatus: process.env.JOB_STATUS, + attempt: Number(process.env.GITHUB_RUN_ATTEMPT)}); + + report: + needs: build + if: ${{ !cancelled() }} + runs-on: ubuntu-latest + outputs: + status: ${{ steps.check.outputs.status }} + results: ${{ steps.check.outputs.results }} + failed-flavors: ${{ steps.check.outputs.failed-flavors }} + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Report configuration results + id: check + uses: actions/github-script@v8 + env: + JOB_RESULTS: ${{ toJSON(needs) }} + FLAVORS: ${{ inputs.flavors }} + PREVIOUS_RESULTS: ${{ inputs.previous-results }} + FAIL_ON_ERROR: ${{ inputs.fail-on-error }} + with: + script: | + const {reportConfigurationResults} = require('./.github/workflow-scripts/template-app-ci-state'); + await reportConfigurationResults({context, core, + needs: JSON.parse(process.env.JOB_RESULTS), job: 'build', + flavors: JSON.parse(process.env.FLAVORS), + previousResults: JSON.parse(process.env.PREVIOUS_RESULTS), + failOnError: process.env.FAIL_ON_ERROR === 'true', + attempt: Number(process.env.GITHUB_RUN_ATTEMPT)}); diff --git a/.github/workflows/e2e-ios-templateapp.yml b/.github/workflows/e2e-ios-templateapp.yml index 5a663512538..6559042828f 100644 --- a/.github/workflows/e2e-ios-templateapp.yml +++ b/.github/workflows/e2e-ios-templateapp.yml @@ -7,118 +7,50 @@ permissions: on: workflow_call: inputs: + flavors: + description: 'JSON array of configurations to test' + type: string + default: '["Debug", "Release"]' + previous-results: + description: 'Results retained from an earlier test attempt in this run' + type: string + default: '{}' + retry-attempt: + type: number + default: 0 fail-on-error: type: boolean default: false outputs: status: - description: 'The result of the E2E tests (success or failure)' + description: 'Whether both configurations have passed E2E' value: ${{ jobs.report.outputs.status }} + results: + description: 'Test results for both configurations, including earlier attempts' + value: ${{ jobs.report.outputs.results }} + failed-flavors: + description: 'JSON array of configurations that still need successful E2E' + value: ${{ jobs.report.outputs.failed-flavors }} jobs: - build: - runs-on: macos-26 - outputs: - failure-debug: ${{ steps.report-status.outputs.failure-debug }} - failure-release: ${{ steps.report-status.outputs.failure-release }} - strategy: - fail-fast: false - matrix: - flavor: [Debug, Release] - steps: - - name: Checkout - uses: actions/checkout@v6 - - name: Setup node.js - uses: ./.github/actions/setup-node - - name: Run yarn - uses: ./.github/actions/yarn-install - - name: Download React Native Package - uses: ./.github/actions/download-artifact - with: - name: react-native-package - path: /tmp/react-native-tmp - - name: Print /tmp folder - run: ls -lR /tmp/react-native-tmp - - name: Configure git - shell: bash - run: | - git config --global user.email "react-native-bot@meta.com" - git config --global user.name "React Native Bot" - - name: Create the app - run: | - REACT_NATIVE_PKG=$(find /tmp/react-native-tmp -type f -name "*.tgz") - echo "React Native tgs is $REACT_NATIVE_PKG" - - # For stable branches, we want to use the stable branch of the template - # In all the other cases, we want to use "main" - BRANCH=${{ github.ref_name }} - if ! [[ $BRANCH == *-stable* ]]; then - BRANCH=main - fi - - node ./scripts/e2e/init-project-e2e.js --projectName RNTestProject --currentBranch $BRANCH --directory /tmp/RNTestProject --pathToLocalReactNative $REACT_NATIVE_PKG - - name: Download the XCFrameworks built in this run - uses: ./.github/actions/setup-spm-artifacts - with: - working-directory: /tmp/RNTestProject/ios - - name: Convert the app to SwiftPM - working-directory: /tmp/RNTestProject/ios - run: RN_STRICT_API=1 npx react-native spm add --deintegrate --artifacts /tmp/spm-artifacts --download skip - - name: Build the app - working-directory: /tmp/RNTestProject/ios - run: | - xcodebuild \ - -scheme "RNTestProject" \ - -project RNTestProject.xcodeproj \ - -configuration "${{ matrix.flavor }}" \ - -sdk "iphonesimulator" \ - -destination "generic/platform=iOS Simulator" \ - -derivedDataPath "/tmp/RNTestProject" - - name: Verify app supports the arm64 simulator - run: lipo /tmp/RNTestProject/Build/Products/${{ matrix.flavor }}-iphonesimulator/RNTestProject.app/RNTestProject -verify_arch arm64 - - name: Upload app - uses: ./.github/actions/upload-artifact - with: - name: RNTestProject-${{ matrix.flavor }} - overwrite: true - path: /tmp/RNTestProject/Build/Products/${{ matrix.flavor }}-iphonesimulator/RNTestProject.app - - name: Report status - id: report-status - if: always() - uses: actions/github-script@v8 - env: - STEP_RESULTS: ${{ toJSON(steps) }} - JOB_STATUS: ${{ job.status }} - TEST_FLAVOR: ${{ matrix.flavor }} - with: - script: | - const {recordJobFailure} = require('./.github/workflow-scripts/report-test-results'); - await recordJobFailure({github, context, core, - steps: JSON.parse(process.env.STEP_RESULTS), - flavor: process.env.TEST_FLAVOR, - runnerName: process.env.RUNNER_NAME, - jobStatus: process.env.JOB_STATUS, - attempt: Number(process.env.GITHUB_RUN_ATTEMPT)}); - test: - needs: build # Standard arm64 runner: run the simulator natively, as RNTester does. runs-on: macos-26 outputs: + debug-result: ${{ steps.report-status.outputs.debug-result }} + release-result: ${{ steps.report-status.outputs.release-result }} status: ${{ steps.report-status.outputs.status }} failure-debug: ${{ steps.report-status.outputs.failure-debug }} failure-release: ${{ steps.report-status.outputs.failure-release }} strategy: fail-fast: false matrix: - flavor: [Debug, Release] + flavor: ${{ fromJSON(inputs.flavors) }} steps: - name: Checkout uses: actions/checkout@v6 - name: Setup node.js uses: ./.github/actions/setup-node - - name: Run yarn - uses: ./.github/actions/yarn-install - name: Download app uses: ./.github/actions/download-artifact with: @@ -126,20 +58,37 @@ jobs: path: /tmp/RNTestProjectBuild/RNTestProject.app - name: Check downloaded folder content run: ls -l /tmp/RNTestProjectBuild/RNTestProject.app + - name: Download previous per-flow test state + if: inputs.retry-attempt > 0 + continue-on-error: true + uses: ./.github/actions/download-artifact + with: + name: e2e_ios_templateapp_state_${{ matrix.flavor }}_${{ github.run_attempt }} + path: /tmp/maestro-ios-state + - name: Check for unfinished E2E flows + id: test-state + uses: actions/github-script@v8 + with: + script: | + const {prepareTestState} = require('./.github/workflow-scripts/template-app-ci-state'); + core.setOutput('should-run', prepareTestState('/tmp/maestro-ios-state/results.json', './scripts/e2e/.maestro/')); + - name: Run yarn + if: steps.test-state.outputs.should-run == 'true' + uses: ./.github/actions/yarn-install - name: Download React Native Package - if: ${{ matrix.flavor == 'Debug' }} + if: ${{ steps.test-state.outputs.should-run == 'true' && matrix.flavor == 'Debug' }} uses: ./.github/actions/download-artifact with: name: react-native-package path: /tmp/react-native-tmp - name: Configure git - if: ${{ matrix.flavor == 'Debug' }} + if: ${{ steps.test-state.outputs.should-run == 'true' && matrix.flavor == 'Debug' }} shell: bash run: | git config --global user.email "react-native-bot@meta.com" git config --global user.name "React Native Bot" - name: Prepare project for Metro - if: ${{ matrix.flavor == 'Debug' }} + if: ${{ steps.test-state.outputs.should-run == 'true' && matrix.flavor == 'Debug' }} # In Debug the app loads its bundle from Metro, which must run from an # initialized project. Re-initialize it here (JS only — no pods); the # native app itself comes prebuilt from the `build` job. @@ -155,6 +104,7 @@ jobs: node ./scripts/e2e/init-project-e2e.js --projectName RNTestProject --currentBranch $BRANCH --directory /tmp/RNTestProject --pathToLocalReactNative $REACT_NATIVE_PKG - name: Run E2E Tests id: run-tests + if: steps.test-state.outputs.should-run == 'true' continue-on-error: true uses: ./.github/actions/maestro-ios with: @@ -165,17 +115,32 @@ jobs: working-directory: /tmp/RNTestProject device-model: iPhone-17-Pro device-os: iOS-26-2 + test-state-path: /tmp/maestro-ios-state/results.json + - name: Store per-flow test state + if: ${{ !cancelled() && steps.test-state.outputs.should-run == 'true' }} + uses: ./.github/actions/upload-artifact + with: + name: e2e_ios_templateapp_state_${{ matrix.flavor }}_${{ github.run_attempt }} + overwrite: true + if-no-files-found: warn + path: /tmp/maestro-ios-state/results.json - name: Report status id: report-status if: always() uses: actions/github-script@v8 env: + SHOULD_RUN: ${{ steps.test-state.outputs.should-run }} + TEST_OUTCOME: ${{ steps.run-tests.outcome }} STEP_RESULTS: ${{ toJSON(steps) }} JOB_STATUS: ${{ job.status }} TEST_FLAVOR: ${{ matrix.flavor }} with: script: | const {recordJobFailure} = require('./.github/workflow-scripts/report-test-results'); + const {recordConfigurationResult} = require('./.github/workflow-scripts/template-app-ci-state'); + recordConfigurationResult({core, flavor: process.env.TEST_FLAVOR, + passed: process.env.JOB_STATUS === 'success' && + (process.env.SHOULD_RUN === 'false' || process.env.TEST_OUTCOME === 'success')}); await recordJobFailure({github, context, core, steps: JSON.parse(process.env.STEP_RESULTS), flavor: process.env.TEST_FLAVOR, @@ -184,24 +149,30 @@ jobs: attempt: Number(process.env.GITHUB_RUN_ATTEMPT)}); report: - needs: [build, test] - if: always() + needs: test + if: ${{ !cancelled() }} runs-on: ubuntu-latest outputs: status: ${{ steps.check.outputs.status }} + results: ${{ steps.check.outputs.results }} + failed-flavors: ${{ steps.check.outputs.failed-flavors }} steps: - name: Checkout uses: actions/checkout@v6 - - name: Report failed jobs + - name: Report configuration results id: check uses: actions/github-script@v8 env: JOB_RESULTS: ${{ toJSON(needs) }} + FLAVORS: ${{ inputs.flavors }} + PREVIOUS_RESULTS: ${{ inputs.previous-results }} FAIL_ON_ERROR: ${{ inputs.fail-on-error }} with: script: | - const {reportTestResults} = require('./.github/workflow-scripts/report-test-results'); - await reportTestResults({context, core, - needs: JSON.parse(process.env.JOB_RESULTS), + const {reportConfigurationResults} = require('./.github/workflow-scripts/template-app-ci-state'); + await reportConfigurationResults({context, core, + needs: JSON.parse(process.env.JOB_RESULTS), job: 'test', + flavors: JSON.parse(process.env.FLAVORS), + previousResults: JSON.parse(process.env.PREVIOUS_RESULTS), failOnError: process.env.FAIL_ON_ERROR === 'true', attempt: Number(process.env.GITHUB_RUN_ATTEMPT)}); diff --git a/.github/workflows/test-all.yml b/.github/workflows/test-all.yml index c9aff102886..f648824ffb5 100644 --- a/.github/workflows/test-all.yml +++ b/.github/workflows/test-all.yml @@ -153,23 +153,66 @@ jobs: with: platform: ios - test_e2e_ios_templateapp: - needs: [build_npm_package, prebuild_apple_dependencies, check_code_changes] + build_ios_templateapp: + needs: + [ + build_npm_package, + prebuild_apple_dependencies, + prebuild_react_native_core, + check_code_changes, + ] if: needs.check_code_changes.outputs.should_test_ios == 'true' + uses: ./.github/workflows/build-ios-templateapp.yml + secrets: inherit + + build_ios_templateapp_retry_1: + needs: build_ios_templateapp + if: ${{ !cancelled() && (needs.build_ios_templateapp.outputs.status == 'failure' || needs.build_ios_templateapp.result == 'failure') }} + uses: ./.github/workflows/build-ios-templateapp.yml + with: + flavors: ${{ needs.build_ios_templateapp.outputs.failed-flavors || '["Debug", "Release"]' }} + previous-results: ${{ needs.build_ios_templateapp.outputs.results || '{}' }} + secrets: inherit + + build_ios_templateapp_retry_2: + needs: build_ios_templateapp_retry_1 + if: ${{ !cancelled() && (needs.build_ios_templateapp_retry_1.outputs.status == 'failure' || needs.build_ios_templateapp_retry_1.result == 'failure') }} + uses: ./.github/workflows/build-ios-templateapp.yml + with: + flavors: ${{ needs.build_ios_templateapp_retry_1.outputs.failed-flavors || '["Debug", "Release"]' }} + previous-results: ${{ needs.build_ios_templateapp_retry_1.outputs.results || '{}' }} + fail-on-error: true + secrets: inherit + + test_e2e_ios_templateapp: + needs: + [ + build_ios_templateapp, + build_ios_templateapp_retry_1, + build_ios_templateapp_retry_2, + ] + if: ${{ !cancelled() && (needs.build_ios_templateapp.outputs.status == 'success' || needs.build_ios_templateapp_retry_1.outputs.status == 'success' || needs.build_ios_templateapp_retry_2.outputs.status == 'success') }} uses: ./.github/workflows/e2e-ios-templateapp.yml secrets: inherit test_e2e_ios_templateapp_retry_1: needs: test_e2e_ios_templateapp - if: ${{ always() && needs.test_e2e_ios_templateapp.outputs.status == 'failure' }} + if: ${{ !cancelled() && (needs.test_e2e_ios_templateapp.outputs.status == 'failure' || needs.test_e2e_ios_templateapp.result == 'failure') }} uses: ./.github/workflows/e2e-ios-templateapp.yml + with: + flavors: ${{ needs.test_e2e_ios_templateapp.outputs.failed-flavors || '["Debug", "Release"]' }} + previous-results: ${{ needs.test_e2e_ios_templateapp.outputs.results || '{}' }} + retry-attempt: 1 secrets: inherit test_e2e_ios_templateapp_retry_2: needs: test_e2e_ios_templateapp_retry_1 - if: ${{ always() && needs.test_e2e_ios_templateapp_retry_1.outputs.status == 'failure' }} + if: ${{ !cancelled() && (needs.test_e2e_ios_templateapp_retry_1.outputs.status == 'failure' || needs.test_e2e_ios_templateapp_retry_1.result == 'failure') }} uses: ./.github/workflows/e2e-ios-templateapp.yml with: + flavors: ${{ needs.test_e2e_ios_templateapp_retry_1.outputs.failed-flavors || '["Debug", "Release"]' }} + previous-results: ${{ needs.test_e2e_ios_templateapp_retry_1.outputs.results || '{}' }} + retry-attempt: 2 fail-on-error: true secrets: inherit