diff --git a/.clang-format-ignore b/.clang-format-ignore index c955f0ad4d5d..8d232f8c190b 100644 --- a/.clang-format-ignore +++ b/.clang-format-ignore @@ -1,3 +1,6 @@ +**/Pods/** +**/build/** +**/node_modules/** packages/react-native/React/I18n/FBXXHashUtils.h packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/** packages/react-native/ReactAndroid/src/main/jni/third-party/** diff --git a/.eslintrc.js b/.eslintrc.js index 9db5a0e48996..5f5b69ad614b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -51,7 +51,6 @@ module.exports = { files: [ './packages/react-native/Libraries/**/*.{js,flow}', './packages/react-native/src/**/*.{js,flow}', - './packages/assets-registry/registry.js', ], parser: 'flow-eslint', rules: { @@ -62,6 +61,13 @@ module.exports = { files: ['package.json'], parser: 'jsonc-eslint-parser', }, + { + // Generated bundles carry `@nolint`, which this lint run does not honor. + files: ['private/eslint-plugin-monorepo/rules/sort-imports.js'], + rules: { + 'ft-flow/require-valid-file-annotation': 'off', + }, + }, { files: ['flow-typed/**/*.js', 'packages/react-native/flow/**/*'], rules: { diff --git a/.flowconfig b/.flowconfig index 4db110a0acfe..2b273f8cbbb4 100644 --- a/.flowconfig +++ b/.flowconfig @@ -16,6 +16,7 @@ packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeEnumTurboModul **/*.windows.js **/node_modules/resolve/test/resolver/malformed_package_json/package.json +**/node_modules/invariant/** ; Checked-in build output packages/debugger-frontend/dist/** @@ -39,6 +40,8 @@ flow-typed/ packages/react-native/flow/ [options] +builtin_lib=core-only + emoji=true format.bracket_spacing=false @@ -53,11 +56,19 @@ experimental.multi_platform.extensions=.android munge_underscores=true module.name_mapper='^react-native$' -> '/packages/react-native/index.js' +module.name_mapper='^react-native/asset-registry$' -> '/packages/react-native/src/asset-registry.js' +module.name_mapper='^react-native/package.json$' -> '/packages/react-native/package.json' module.name_mapper='^react-native/react-private-interface$' -> '/packages/react-native/src/react-private-interface.js' module.name_mapper='^react-native/setup-env$' -> '/packages/react-native/src/setup-env.js' -module.name_mapper='^react-native/\(.*\)$' -> '/packages/react-native/\1' +module.name_mapper='^react-native/unstable-internals-do-not-use$' -> '/packages/react-native/src/unstable-internals-do-not-use.js' +module.name_mapper='^react-native/scripts/\(.*\)$' -> '/packages/react-native/scripts/\1' +module.name_mapper='^react-native/src/fb_internal/\(.*\)$' -> '/packages/react-native/src/fb_internal/\1' +# Deep imports under React Native's implementation directories are redirected +# to a module that does not exist. Package roots, secondary entry points, and +# `src/fb_internal/*` stay importable. +module.name_mapper='^react-native/\(Libraries\|src/private\|src/types\)/.*$' -> 'react-native-deep-import-is-not-part-of-the-public-api' module.name_mapper='^@react-native/dev-middleware$' -> '/packages/dev-middleware' -module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\|xml\|ktx\|heic\|heif\)$' -> '/packages/react-native/Libraries/Image/RelativeImageStub' +module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\|xml\|ktx\|heic\|ttf\|heif\)$' -> '/packages/react-native/Libraries/Image/RelativeImageStub' module.system.haste.module_ref_prefix=m# @@ -86,4 +97,4 @@ untyped-import untyped-type-import [version] -^0.331.0 +^0.340.0 diff --git a/.github/actions/build-android/action.yml b/.github/actions/build-android/action.yml index 27ddd7b63735..528b0edf6644 100644 --- a/.github/actions/build-android/action.yml +++ b/.github/actions/build-android/action.yml @@ -85,13 +85,13 @@ runs: shell: bash run: ccache -s -v - name: Upload Maven Artifacts - uses: actions/upload-artifact@v6 + uses: ./.github/actions/upload-artifact with: name: maven-local path: /tmp/maven-local - name: Upload test results if: ${{ always() }} - uses: actions/upload-artifact@v6 + uses: ./.github/actions/upload-artifact with: name: build-android-results compression-level: 1 @@ -101,14 +101,14 @@ runs: packages/react-native/ReactAndroid/build/reports - name: Upload RNTester APK - hermes-debug if: ${{ always() }} - uses: actions/upload-artifact@v6 + uses: ./.github/actions/upload-artifact with: name: rntester-debug path: packages/rn-tester/android/app/build/outputs/apk/debug/ compression-level: 0 - name: Upload RNTester APK - hermes-release if: ${{ always() }} - uses: actions/upload-artifact@v6 + uses: ./.github/actions/upload-artifact with: name: rntester-release path: packages/rn-tester/android/app/build/outputs/apk/release/ diff --git a/.github/actions/build-fantom-runner/action.yml b/.github/actions/build-fantom-runner/action.yml index c4b34c32fbee..506f1453eb4b 100644 --- a/.github/actions/build-fantom-runner/action.yml +++ b/.github/actions/build-fantom-runner/action.yml @@ -54,6 +54,14 @@ runs: env: CC: clang CXX: clang++ + - name: Upload Fantom build logs + if: ${{ always() }} + uses: ./.github/actions/upload-artifact + with: + name: build-fantom-results + compression-level: 1 + if-no-files-found: ignore + path: private/react-native-fantom/build/reports - name: Save Fantom ccache if: ${{ github.ref == 'refs/heads/main' || contains(github.ref, '-stable') }} uses: actions/cache/save@v5 @@ -77,7 +85,7 @@ runs: shell: bash run: cp packages/react-native/ReactAndroid/hermes-engine/build/hermes/lib/libhermesvm.so private/react-native-fantom/build/tester/ - name: Upload Fantom Runner binary - uses: actions/upload-artifact@v6 + uses: ./.github/actions/upload-artifact with: name: fantom-runner-binary compression-level: 1 diff --git a/.github/actions/build-npm-package/action.yml b/.github/actions/build-npm-package/action.yml index e3771ce3d51a..28abfe5fa022 100644 --- a/.github/actions/build-npm-package/action.yml +++ b/.github/actions/build-npm-package/action.yml @@ -19,14 +19,14 @@ runs: run: git config --global --add safe.directory '*' - name: Download ReactNativeDependencies if: ${{ inputs.skip-apple-prebuilts != 'true' }} - uses: actions/download-artifact@v7 + uses: ./.github/actions/download-artifact with: pattern: ReactNativeDependencies* path: ./packages/react-native/ReactAndroid/external-artifacts/artifacts merge-multiple: true - name: Download ReactCore artifacts if: ${{ inputs.skip-apple-prebuilts != 'true' }} - uses: actions/download-artifact@v7 + uses: ./.github/actions/download-artifact with: pattern: ReactCore* path: ./packages/react-native/ReactAndroid/external-artifacts/artifacts @@ -35,7 +35,7 @@ runs: # ReactNativeDependencies* pattern above; ReactNativeHeaders* needs its own. - name: Download ReactNativeHeaders artifacts if: ${{ inputs.skip-apple-prebuilts != 'true' }} - uses: actions/download-artifact@v7 + uses: ./.github/actions/download-artifact with: pattern: ReactNativeHeaders* path: ./packages/react-native/ReactAndroid/external-artifacts/artifacts @@ -77,7 +77,7 @@ runs: fi node ./scripts/releases-ci/publish-npm.js -t ${{ inputs.release-type }} - name: Upload npm logs - uses: actions/upload-artifact@v6 + uses: ./.github/actions/upload-artifact with: name: npm-logs path: ~/.npm/_logs @@ -92,7 +92,7 @@ runs: echo "$FILENAME" > build/react-native-package-version - name: Upload release package - uses: actions/upload-artifact@v6 + uses: ./.github/actions/upload-artifact if: ${{ inputs.release-type == 'dry-run' }} with: name: react-native-package diff --git a/.github/actions/download-artifact/action.yml b/.github/actions/download-artifact/action.yml new file mode 100644 index 000000000000..f2612331337e --- /dev/null +++ b/.github/actions/download-artifact/action.yml @@ -0,0 +1,88 @@ +name: Download artifact with retries +description: Downloads an artifact, retrying transient failures up to two times + +inputs: + name: + description: Artifact name. Leave empty to download by pattern instead. + required: false + default: '' + pattern: + description: Glob pattern matching the artifacts to download. Ignored when name is set. + required: false + default: '' + path: + description: Destination path + required: true + merge-multiple: + description: Download pattern-matched artifacts into path directly instead of per-artifact subdirectories + required: false + default: 'false' + run-id: + description: Download artifacts from a different workflow run. Leave empty for the current run. + required: false + default: '' + github-token: + description: Token used for cross-run downloads. Leave empty for same-run downloads. + required: false + default: '' + +outputs: + download-path: + description: Absolute path where the artifact was downloaded + value: ${{ steps.download-3.outputs.download-path || steps.download-2.outputs.download-path || steps.download-1.outputs.download-path }} + +runs: + using: composite + steps: + - name: Download artifact (attempt 1 of 3) + id: download-1 + if: ${{ always() }} + continue-on-error: true + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + with: + name: ${{ inputs.name }} + pattern: ${{ inputs.pattern }} + path: ${{ inputs.path }} + merge-multiple: ${{ inputs.merge-multiple }} + run-id: ${{ inputs.run-id }} + github-token: ${{ inputs.github-token }} + + - name: Wait before attempt 2 + if: ${{ always() && steps.download-1.outcome == 'failure' }} + shell: bash + run: | + echo "::warning::Artifact download failed; retrying in 10 seconds" + sleep 10 + + - name: Download artifact (attempt 2 of 3) + id: download-2 + if: ${{ always() && steps.download-1.outcome == 'failure' }} + continue-on-error: true + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + with: + name: ${{ inputs.name }} + pattern: ${{ inputs.pattern }} + path: ${{ inputs.path }} + merge-multiple: ${{ inputs.merge-multiple }} + run-id: ${{ inputs.run-id }} + github-token: ${{ inputs.github-token }} + + - name: Wait before attempt 3 + if: ${{ always() && steps.download-2.outcome == 'failure' }} + shell: bash + run: | + echo "::warning::Artifact download failed again; retrying in 20 seconds" + sleep 20 + + - name: Download artifact (attempt 3 of 3) + id: download-3 + if: ${{ always() && steps.download-2.outcome == 'failure' }} + # Deliberately do not continue on error: the last failure must fail the caller. + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + with: + name: ${{ inputs.name }} + pattern: ${{ inputs.pattern }} + path: ${{ inputs.path }} + merge-multiple: ${{ inputs.merge-multiple }} + run-id: ${{ inputs.run-id }} + github-token: ${{ inputs.github-token }} diff --git a/.github/actions/maestro-android/action.yml b/.github/actions/maestro-android/action.yml index 7f760573c940..94a3be4c2528 100644 --- a/.github/actions/maestro-android/action.yml +++ b/.github/actions/maestro-android/action.yml @@ -90,7 +90,7 @@ runs: NORM_APP_ID=$(echo "${{ inputs.app-id }}" | tr '.' '-') echo "app-id=$NORM_APP_ID" >> $GITHUB_OUTPUT - name: Store tests result - uses: actions/upload-artifact@v6 + uses: ./.github/actions/upload-artifact if: always() with: name: e2e_android_${{ steps.normalize-app-id.outputs.app-id }}_report_${{ inputs.flavor }}_${{ inputs.emulator-arch }}_NewArch @@ -100,7 +100,7 @@ runs: screen.mp4 - name: Store Logs if: always() - uses: actions/upload-artifact@v6 + uses: ./.github/actions/upload-artifact with: name: maestro-logs-android-${{ steps.normalize-app-id.outputs.app-id }}-${{ inputs.flavor }}-${{ inputs.emulator-arch }}-NewArch overwrite: true diff --git a/.github/actions/maestro-ios/action.yml b/.github/actions/maestro-ios/action.yml index 6ebc7327fb0b..f7f3feac346a 100644 --- a/.github/actions/maestro-ios/action.yml +++ b/.github/actions/maestro-ios/action.yml @@ -18,25 +18,42 @@ inputs: required: false default: '.' description: The directory from which metro should be started + device-model: + required: false + default: '' + description: Maestro device model name, such as iPhone-17-Pro + device-os: + required: false + default: '' + description: Maestro device OS name, such as iOS-26-2 + test-state-path: + required: false + default: '' + description: The path used to persist per-flow test results between retries + exclude-tags: + required: false + default: '' + description: Comma-separated flow tags to exclude from the test run runs: using: composite + # Expects Node.js to be set up by the calling job. steps: + # Booting takes a couple of minutes; it finishes while the next steps run. + - name: Boot simulator + shell: bash + run: | + node .github/workflow-scripts/maestro-ios.js boot \ + "${{ inputs.device-model }}" \ + "${{ inputs.device-os }}" - name: Installing Maestro shell: bash run: export MAESTRO_VERSION=2.6.1; curl -Ls "https://get.maestro.mobile.dev" | bash - - name: Installing Maestro dependencies - shell: bash - run: | - brew tap facebook/fb - brew install facebook/fb/idb-companion - name: Set up JDK 17 uses: actions/setup-java@v5 with: java-version: '17' distribution: 'zulu' - - name: Setup node.js - uses: ./.github/actions/setup-node - name: Run yarn install uses: ./.github/actions/yarn-install - name: Start Metro in Debug @@ -63,24 +80,17 @@ runs: "${{ inputs.maestro-flow }}" \ "Hermes" \ "${{ inputs.flavor }}" \ - "${{ inputs.working-directory }}" - - name: Store video record - if: always() - uses: actions/upload-artifact@v6 - with: - name: e2e_ios_${{ inputs.app-id }}_report_${{ inputs.flavor }}_NewArch - overwrite: true - path: | - video_record_1.mov - video_record_2.mov - video_record_3.mov - video_record_4.mov - video_record_5.mov - report.xml + "${{ inputs.working-directory }}" \ + "${{ inputs.device-model }}" \ + "${{ inputs.device-os }}" \ + "${{ inputs.test-state-path }}" \ + "${{ inputs.exclude-tags }}" - name: Store Logs - if: failure() && steps.run-tests.outcome == 'failure' - uses: actions/upload-artifact@v6 + if: always() + uses: ./.github/actions/upload-artifact with: name: maestro-logs-${{ inputs.app-id }}-${{ inputs.flavor }}-NewArch overwrite: true + if-no-files-found: ignore + # Only failed runs leave their report, debug output and recording here path: /tmp/MaestroLogs diff --git a/.github/actions/run-fantom-tests/action.yml b/.github/actions/run-fantom-tests/action.yml index 8a6fdcd832ac..f511bcdd2494 100644 --- a/.github/actions/run-fantom-tests/action.yml +++ b/.github/actions/run-fantom-tests/action.yml @@ -15,7 +15,7 @@ runs: - name: Install node dependencies uses: ./.github/actions/yarn-install - name: Download Fantom Runner binary - uses: actions/download-artifact@v7 + uses: ./.github/actions/download-artifact with: name: fantom-runner-binary path: private/react-native-fantom/build/tester @@ -27,26 +27,28 @@ runs: run: | for attempt in 1 2 3; do echo "Attempt $attempt of 3" - if [ "$attempt" -eq 1 ]; then - if yarn fantom; then - exit 0 - fi - else - if yarn fantom --onlyFailures; then - exit 0 - fi + if yarn fantom --ci; then + exit 0 fi if [ "$attempt" -lt 3 ]; then - echo "Attempt $attempt failed. Retrying only failed tests..." + echo "Attempt $attempt failed. Retrying..." fi done echo "All 3 attempts failed." exit 1 env: LD_LIBRARY_PATH: ${{ github.workspace }}/private/react-native-fantom/build/tester + - name: Upload failed screenshot comparisons + if: ${{ always() }} + uses: ./.github/actions/upload-artifact + with: + name: fantom-screenshot-failures + compression-level: 1 + if-no-files-found: ignore + path: private/react-native-fantom/build/screenshot-failures - name: Upload test results if: ${{ always() }} - uses: actions/upload-artifact@v6 + uses: ./.github/actions/upload-artifact with: name: run-fantom-tests-results compression-level: 1 diff --git a/.github/actions/setup-spm-artifacts/action.yml b/.github/actions/setup-spm-artifacts/action.yml new file mode 100644 index 000000000000..059cf03b4e5a --- /dev/null +++ b/.github/actions/setup-spm-artifacts/action.yml @@ -0,0 +1,57 @@ +name: setup-spm-artifacts +description: >- + Downloads the ReactCore and ReactNativeDependencies XCFrameworks built in this + run, in both flavors, into the SwiftPM artifact root /tmp/spm-artifacts. Pass + `--artifacts /tmp/spm-artifacts --download skip` to the `react-native spm` + command that follows. +inputs: + working-directory: + description: The app directory that `npx react-native spm download` runs from. + required: true +runs: + using: composite + steps: + # Both flavors are needed by every build, not just the one it builds: + # `spm` stages both flavor framework trees and lets a per-configuration + # build setting pick one at build time, so it validates the debug/ and + # release/ artifact slots together (and `--download skip` refuses an + # incomplete slot). Please don't "optimise" this down to one flavor. + - name: Download ReactCore (Debug) + uses: ./.github/actions/download-artifact + with: + name: ReactCoreDebug.xcframework.tar.gz + path: /tmp/rc-debug + - name: Download ReactCore (Release) + uses: ./.github/actions/download-artifact + with: + name: ReactCoreRelease.xcframework.tar.gz + path: /tmp/rc-release + - name: Download ReactNativeDependencies (Debug) + uses: ./.github/actions/download-artifact + with: + name: ReactNativeDependenciesDebug.xcframework.tar.gz + path: /tmp/deps-debug + - name: Download ReactNativeDependencies (Release) + uses: ./.github/actions/download-artifact + with: + name: ReactNativeDependenciesRelease.xcframework.tar.gz + path: /tmp/deps-release + # The ordinary `spm download`, pointed at the XCFrameworks this run just + # built rather than at the published nightly (RN_CORE_TARBALL_PATH / + # RN_DEPS_TARBALL_PATH are overrides download-spm-artifacts.js already + # supports). It fills both flavor slots per call and skips any slot that + # already validates, so it runs twice: the first pass fills both slots + # from the Release tarballs, then debug/ is dropped and refilled from the + # Debug tarballs while release/ is left alone. hermes-engine is fetched + # from Maven by the command itself. + - name: Stage the XCFrameworks for SwiftPM (Debug + Release) + shell: bash + working-directory: ${{ inputs.working-directory }} + run: | + RN_CORE_TARBALL_PATH=/tmp/rc-release/ReactCoreRelease.xcframework.tar.gz \ + RN_DEPS_TARBALL_PATH=/tmp/deps-release/ReactNativeDependenciesRelease.xcframework.tar.gz \ + npx react-native spm download --artifacts /tmp/spm-artifacts + rm -rf /tmp/spm-artifacts/debug + RN_CORE_TARBALL_PATH=/tmp/rc-debug/ReactCoreDebug.xcframework.tar.gz \ + RN_DEPS_TARBALL_PATH=/tmp/deps-debug/ReactNativeDependenciesDebug.xcframework.tar.gz \ + npx react-native spm download --artifacts /tmp/spm-artifacts diff --git a/.github/actions/test-ios-helloworld/action.yml b/.github/actions/test-ios-helloworld/action.yml index b325a061d929..28a5cb206ee0 100644 --- a/.github/actions/test-ios-helloworld/action.yml +++ b/.github/actions/test-ios-helloworld/action.yml @@ -1,15 +1,12 @@ name: test-ios-helloworld description: Test iOS Hello World inputs: - use-frameworks: - description: The dependency building and linking strategy to use. Must be one of "StaticLibraries", "DynamicFrameworks" - default: StaticLibraries - ruby-version: - description: The version of ruby that must be used - default: 2.6.10 flavor: description: The flavor of the build. Must be one of "Debug", "Release". default: Debug + dependency-manager: + description: 'How the app gets its native dependencies: swiftpm or cocoapods' + default: swiftpm runs: using: composite steps: @@ -19,46 +16,64 @@ runs: uses: ./.github/actions/setup-node - name: Run yarn install uses: ./.github/actions/yarn-install - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ inputs.ruby-version }} - name: Set Hermes prebuilt version shell: bash run: | node ./scripts/releases/use-hermes-prebuilt.js - name: Run yarn install again, with the correct hermes version uses: ./.github/actions/yarn-install + - name: Setup ruby + if: ${{ inputs.dependency-manager == 'cocoapods' }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6.10 - name: Download ReactNativeDependencies - uses: actions/download-artifact@v7 + if: ${{ inputs.dependency-manager == 'cocoapods' }} + uses: ./.github/actions/download-artifact with: name: ReactNativeDependencies${{ inputs.flavor }}.xcframework.tar.gz path: /tmp/third-party - - name: Print third-party folder - shell: bash - run: ls -lR /tmp/third-party - name: Download React Native Prebuilds - uses: actions/download-artifact@v7 + if: ${{ inputs.dependency-manager == 'cocoapods' }} + uses: ./.github/actions/download-artifact with: name: ReactCore${{ inputs.flavor }}.xcframework.tar.gz path: /tmp/ReactCore - - name: Print ReactCore folder - shell: bash - run: ls -lR /tmp/ReactCore - - name: Install iOS dependencies - Configuration ${{ inputs.flavor }}; + - name: Install iOS dependencies - Configuration ${{ inputs.flavor }} + if: ${{ inputs.dependency-manager == 'cocoapods' }} shell: bash run: | cd private/helloworld - args=() - - if [[ ${{ inputs.use-frameworks }} == "DynamicFrameworks" ]]; then - args+=(--frameworks dynamic) - fi export RCT_USE_LOCAL_RN_DEP="/tmp/third-party/ReactNativeDependencies${{ inputs.flavor }}.xcframework.tar.gz" export RCT_TESTONLY_RNCORE_TARBALL_PATH="/tmp/ReactCore/ReactCore${{ inputs.flavor }}.xcframework.tar.gz" - yarn bootstrap ios "${args[@]}" | cat + yarn bootstrap ios | cat + - name: Download the XCFrameworks built in this run + if: ${{ inputs.dependency-manager == 'swiftpm' }} + uses: ./.github/actions/setup-spm-artifacts + with: + working-directory: private/helloworld/ios + # HelloWorld is a CocoaPods project in git. CI converts it to SwiftPM on every run. + - name: Convert HelloWorld to SwiftPM + if: ${{ inputs.dependency-manager == 'swiftpm' }} + shell: bash + working-directory: private/helloworld/ios + run: RN_STRICT_API=1 npx react-native spm add --deintegrate --artifacts /tmp/spm-artifacts --download skip + - name: Assert HelloWorld is on SwiftPM + if: ${{ inputs.dependency-manager == 'swiftpm' }} + shell: bash + working-directory: private/helloworld/ios + run: | + if [[ ! -f HelloWorld.xcodeproj/.spm-injected.json ]]; then + echo "::error::spm add did not inject SwiftPM: HelloWorld.xcodeproj/.spm-injected.json is missing" + exit 1 + fi + if grep -q 'Pods-' HelloWorld.xcodeproj/project.pbxproj; then + echo "::error::spm add --deintegrate left CocoaPods references in HelloWorld.xcodeproj" + exit 1 + fi + echo "SwiftPM injected in place; CocoaPods de-integrated." - name: Run Helloworld tests shell: bash diff --git a/.github/actions/test-ios-rntester/action.yml b/.github/actions/test-ios-rntester/action.yml index 2b62f554daa1..e54d2cc1be20 100644 --- a/.github/actions/test-ios-rntester/action.yml +++ b/.github/actions/test-ios-rntester/action.yml @@ -1,9 +1,6 @@ name: test-ios-rntester description: Test iOS RNTester inputs: - ruby-version: - description: The version of ruby that must be used - default: 2.6.10 run-unit-tests: description: whether unit tests should run or not. default: false @@ -14,19 +11,9 @@ inputs: description: Whether we want to run E2E tests or not required: false default: false - use-frameworks: - description: Whether we have to build with Dynamic Frameworks. - required: false - default: false - use-prebuilds: - description: >- - Whether to consume the prebuilt ReactCore/ReactNativeDependencies - artifacts. 'auto' (default) keeps the historical coupling: prebuilds for - static, source for dynamic frameworks. Pass 'true' with - use-frameworks:true for the prebuilt + dynamic-frameworks lane (the - config of the 2026-07-03 SocketRocket dual-copy regression). - required: false - default: auto + dependency-manager: + description: 'How the app gets its native dependencies: swiftpm or cocoapods' + default: swiftpm runs: using: composite @@ -37,10 +24,6 @@ runs: uses: ./.github/actions/setup-node - name: Run yarn uses: ./.github/actions/yarn-install - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ inputs.ruby-version }} - name: Set Hermes prebuilt version shell: bash run: | @@ -50,77 +33,127 @@ runs: - name: Prepare IOS Tests if: ${{ inputs.run-unit-tests == 'true' }} uses: ./.github/actions/prepare-ios-tests - - name: Resolve prebuilds mode - id: prebuilds + - name: Setup ruby + if: ${{ inputs.dependency-manager == 'cocoapods' }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6.10 + bundler: none + - name: Install Bundler + if: ${{ inputs.dependency-manager == 'cocoapods' }} shell: bash run: | - if [[ "${{ inputs.use-prebuilds }}" == "auto" ]]; then - # Historical coupling: prebuilds for static, source for dynamic frameworks. - if [[ "${{ inputs.use-frameworks }}" == "true" ]]; then - echo "enabled=false" >> "$GITHUB_OUTPUT" - else - echo "enabled=true" >> "$GITHUB_OUTPUT" - fi - elif [[ "${{ inputs.use-prebuilds }}" == "true" ]]; then - echo "enabled=true" >> "$GITHUB_OUTPUT" - elif [[ "${{ inputs.use-prebuilds }}" == "false" ]]; then - echo "enabled=false" >> "$GITHUB_OUTPUT" - else - # Don't silently treat a typo as 'disabled' — surface it. - echo "::warning::Unexpected use-prebuilds value '${{ inputs.use-prebuilds }}' (expected auto/true/false); treating as disabled." - echo "enabled=false" >> "$GITHUB_OUTPUT" + BUNDLER_VERSION="$(awk '/BUNDLED WITH/{getline; print $1}' Gemfile.lock)" + if [ -z "$BUNDLER_VERSION" ]; then + echo "Could not determine Bundler version from Gemfile.lock." >&2 + exit 1 fi + for attempt in 1 2 3; do + echo "Attempt $attempt of 3" + if gem install bundler --version "$BUNDLER_VERSION" --no-document; then + exit 0 + fi + if [ "$attempt" -lt 3 ]; then + echo "Attempt $attempt failed. Retrying..." + sleep "$((attempt * 10))" + fi + done + echo "All 3 attempts failed." + exit 1 - name: Download ReactNativeDependencies - if: ${{ steps.prebuilds.outputs.enabled == 'true' }} - uses: actions/download-artifact@v7 + if: ${{ inputs.dependency-manager == 'cocoapods' }} + uses: ./.github/actions/download-artifact with: name: ReactNativeDependencies${{ inputs.flavor }}.xcframework.tar.gz path: /tmp/third-party/ - - name: Print third-party folder - if: ${{ steps.prebuilds.outputs.enabled == 'true' }} - shell: bash - run: ls -lR /tmp/third-party - name: Download React Native Prebuilds - if: ${{ steps.prebuilds.outputs.enabled == 'true' }} - uses: actions/download-artifact@v7 + if: ${{ inputs.dependency-manager == 'cocoapods' }} + uses: ./.github/actions/download-artifact with: name: ReactCore${{ inputs.flavor }}.xcframework.tar.gz path: /tmp/ReactCore - - name: Print ReactCore folder - if: ${{ steps.prebuilds.outputs.enabled == 'true' }} - shell: bash - run: ls -lR /tmp/ReactCore - name: Install CocoaPods dependencies + if: ${{ inputs.dependency-manager == 'cocoapods' }} shell: bash run: | - if [[ ${{ inputs.use-frameworks }} == "true" ]]; then - export USE_FRAMEWORKS=dynamic - fi - if [[ "${{ steps.prebuilds.outputs.enabled }}" == "true" ]]; then - export RCT_USE_LOCAL_RN_DEP="/tmp/third-party/ReactNativeDependencies${{ inputs.flavor }}.xcframework.tar.gz" - export RCT_TESTONLY_RNCORE_TARBALL_PATH="/tmp/ReactCore/ReactCore${{ inputs.flavor }}.xcframework.tar.gz" - fi + export RCT_USE_LOCAL_RN_DEP="/tmp/third-party/ReactNativeDependencies${{ inputs.flavor }}.xcframework.tar.gz" + export RCT_TESTONLY_RNCORE_TARBALL_PATH="/tmp/ReactCore/ReactCore${{ inputs.flavor }}.xcframework.tar.gz" cd packages/rn-tester bundle install bundle exec pod update hermes-engine --no-repo-update + - name: Download the XCFrameworks built in this run + if: ${{ inputs.dependency-manager == 'swiftpm' }} + uses: ./.github/actions/setup-spm-artifacts + with: + working-directory: packages/rn-tester + # RNTester is a CocoaPods project in git, so developers can build React + # Native from source. CI converts it to SwiftPM on every run. + # react-native-test-library ships only a podspec; scaffold writes its + # Package.swift. + - name: Scaffold Package.swift manifests for community dependencies + if: ${{ inputs.dependency-manager == 'swiftpm' }} + shell: bash + working-directory: packages/rn-tester + run: npx react-native spm scaffold --artifacts /tmp/spm-artifacts --download skip || true + - name: Convert RNTester to SwiftPM + if: ${{ inputs.dependency-manager == 'swiftpm' }} + shell: bash + working-directory: packages/rn-tester + run: RN_STRICT_API=1 npx react-native spm add --deintegrate --artifacts /tmp/spm-artifacts --download skip + - name: Assert RNTester is on SwiftPM + if: ${{ inputs.dependency-manager == 'swiftpm' }} + shell: bash + working-directory: packages/rn-tester + run: | + if [[ ! -f RNTesterPods.xcodeproj/.spm-injected.json ]]; then + echo "::error::spm add did not inject SwiftPM: RNTesterPods.xcodeproj/.spm-injected.json is missing" + exit 1 + fi + if grep -q 'Pods-' RNTesterPods.xcodeproj/project.pbxproj; then + echo "::error::spm add --deintegrate left CocoaPods references in RNTesterPods.xcodeproj" + exit 1 + fi + echo "SwiftPM injected in place; CocoaPods de-integrated." - name: Build RNTester shell: bash run: | + if [[ "${{ inputs.dependency-manager }}" == "cocoapods" ]]; then + container=(-workspace packages/rn-tester/RNTesterPods.xcworkspace) + else + container=(-project packages/rn-tester/RNTesterPods.xcodeproj) + fi xcodebuild \ -scheme "RNTester" \ - -workspace packages/rn-tester/RNTesterPods.xcworkspace \ + "${container[@]}" \ -configuration "${{ inputs.flavor }}" \ -sdk "iphonesimulator" \ -destination "generic/platform=iOS Simulator" \ -derivedDataPath "/tmp/RNTesterBuild" - echo "Print path to *.app file" - APP_PATH=$(find "/tmp/RNTesterBuild" -type d -name "*.app") - - echo "App found at $APP_PATH" - echo "app-path=$APP_PATH" >> $GITHUB_ENV + APP_PATH="/tmp/RNTesterBuild/Build/Products/${{ inputs.flavor }}-iphonesimulator/RNTester.app" + echo "App found at $APP_PATH" + echo "app-path=$APP_PATH" >> $GITHUB_ENV + - name: Check the embedded React.framework flavor + if: ${{ inputs.dependency-manager == 'swiftpm' }} + shell: bash + run: | + BINARY="${{ env.app-path }}/Frameworks/React.framework/React" + if [[ ! -f "$BINARY" ]]; then + echo "::error::No embedded React.framework binary at $BINARY" + exit 1 + fi + COUNT=$(nm "$BINARY" | grep -c getDebugProps || true) + echo "getDebugProps symbols in $BINARY: $COUNT" + if [[ "${{ inputs.flavor }}" == 'Debug' && "$COUNT" -eq 0 ]]; then + echo "::error::Debug build embeds a Release React.framework (expected getDebugProps symbols, found none)" + exit 1 + fi + if [[ "${{ inputs.flavor }}" == 'Release' && "$COUNT" -ne 0 ]]; then + echo "::error::Release build embeds a Debug React.framework ($COUNT getDebugProps symbols, expected none)" + exit 1 + fi - name: 'Run Tests: iOS Unit and Integration Tests' if: ${{ inputs.run-unit-tests == 'true' }} shell: bash @@ -134,20 +167,20 @@ runs: cd /Users/runner/Library/Developer/Xcode tar -zcvf xcresults.tar.gz "/tmp/RNTesterTestResults" - name: Upload artifact - uses: actions/upload-artifact@v6 - if: ${{ inputs.run-unit-tests == 'true' }} + uses: ./.github/actions/upload-artifact + if: ${{ inputs.run-unit-tests == 'true' && inputs.dependency-manager == 'swiftpm' }} with: - name: xcresults-${{ inputs.flavor }}-${{ inputs.use-frameworks == 'true' && 'dynamic-frameworks' || 'static-libraries' }}-Ruby${{ inputs.ruby-version }} + name: xcresults-${{ inputs.flavor }} path: /Users/runner/Library/Developer/Xcode/xcresults.tar.gz - name: Upload RNTester App - if: ${{ inputs.use-frameworks == 'false' && inputs.ruby-version == '2.6.10' }} # This is needed to avoid conflicts with the artifacts - uses: actions/upload-artifact@v6 + if: ${{ inputs.dependency-manager == 'swiftpm' }} # The e2e tests download this artifact; one upload per name + uses: ./.github/actions/upload-artifact with: name: RNTesterApp-NewArch-${{ inputs.flavor }} path: ${{ env.app-path }} - name: Store test results - if: ${{ inputs.run-unit-tests == 'true' }} - uses: actions/upload-artifact@v6 + if: ${{ inputs.run-unit-tests == 'true' && inputs.dependency-manager == 'swiftpm' }} + uses: ./.github/actions/upload-artifact with: - name: test-results-${{ inputs.flavor }}-${{ inputs.use-frameworks == 'true' && 'dynamic-frameworks' || 'static-libraries' }}-Ruby${{ inputs.ruby-version }} + name: test-results-${{ inputs.flavor }} path: ./reports/junit diff --git a/.github/actions/test-js/action.yml b/.github/actions/test-js/action.yml index 653a7ee95928..6d2c4e0f0939 100644 --- a/.github/actions/test-js/action.yml +++ b/.github/actions/test-js/action.yml @@ -19,7 +19,7 @@ runs: run: node ./scripts/run-ci-javascript-tests.js --maxWorkers 2 - name: Upload test results if: ${{ always() }} - uses: actions/upload-artifact@v6 + uses: ./.github/actions/upload-artifact with: name: test-js-results compression-level: 1 diff --git a/.github/actions/upload-artifact/action.yml b/.github/actions/upload-artifact/action.yml new file mode 100644 index 000000000000..9d1b6a39781e --- /dev/null +++ b/.github/actions/upload-artifact/action.yml @@ -0,0 +1,100 @@ +name: Upload artifact with retries +description: Uploads an artifact, retrying transient failures up to two times + +inputs: + name: + description: Artifact name + default: artifact + path: + description: A file, directory, or wildcard pattern to upload + required: true + if-no-files-found: + description: Behavior when no files are found (warn, error, or ignore) + default: warn + retention-days: + description: Number of days to retain the artifact + compression-level: + description: Zlib compression level (0-9) + default: '6' + overwrite: + description: Whether to replace an artifact with the same name + default: 'false' + include-hidden-files: + description: Whether to include hidden files + default: 'false' + archive: + description: Whether to archive the artifact before uploading + default: 'true' + +outputs: + artifact-id: + description: The uploaded artifact's ID + value: ${{ steps.upload-3.outputs.artifact-id || steps.upload-2.outputs.artifact-id || steps.upload-1.outputs.artifact-id }} + artifact-url: + description: The uploaded artifact's URL + value: ${{ steps.upload-3.outputs.artifact-url || steps.upload-2.outputs.artifact-url || steps.upload-1.outputs.artifact-url }} + artifact-digest: + description: The uploaded artifact's SHA-256 digest + value: ${{ steps.upload-3.outputs.artifact-digest || steps.upload-2.outputs.artifact-digest || steps.upload-1.outputs.artifact-digest }} + +runs: + using: composite + steps: + - name: Upload artifact (attempt 1 of 3) + id: upload-1 + if: ${{ always() }} + continue-on-error: true + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: ${{ inputs.name }} + path: ${{ inputs.path }} + if-no-files-found: ${{ inputs.if-no-files-found }} + retention-days: ${{ inputs.retention-days }} + compression-level: ${{ inputs.compression-level }} + overwrite: ${{ inputs.overwrite }} + include-hidden-files: ${{ inputs.include-hidden-files }} + archive: ${{ inputs.archive }} + + - name: Wait before attempt 2 + if: ${{ always() && steps.upload-1.outcome == 'failure' }} + shell: bash + run: | + echo "::warning::Artifact upload failed; retrying in 10 seconds" + sleep 10 + + - name: Upload artifact (attempt 2 of 3) + id: upload-2 + if: ${{ always() && steps.upload-1.outcome == 'failure' }} + continue-on-error: true + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: ${{ inputs.name }} + path: ${{ inputs.path }} + if-no-files-found: ${{ inputs.if-no-files-found }} + retention-days: ${{ inputs.retention-days }} + compression-level: ${{ inputs.compression-level }} + overwrite: ${{ inputs.overwrite }} + include-hidden-files: ${{ inputs.include-hidden-files }} + archive: ${{ inputs.archive }} + + - name: Wait before attempt 3 + if: ${{ always() && steps.upload-2.outcome == 'failure' }} + shell: bash + run: | + echo "::warning::Artifact upload failed again; retrying in 20 seconds" + sleep 20 + + - name: Upload artifact (attempt 3 of 3) + id: upload-3 + if: ${{ always() && steps.upload-2.outcome == 'failure' }} + # Deliberately do not continue on error: the last failure must fail the caller. + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: ${{ inputs.name }} + path: ${{ inputs.path }} + if-no-files-found: ${{ inputs.if-no-files-found }} + retention-days: ${{ inputs.retention-days }} + compression-level: ${{ inputs.compression-level }} + overwrite: ${{ inputs.overwrite }} + include-hidden-files: ${{ inputs.include-hidden-files }} + archive: ${{ inputs.archive }} diff --git a/.github/workflow-scripts/__tests__/__fixtures__/visual.js b/.github/workflow-scripts/__tests__/__fixtures__/visual.js new file mode 100644 index 000000000000..cd72997285d2 --- /dev/null +++ b/.github/workflow-scripts/__tests__/__fixtures__/visual.js @@ -0,0 +1,28 @@ +/** + * 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 SHA_A = 'a'.repeat(40); +const SHA_B = 'b'.repeat(40); + +const ANDROID_ENVIRONMENT = { + apiLevel: 35, + abi: 'x86_64', + nativeBridge: 'libndk_translation.so', + systemImage: + 'google/sdk_gphone64_x86_64/emu64xa:15/AE3A/1:userdebug/dev-keys', + screenSize: '1080x2400', + density: 420, + fontScale: '1.0', + locale: 'en-US', + animatorDurationScale: '0.0', + emulatorVersion: '37.2.12', +}; + +module.exports = {ANDROID_ENVIRONMENT, SHA_A, SHA_B}; diff --git a/.github/workflow-scripts/__tests__/checkBranchTarget-test.js b/.github/workflow-scripts/__tests__/checkBranchTarget-test.js new file mode 100644 index 000000000000..3524fd39f6c1 --- /dev/null +++ b/.github/workflow-scripts/__tests__/checkBranchTarget-test.js @@ -0,0 +1,47 @@ +/** + * 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. + * + * @format + */ + +'use strict'; + +const checkBranchTarget = require('../checkBranchTarget'); + +describe('checkBranchTarget', () => { + test('passes for main', () => { + expect(checkBranchTarget('main')).toEqual({ + message: '', + status: 'PASS', + shouldAddPickLabel: false, + }); + }); + + test('passes for a stable branch and adds the pick label', () => { + expect(checkBranchTarget('0.76-stable')).toEqual({ + message: '', + status: 'PASS', + shouldAddPickLabel: true, + }); + }); + + test('passes for the head branch of another open PR', () => { + expect(checkBranchTarget('pr58950', true)).toEqual({ + message: '', + status: 'PASS', + shouldAddPickLabel: false, + }); + }); + + test('fails for any other branch', () => { + const {message, status, shouldAddPickLabel} = + checkBranchTarget('feature-branch'); + + expect(status).toBe('FAIL'); + expect(message).toContain('`feature-branch`'); + expect(shouldAddPickLabel).toBe(false); + }); +}); diff --git a/.github/workflow-scripts/__tests__/checkForReproducer-links-test.js b/.github/workflow-scripts/__tests__/checkForReproducer-links-test.js new file mode 100644 index 000000000000..b1da2c381cb4 --- /dev/null +++ b/.github/workflow-scripts/__tests__/checkForReproducer-links-test.js @@ -0,0 +1,71 @@ +/** + * 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. + * + * @format + */ + +'use strict'; + +const checkForReproducer = require('../checkForReproducer'); + +const ISSUE_AUTHOR = 'issue-author'; + +function buildGithub(body) { + return { + rest: { + issues: { + get: jest.fn().mockResolvedValue({ + data: { + user: {login: ISSUE_AUTHOR}, + created_at: '2026-10-01T00:00:00Z', + body, + }, + }), + listComments: jest.fn().mockResolvedValue({data: []}), + listEventsForTimeline: jest.fn().mockResolvedValue({data: []}), + removeLabel: jest.fn().mockResolvedValue({}), + addLabels: jest.fn().mockResolvedValue({}), + }, + }, + }; +} + +const context = { + repo: {owner: 'react', repo: 'react-native'}, + payload: {issue: {number: 1}}, +}; + +describe('checkForReproducer reproducer links', () => { + test.each([ + 'https://github.com/react/react-native/pull/58972', + 'https://github.com/facebook/react-native/pull/58972', + ])('accepts a pull request link as a reproducer: %s', async link => { + const github = buildGithub(`Reproducer: ${link}`); + + await checkForReproducer(github, context); + + expect(github.rest.issues.removeLabel).toHaveBeenCalledWith( + expect.objectContaining({name: 'Needs: Repro'}), + ); + expect(github.rest.issues.addLabels).not.toHaveBeenCalled(); + }); + + test.each([ + 'Reproducer: https://github.com/someone-else/some-repo/pull/12', + 'It crashes when I scroll.', + ])('asks for a reproducer when there is none: %s', async body => { + const github = buildGithub(body); + + await checkForReproducer(github, context); + + expect(github.rest.issues.addLabels).toHaveBeenCalledWith( + expect.objectContaining({ + labels: ['Needs: Repro', 'Needs: Author Feedback'], + }), + ); + expect(github.rest.issues.removeLabel).not.toHaveBeenCalled(); + }); +}); diff --git a/.github/workflow-scripts/__tests__/extractIssueOncalls-test.js b/.github/workflow-scripts/__tests__/extractIssueOncalls-test.js deleted file mode 100644 index 7ad91ddc06a1..000000000000 --- a/.github/workflow-scripts/__tests__/extractIssueOncalls-test.js +++ /dev/null @@ -1,83 +0,0 @@ -/** - * 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. - * - * @format - */ - -const {extractIssueOncalls} = require('../extractIssueOncalls'); - -const userMap = { - '@g': '1785', - '@c': '1781', - '@s': '1272', - '@d': '1332', - '@m': '9555', - '@p': '6097', - '@f': '7565', -}; - -const schedule = { - '2025-04-01': ['@m', '@f'], - '2025-04-08': ['@g', '@d'], -}; - -describe('extractIssueOncalls', () => { - beforeEach(() => { - jest.clearAllMocks(); - jest.useFakeTimers('modern'); - }); - - afterEach(() => { - jest.useRealTimers(); - }); - it('extracts m and f on 6 of April', () => { - jest.setSystemTime(new Date(2025, 3, 6)); - const oncalls = extractIssueOncalls(schedule, userMap); - expect(oncalls).toEqual([userMap['@m'], userMap['@f']]); - }); - - it('extracts m and f on 7 of April', () => { - jest.setSystemTime(new Date(2025, 3, 7)); - const oncalls = extractIssueOncalls(schedule, userMap); - expect(oncalls).toEqual([userMap['@m'], userMap['@f']]); - }); - - it('extracts g and d on 8 of April', () => { - jest.setSystemTime(new Date(2025, 3, 8)); - const oncalls = extractIssueOncalls(schedule, userMap); - expect(oncalls).toEqual([userMap['@g'], userMap['@d']]); - }); - - it('extracts g and d on 9 of April', () => { - jest.setSystemTime(new Date(2025, 3, 9)); - const oncalls = extractIssueOncalls(schedule, userMap); - expect(oncalls).toEqual([userMap['@g'], userMap['@d']]); - }); - - it('extracts g and d on 10 of April', () => { - jest.setSystemTime(new Date(2025, 3, 10)); - const oncalls = extractIssueOncalls(schedule, userMap); - expect(oncalls).toEqual([userMap['@g'], userMap['@d']]); - }); - - it('extracts g and d on 11 of April', () => { - jest.setSystemTime(new Date(2025, 3, 11)); - const oncalls = extractIssueOncalls(schedule, userMap); - expect(oncalls).toEqual([userMap['@g'], userMap['@d']]); - }); - - it('extracts g and d on 12 of April', () => { - jest.setSystemTime(new Date(2025, 3, 12)); - const oncalls = extractIssueOncalls(schedule, userMap); - expect(oncalls).toEqual([userMap['@g'], userMap['@d']]); - }); - - it('extracts g and d on 13 of April', () => { - jest.setSystemTime(new Date(2025, 3, 13)); - const oncalls = extractIssueOncalls(schedule, userMap); - expect(oncalls).toEqual([userMap['@g'], userMap['@d']]); - }); -}); diff --git a/.github/workflow-scripts/__tests__/generateChangelog-test.js b/.github/workflow-scripts/__tests__/generateChangelog-test.js deleted file mode 100644 index 346aa06cc708..000000000000 --- a/.github/workflow-scripts/__tests__/generateChangelog-test.js +++ /dev/null @@ -1,251 +0,0 @@ -/** - * 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. - * - * @format - */ - -const { - generateChangelog, - _computePreviousVersionFrom, - _generateChangelog, - _pushCommit, - _createPR, -} = require('../generateChangelog'); - -const silence = () => {}; -const mockGetNpmPackageInfo = jest.fn(); -const mockExecSync = jest.fn(); -const mockRun = jest.fn(); -const mockFetch = jest.fn(); -const mockExit = jest.fn(); - -jest.mock('../utils.js', () => ({ - log: silence, - run: mockRun, - getNpmPackageInfo: mockGetNpmPackageInfo, -})); - -process.exit = mockExit; -global.fetch = mockFetch; - -describe('Generate Changelog', () => { - beforeEach(jest.clearAllMocks); - - describe('_computePreviousVersionFrom', () => { - it('returns rc.0 when rc is 1', async () => { - const currentVersion = '0.78.0-rc.1'; - const expectedVersion = '0.78.0-rc.0'; - - const receivedVersion = await _computePreviousVersionFrom(currentVersion); - - expect(receivedVersion).toEqual(expectedVersion); - }); - - it('returns previous rc version when rc is > 1', async () => { - const currentVersion = '0.78.0-rc.5'; - const expectedVersion = '0.78.0-rc.4'; - - const receivedVersion = await _computePreviousVersionFrom(currentVersion); - - expect(receivedVersion).toEqual(expectedVersion); - }); - - it('returns previous patch version when rc is 0', async () => { - const currentVersion = '0.78.0-rc.0'; - const expectedVersion = '0.77.1'; - - mockGetNpmPackageInfo.mockReturnValueOnce( - Promise.resolve({version: '0.77.1'}), - ); - - const receivedVersion = await _computePreviousVersionFrom(currentVersion); - - expect(receivedVersion).toEqual(expectedVersion); - }); - - it('returns patch 0 when patch is 1', async () => { - const currentVersion = '0.78.1'; - const expectedVersion = '0.78.0'; - - const receivedVersion = await _computePreviousVersionFrom(currentVersion); - - expect(receivedVersion).toEqual(expectedVersion); - }); - - it('returns previous patch when patch is > 1', async () => { - const currentVersion = '0.78.5'; - const expectedVersion = '0.78.4'; - - const receivedVersion = await _computePreviousVersionFrom(currentVersion); - - expect(receivedVersion).toEqual(expectedVersion); - }); - - it('returns null when patch is 0', async () => { - const currentVersion = '0.78.0'; - - const receivedVersion = await _computePreviousVersionFrom(currentVersion); - - expect(receivedVersion).toBeNull(); - }); - - it("throws an error when the version can't be parsed", async () => { - const currentVersion = '0.78.0-rc0'; - - await expect( - _computePreviousVersionFrom(currentVersion), - ).rejects.toThrow(); - }); - }); - - describe('_generateChangelog', () => { - it('calls git in the right order', async () => { - const currentVersion = '0.79.0-rc5'; - const previousVersion = '0.79.0-rc4'; - const token = 'token'; - - expectedCommandArgs = [ - '@rnx-kit/rn-changelog-generator', - '--base', - `v${previousVersion}`, - '--compare', - `v${currentVersion}`, - '--repo', - '.', - '--changelog', - './CHANGELOG.md', - '--token', - `${token}`, - ]; - - _generateChangelog(previousVersion, currentVersion, token); - - expect(mockRun).toHaveBeenCalledTimes(4); - expect(mockRun).toHaveBeenNthCalledWith(1, 'git checkout main'); - expect(mockRun).toHaveBeenNthCalledWith(2, 'git fetch'); - expect(mockRun).toHaveBeenNthCalledWith(3, 'git pull origin main'); - expect(mockRun).toHaveBeenNthCalledWith( - 4, - `npx ${expectedCommandArgs.join(' ')}`, - ); - }); - }); - - describe('_pushCommit', () => { - it('calls git in the right order', async () => { - const currentVersion = '0.79.0-rc5'; - - _pushCommit(currentVersion); - - expect(mockRun).toHaveBeenCalledTimes(4); - expect(mockRun).toHaveBeenNthCalledWith( - 1, - `git checkout -b changelog/v${currentVersion}`, - ); - expect(mockRun).toHaveBeenNthCalledWith(2, 'git add CHANGELOG.md'); - expect(mockRun).toHaveBeenNthCalledWith( - 3, - `git commit -m "[RN][Changelog] Add changelog for v${currentVersion}"`, - ); - expect(mockRun).toHaveBeenNthCalledWith( - 4, - `git push origin changelog/v${currentVersion}`, - ); - }); - }); - - describe('_createPR', () => { - it('throws error when status is not 201', async () => { - const currentVersion = '0.79.0-rc5'; - const token = 'token'; - - mockFetch.mockReturnValueOnce(Promise.resolve({status: 401})); - - const headers = { - Accept: 'Accept: application/vnd.github+json', - 'X-GitHub-Api-Version': '2022-11-28', - Authorization: `Bearer ${token}`, - }; - - const content = ` -## Summary -Add Changelog for ${currentVersion} - -## Changelog: -[Internal] - Add Changelog for ${currentVersion} - -## Test Plan: -N/A`; - - const body = { - title: `[RN][Changelog] Add changelog for v${currentVersion}`, - head: `changelog/v${currentVersion}`, - base: 'main', - body: content, - }; - - await expect(_createPR(currentVersion, token)).rejects.toThrow(); - - expect(mockFetch).toHaveBeenCalledTimes(1); - expect(mockFetch).toHaveBeenCalledWith( - 'https://api.github.com/repos/facebook/react-native/pulls', - { - method: 'POST', - headers: headers, - body: JSON.stringify(body), - }, - ); - }); - it('Returns the pr url', async () => { - const currentVersion = '0.79.0-rc5'; - const token = 'token'; - const expectedPrURL = - 'https://github.com/facebook/react-native/pulls/1234'; - - const returnedObject = { - status: 201, - json: () => Promise.resolve({html_url: expectedPrURL}), - }; - mockFetch.mockReturnValueOnce(Promise.resolve(returnedObject)); - - const headers = { - Accept: 'Accept: application/vnd.github+json', - 'X-GitHub-Api-Version': '2022-11-28', - Authorization: `Bearer ${token}`, - }; - - const content = ` -## Summary -Add Changelog for ${currentVersion} - -## Changelog: -[Internal] - Add Changelog for ${currentVersion} - -## Test Plan: -N/A`; - - const body = { - title: `[RN][Changelog] Add changelog for v${currentVersion}`, - head: `changelog/v${currentVersion}`, - base: 'main', - body: content, - }; - - const receivedPrURL = await _createPR(currentVersion, token); - - expect(mockFetch).toHaveBeenCalledTimes(1); - expect(mockFetch).toHaveBeenCalledWith( - 'https://api.github.com/repos/facebook/react-native/pulls', - { - method: 'POST', - headers: headers, - body: JSON.stringify(body), - }, - ); - expect(receivedPrURL).toEqual(expectedPrURL); - }); - }); -}); diff --git a/.github/workflow-scripts/__tests__/maestro-android-test.js b/.github/workflow-scripts/__tests__/maestro-android-test.js index c07def601b2e..bf353061d97d 100644 --- a/.github/workflow-scripts/__tests__/maestro-android-test.js +++ b/.github/workflow-scripts/__tests__/maestro-android-test.js @@ -47,22 +47,16 @@ describe('Maestro Android runner', () => { }); it('excludes flows with matching tags', () => { - const releaseOnlyFlow = path.join( - temporaryDirectory, - 'android-release-only.yml', - ); + const releaseOnlyFlow = path.join(temporaryDirectory, 'release-only.yml'); const regularFlow = path.join(temporaryDirectory, 'regular.yml'); fs.writeFileSync( releaseOnlyFlow, - 'appId: x\ntags:\n - android-release-only\n---\n- launchApp\n', + 'appId: x\ntags:\n - release-only\n---\n- launchApp\n', ); fs.writeFileSync(regularFlow, 'appId: x\n---\n- launchApp\n'); expect( - filterFlowsByTags( - [releaseOnlyFlow, regularFlow], - ['android-release-only'], - ), + filterFlowsByTags([releaseOnlyFlow, regularFlow], ['release-only']), ).toEqual([regularFlow]); }); diff --git a/.github/workflow-scripts/__tests__/maestro-ios-test.js b/.github/workflow-scripts/__tests__/maestro-ios-test.js index 8b604ae1da66..636278940167 100644 --- a/.github/workflow-scripts/__tests__/maestro-ios-test.js +++ b/.github/workflow-scripts/__tests__/maestro-ios-test.js @@ -11,53 +11,263 @@ jest.mock('child_process', () => ({ execSync: jest.fn(), spawn: jest.fn(), })); -jest.mock('fs', () => ({ - existsSync: jest.fn(), - lstatSync: jest.fn(), - readdirSync: jest.fn(), -})); const childProcess = require('child_process'); +const {EventEmitter} = require('events'); const fs = require('fs'); +const os = require('os'); +const path = require('path'); + +const { + collectFlows, + executeFlowSuite, + filterFlowsByTags, + findAvailableSimulator, + loadState, + parseJUnitReport, + runMaestroFlow, +} = require('../maestro-ios'); -const {executeFlows, findAvailableSimulator} = require('../maestro-ios'); +// Simulates a single Maestro run in which the flows matching `failing` fail. +function suiteResults(failing = () => false) { + return jest.fn(async (appId, udid, flows) => { + return new Map( + flows.map(flow => [ + path.relative(process.cwd(), flow), + failing(flow) + ? {passed: false, error: 'failed assertion'} + : {passed: true}, + ]), + ); + }); +} describe('Maestro iOS runner', () => { + let temporaryDirectory; + beforeEach(() => { - jest.clearAllMocks(); - childProcess.spawn.mockReturnValue({pid: 1, kill: jest.fn()}); + jest.resetAllMocks(); + temporaryDirectory = fs.mkdtempSync( + path.join(os.tmpdir(), 'maestro-ios-test-'), + ); + jest.spyOn(console, 'error').mockImplementation(() => {}); + jest.spyOn(console, 'info').mockImplementation(() => {}); + jest.spyOn(console, 'log').mockImplementation(() => {}); + childProcess.spawn.mockImplementation(() => { + const recordingProcess = new EventEmitter(); + recordingProcess.pid = 1; + recordingProcess.kill = jest.fn(() => { + recordingProcess.emit('exit', 0, null); + return true; + }); + return recordingProcess; + }); + }); + + afterEach(() => { + jest.restoreAllMocks(); + fs.rmSync(temporaryDirectory, {recursive: true, force: true}); + }); + + it('collects YAML flows in a stable order and skips helpers and other files', () => { + const helpersDirectory = path.join(temporaryDirectory, 'helpers'); + const nestedDirectory = path.join(temporaryDirectory, 'nested'); + fs.mkdirSync(helpersDirectory); + fs.mkdirSync(nestedDirectory); + fs.writeFileSync(path.join(temporaryDirectory, 'second.yaml'), 'appId: x'); + fs.writeFileSync(path.join(temporaryDirectory, 'image.png'), 'not a flow'); + fs.writeFileSync(path.join(temporaryDirectory, 'first.yml'), 'appId: x'); + fs.writeFileSync(path.join(helpersDirectory, 'search.yml'), 'appId: x'); + fs.writeFileSync(path.join(nestedDirectory, 'third.yml'), 'appId: x'); + + expect(collectFlows(temporaryDirectory)).toEqual([ + path.join(temporaryDirectory, 'first.yml'), + path.join(nestedDirectory, 'third.yml'), + path.join(temporaryDirectory, 'second.yaml'), + ]); }); - it('executes each YAML flow separately and skips other files', () => { - fs.existsSync.mockReturnValue(true); - fs.lstatSync.mockImplementation(path => ({ - isDirectory: () => path === 'flows/', - })); - fs.readdirSync.mockReturnValue(['second.yaml', 'image.png', 'first.yml']); + it('excludes flows with matching tags', () => { + const androidOnlyFlow = path.join(temporaryDirectory, 'android-only.yml'); + const regularFlow = path.join(temporaryDirectory, 'regular.yml'); + fs.writeFileSync( + androidOnlyFlow, + 'appId: x\ntags:\n - android-only\n---\n- launchApp\n', + ); + fs.writeFileSync(regularFlow, 'appId: x\n---\n- launchApp\n'); + + expect( + filterFlowsByTags([androidOnlyFlow, regularFlow], ['android-only']), + ).toEqual([regularFlow]); + }); - executeFlows('com.example', 'device-id', 'flows/', 'Hermes'); + it('parses flow results from a Maestro JUnit report', () => { + const report = ` + + + + + Assertion is false: "Cheesecake" is visible + + + + +`; - expect(childProcess.execSync).toHaveBeenCalledTimes(2); + expect(parseJUnitReport(report)).toEqual( + new Map([ + ['flows/first.yml', {passed: true, error: 'SUCCESS'}], + [ + 'flows/second.yml', + {passed: false, error: 'Assertion is false: "Cheesecake" is visible'}, + ], + ['flows/third.yml', {passed: true, error: 'WARNING'}], + ]), + ); + }); + + it('runs all flows together, then retries each failure once on a rebooted simulator', async () => { + const flows = ['first.yml', 'second.yml', 'third.yml'].map(file => + path.join(temporaryDirectory, file), + ); + const statePath = path.join(temporaryDirectory, 'state', 'results.json'); + const executeSuite = suiteResults(flow => !flow.endsWith('first.yml')); + const executeFlow = jest.fn(async (appId, udid, flow) => { + if (flow.endsWith('second.yml')) { + throw new Error('failed again'); + } + }); + const resetSimulator = jest.fn(); + + await expect( + executeFlowSuite({ + flows, + appId: 'com.example', + udid: 'device-id', + state: loadState(statePath), + statePath, + executeSuite, + executeFlow, + resetSimulator, + }), + ).rejects.toThrow('1 Maestro flow(s) failed'); + + expect(executeSuite).toHaveBeenCalledTimes(1); + expect(executeSuite.mock.calls[0][2]).toEqual(flows); + expect(executeFlow.mock.calls.map(call => [call[2], call[3]])).toEqual([ + [flows[1], 2], + [flows[2], 2], + ]); + expect(resetSimulator).toHaveBeenCalledTimes(2); + expect(resetSimulator).toHaveBeenCalledWith('device-id'); + expect(Object.values(loadState(statePath).flows)).toEqual([ + {status: 'passed', attempts: 1}, + {status: 'failed', attempts: 2, error: 'failed again'}, + {status: 'passed', attempts: 2}, + ]); + }); + + it('does not retry when every flow passes', async () => { + const flow = path.join(temporaryDirectory, 'first.yml'); + const statePath = path.join(temporaryDirectory, 'results.json'); + const executeFlow = jest.fn(); + const resetSimulator = jest.fn(); + + await executeFlowSuite({ + flows: [flow], + appId: 'com.example', + udid: 'device-id', + state: loadState(statePath), + statePath, + executeSuite: suiteResults(), + executeFlow, + resetSimulator, + }); + + expect(executeFlow).not.toHaveBeenCalled(); + expect(resetSimulator).not.toHaveBeenCalled(); + expect(Object.values(loadState(statePath).flows)).toEqual([ + {status: 'passed', attempts: 1}, + ]); + }); + + it('only runs flows that have not passed in a previous CI attempt', async () => { + const flows = ['first.yml', 'second.yml'].map(file => + path.join(temporaryDirectory, file), + ); + const statePath = path.join(temporaryDirectory, 'results.json'); + await expect( + executeFlowSuite({ + flows, + appId: 'com.example', + udid: 'device-id', + state: loadState(statePath), + statePath, + executeSuite: suiteResults(flow => flow.endsWith('second.yml')), + executeFlow: jest.fn().mockRejectedValue(new Error('failed again')), + resetSimulator: jest.fn(), + }), + ).rejects.toThrow(); + + const executeSuite = suiteResults(); + await executeFlowSuite({ + flows, + appId: 'com.example', + udid: 'device-id', + state: loadState(statePath), + statePath, + executeSuite, + executeFlow: jest.fn(), + resetSimulator: jest.fn(), + }); + + expect(executeSuite).toHaveBeenCalledTimes(1); + expect(executeSuite.mock.calls[0][2]).toEqual([flows[1]]); + }); + + it('waits for the recorder to exit before returning', async () => { + const recordingProcess = new EventEmitter(); + recordingProcess.pid = 1; + recordingProcess.kill = jest.fn(() => true); + childProcess.spawn.mockReturnValueOnce(recordingProcess); + + let finished = false; + const execution = runMaestroFlow( + 'com.example', + 'device-id', + 'flows/first.yml', + 1, + ).then(() => { + finished = true; + }); + + await new Promise(resolve => + jest.requireActual('timers').setImmediate(resolve), + ); + + expect(recordingProcess.kill).toHaveBeenCalledWith('SIGINT'); expect(childProcess.execSync.mock.calls[0][0]).toContain( 'test "flows/first.yml"', ); - expect(childProcess.execSync.mock.calls[1][0]).toContain( - 'test "flows/second.yaml"', - ); + expect(finished).toBe(false); + + recordingProcess.emit('exit', 0, null); + await execution; + expect(finished).toBe(true); }); - it('retries only the failing flow', () => { - fs.existsSync.mockReturnValue(false); - childProcess.execSync.mockImplementationOnce(() => { - throw new Error('Maestro driver failed'); + it('stops the recorder when Maestro fails', async () => { + const error = new Error('Maestro driver failed'); + childProcess.execSync.mockImplementation(() => { + throw error; }); - executeFlows('com.example', 'device-id', 'flow.yml', 'Hermes'); + await expect( + runMaestroFlow('com.example', 'device-id', 'flow.yml', 2), + ).rejects.toBe(error); - expect(childProcess.execSync).toHaveBeenCalledTimes(2); - for (const call of childProcess.execSync.mock.calls) { - expect(call[0]).toContain('test "flow.yml"'); - } + const {value: recordingProcess} = childProcess.spawn.mock.results[0]; + expect(recordingProcess.kill).toHaveBeenCalledWith('SIGINT'); }); it('selects an iPhone Pro simulator from the latest runtime', () => { @@ -78,4 +288,33 @@ describe('Maestro iOS runner', () => { udid: 'new-pro', }); }); + + it('selects the configured device model and OS', () => { + childProcess.execSync.mockReturnValue( + JSON.stringify({ + devices: { + 'com.apple.CoreSimulator.SimRuntime.iOS-26-0': [ + {name: 'iPhone 17 Pro', udid: 'wrong-runtime'}, + ], + 'com.apple.CoreSimulator.SimRuntime.iOS-26-2': [ + {name: 'iPhone 17 Pro Max', udid: 'wrong-model'}, + {name: 'iPhone 17 Pro', udid: 'expected'}, + ], + }, + }), + ); + + expect(findAvailableSimulator('iPhone-17-Pro', 'iOS-26-2')).toEqual({ + name: 'iPhone 17 Pro', + udid: 'expected', + }); + }); + + it('fails when the configured simulator is unavailable', () => { + childProcess.execSync.mockReturnValue(JSON.stringify({devices: {}})); + + expect(() => findAvailableSimulator('iPhone-17-Pro', 'iOS-26-2')).toThrow( + 'Unable to find iPhone 17 Pro simulator on iOS-26-2', + ); + }); }); diff --git a/.github/workflow-scripts/__tests__/publishTemplate-test.js b/.github/workflow-scripts/__tests__/publishTemplate-test.js index 9f735a633977..25734752cf4c 100644 --- a/.github/workflow-scripts/__tests__/publishTemplate-test.js +++ b/.github/workflow-scripts/__tests__/publishTemplate-test.js @@ -7,11 +7,6 @@ * @format */ -const { - publishTemplate, - verifyPublishedTemplate, -} = require('../publishTemplate'); - const mockRun = jest.fn(); const mockSleep = jest.fn(); const mockGetNpmPackageInfo = jest.fn(); @@ -29,6 +24,11 @@ jest.mock('../verifyPublishedPackage.js', () => ({ verifyPublishedPackage: mockVerifyPublishedPackage, })); +const { + publishTemplate, + verifyPublishedTemplate, +} = require('../publishTemplate'); + const getMockGithub = () => ({ rest: { actions: { diff --git a/.github/workflow-scripts/__tests__/report-test-results-test.js b/.github/workflow-scripts/__tests__/report-test-results-test.js new file mode 100644 index 000000000000..77b44f4438f4 --- /dev/null +++ b/.github/workflow-scripts/__tests__/report-test-results-test.js @@ -0,0 +1,388 @@ +/** + * 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. + * + * @format + */ + +const {recordJobFailure, reportTestResults} = require('../report-test-results'); + +const context = { + serverUrl: 'https://github.com', + repo: {owner: 'react', repo: 'react-native'}, + runId: 40446700902, + job: 'test', +}; +const jobUrl = + 'https://github.com/react/react-native/actions/runs/40446700902/job/122302861049'; +const failedTest = {outcome: 'failure', conclusion: 'success'}; + +function createCore() { + const core = { + setOutput: jest.fn(), + setFailed: jest.fn(), + warning: jest.fn(), + summary: {addRaw: jest.fn(), write: jest.fn().mockResolvedValue(undefined)}, + }; + core.summary.addRaw.mockReturnValue(core.summary); + return core; +} + +function createGithub(jobs) { + return { + paginate: jest.fn().mockResolvedValue(jobs), + rest: {actions: {listJobsForWorkflowRunAttempt: jest.fn()}}, + }; +} + +function job(name, url = jobUrl) { + return {name, html_url: url, runner_name: 'runner', status: 'in_progress'}; +} + +function recordArguments(core, github, steps = {'run-tests': failedTest}) { + return { + context, + core, + github, + steps, + flavor: 'debug', + runnerName: 'runner', + attempt: 2, + jobStatus: 'success', + }; +} + +async function render(needs, failOnError = true) { + const core = createCore(); + await reportTestResults({context, core, needs, failOnError, attempt: 3}); + return core; +} + +describe('test job failure recording', () => { + it('records tolerated test failures with their exact job name and log link', async () => { + const core = createCore(); + const name = 'test_e2e_android_rntester_retry_2 / test (debug)'; + const github = createGithub([job(name)]); + await recordJobFailure(recordArguments(core, github)); + expect(core.setOutput).toHaveBeenCalledWith('status', 'failure'); + expect(core.setOutput).toHaveBeenCalledWith( + 'failure-debug', + JSON.stringify({name, url: jobUrl, steps: ['run-tests']}), + ); + expect(github.paginate).toHaveBeenCalledWith( + github.rest.actions.listJobsForWorkflowRunAttempt, + { + owner: 'react', + repo: 'react-native', + run_id: context.runId, + attempt_number: 2, + per_page: 100, + }, + ); + }); + + it('records failures in steps without an explicit id using the job status and API', async () => { + const core = createCore(); + const github = createGithub([ + { + ...job('template / build (Debug)'), + steps: [{name: 'Build the app', conclusion: 'failure'}], + }, + ]); + await recordJobFailure({ + ...recordArguments(core, github, {}), + context: {...context, job: 'build'}, + flavor: 'Debug', + jobStatus: 'failure', + }); + expect(JSON.parse(core.setOutput.mock.calls[1][1])).toEqual({ + name: 'template / build (Debug)', + url: jobUrl, + steps: ['Build the app'], + }); + }); + + it('does not overwrite matrix failures when another configuration passes', async () => { + const core = createCore(); + const github = createGithub([]); + await recordJobFailure( + recordArguments(core, github, { + 'run-tests': {outcome: 'success', conclusion: 'success'}, + }), + ); + expect(core.setOutput).not.toHaveBeenCalled(); + expect(github.paginate).not.toHaveBeenCalled(); + }); + + it('ignores tolerated state-download failures when tests pass', async () => { + const core = createCore(); + const github = createGithub([]); + await recordJobFailure( + recordArguments(core, github, { + download: {outcome: 'failure', conclusion: 'success'}, + 'run-tests': {outcome: 'success', conclusion: 'success'}, + }), + ); + expect(core.setOutput).not.toHaveBeenCalled(); + }); + + it.each(['failure', 'cancelled'])( + 'records an upstream step with outcome %s', + async outcome => { + const core = createCore(); + const github = createGithub([job('test (debug)')]); + await recordJobFailure( + recordArguments(core, github, { + setup: {outcome, conclusion: outcome}, + 'run-tests': {outcome: 'skipped', conclusion: 'skipped'}, + }), + ); + expect(JSON.parse(core.setOutput.mock.calls[1][1]).steps).toEqual([ + 'setup', + ]); + }, + ); + + it('preserves the failure when the API lookup fails', async () => { + const core = createCore(); + const github = createGithub([]); + github.paginate.mockRejectedValue(new Error('permission denied')); + await recordJobFailure(recordArguments(core, github)); + expect(core.setOutput).toHaveBeenCalledWith('status', 'failure'); + expect(JSON.parse(core.setOutput.mock.calls[1][1])).toEqual({ + name: 'test (debug)', + url: `${context.serverUrl}/react/react-native/actions/runs/${context.runId}/attempts/2`, + steps: ['run-tests'], + }); + expect(core.warning).toHaveBeenCalled(); + }); + + it.each(['debug', 'release'])( + 'identifies the %s job when concurrent matrix jobs share a runner name', + async flavor => { + const core = createCore(); + const name = `caller / test (${flavor})`; + const url = `${jobUrl}-${flavor}`; + const github = createGithub([ + job('caller / test (release)', `${jobUrl}-release`), + job('caller / test (debug)', `${jobUrl}-debug`), + ]); + await recordJobFailure({...recordArguments(core, github), flavor}); + expect(core.setOutput).toHaveBeenCalledWith( + `failure-${flavor}`, + JSON.stringify({name, url, steps: ['run-tests']}), + ); + expect(core.warning).not.toHaveBeenCalled(); + }, + ); + + it('distinguishes build and test jobs on the same runner', async () => { + const core = createCore(); + const github = createGithub([ + job('caller / test (debug)'), + job('caller / build (debug)', `${jobUrl}-build`), + ]); + await recordJobFailure({ + ...recordArguments(core, github, {}), + context: {...context, job: 'build'}, + jobStatus: 'failure', + }); + expect(JSON.parse(core.setOutput.mock.calls[1][1])).toEqual({ + name: 'caller / build (debug)', + url: `${jobUrl}-build`, + steps: ['job failure'], + }); + }); + + it('does not link a completed retry when the current job is not listed', async () => { + const core = createCore(); + const github = createGithub([ + {...job('earlier / test (debug)'), status: 'completed'}, + ]); + await recordJobFailure(recordArguments(core, github)); + expect(JSON.parse(core.setOutput.mock.calls[1][1]).url).toBe( + `${context.serverUrl}/react/react-native/actions/runs/${context.runId}/attempts/2`, + ); + expect(core.warning).toHaveBeenCalled(); + }); + + it('selects only the current job on a reused runner', async () => { + const core = createCore(); + const github = createGithub([ + {...job('earlier / test (debug)'), status: 'completed'}, + job('current / test (debug)'), + {...job('other / test (debug)'), runner_name: 'other-runner'}, + ]); + await recordJobFailure(recordArguments(core, github)); + expect(JSON.parse(core.setOutput.mock.calls[1][1]).name).toBe( + 'current / test (debug)', + ); + }); + + it('falls back rather than linking to an ambiguous job', async () => { + const core = createCore(); + const github = createGithub([ + job('first / test (debug)'), + job('second / test (debug)'), + ]); + await recordJobFailure(recordArguments(core, github)); + expect(JSON.parse(core.setOutput.mock.calls[1][1]).name).toBe( + 'test (debug)', + ); + expect(core.warning).toHaveBeenCalled(); + }); + + it('normalises iOS matrix names and supports non-matrix jobs', async () => { + const core = createCore(); + const args = recordArguments( + core, + createGithub([job('caller / test (Release)'), job('caller / test')]), + ); + await recordJobFailure({...args, flavor: 'Release'}); + expect(core.setOutput.mock.calls[1][0]).toBe('failure-release'); + expect(JSON.parse(core.setOutput.mock.calls[1][1]).name).toBe( + 'caller / test (Release)', + ); + await recordJobFailure({...args, flavor: undefined}); + expect(core.setOutput.mock.calls[3][0]).toBe('failure'); + expect(JSON.parse(core.setOutput.mock.calls[3][1]).name).toBe( + 'caller / test', + ); + }); +}); + +describe('test report jobs', () => { + it('reports both failing configurations even though their job conclusion is success', async () => { + const debug = { + name: 'test / test (debug)', + url: jobUrl, + steps: ['run-tests'], + }; + const release = { + ...debug, + name: 'test / test (release)', + url: `${jobUrl}-release`, + }; + const core = await render({ + test: { + result: 'success', + outputs: { + status: 'failure', + 'failure-debug': JSON.stringify(debug), + 'failure-release': JSON.stringify(release), + }, + }, + }); + expect(core.setOutput).toHaveBeenCalledWith('status', 'failure'); + expect(core.setFailed).toHaveBeenCalledWith( + expect.stringContaining(debug.name), + ); + expect(core.setFailed).toHaveBeenCalledWith( + expect.stringContaining(release.name), + ); + const summary = core.summary.addRaw.mock.calls[0][0]; + expect(summary).toContain(`](${debug.url})`); + expect(summary).toContain(`](${release.url})`); + }); + + it('does not hide an unrecorded setup failure behind another matrix failure', async () => { + const core = await render({ + test: { + result: 'failure', + outputs: { + status: 'failure', + 'failure-release': JSON.stringify({ + name: 'test (release)', + url: jobUrl, + steps: ['run-tests'], + }), + }, + }, + }); + expect(core.setFailed).toHaveBeenCalledWith( + expect.stringContaining('test (release)'), + ); + expect(core.setFailed).toHaveBeenCalledWith( + expect.stringContaining('test: job failure'), + ); + }); + + it('keeps intermediate retries non-fatal while reporting their failures', async () => { + const core = await render( + {test: {result: 'success', outputs: {status: 'failure'}}}, + false, + ); + expect(core.setOutput).toHaveBeenCalledWith('status', 'failure'); + expect(core.setFailed).not.toHaveBeenCalled(); + expect(core.warning).toHaveBeenCalledWith( + expect.stringContaining('test: run-tests'), + ); + }); + + it.each(['failure', 'cancelled', 'skipped'])( + 'does not report an upstream %s as success', + async result => { + const core = await render({test: {result, outputs: {}}}); + expect(core.setFailed).toHaveBeenCalledWith( + expect.stringContaining(`job ${result}`), + ); + expect(core.setOutput).toHaveBeenCalledWith('status', 'failure'); + }, + ); + + it('reports build failures and skipped dependent tests', async () => { + const core = await render({ + build: { + result: 'failure', + outputs: { + 'failure-debug': JSON.stringify({ + name: 'template / build (Debug)', + url: jobUrl, + steps: ['build-app'], + }), + }, + }, + test: {result: 'skipped', outputs: {}}, + }); + expect(core.setFailed).toHaveBeenCalledWith( + expect.stringContaining('template / build (Debug)'), + ); + expect(core.setFailed).toHaveBeenCalledWith( + expect.stringContaining('test: job skipped'), + ); + }); + + it('reports success without failing or warning', async () => { + const core = await render({ + test: { + result: 'success', + outputs: {'failure-debug': '', 'failure-release': ''}, + }, + }); + expect(core.setOutput).toHaveBeenCalledWith('status', 'success'); + expect(core.setFailed).not.toHaveBeenCalled(); + expect(core.warning).not.toHaveBeenCalled(); + expect(core.summary.write).toHaveBeenCalled(); + }); + + it('escapes job and step names in the Markdown summary', async () => { + const core = await render({ + test: { + result: 'success', + outputs: { + failure: JSON.stringify({ + name: '