diff --git a/.github/workflows/test-all.yml b/.github/workflows/test-all.yml index 825887470456..4b0b40d1ac19 100644 --- a/.github/workflows/test-all.yml +++ b/.github/workflows/test-all.yml @@ -675,3 +675,51 @@ jobs: - name: Verify debugger-shell build shell: bash run: node scripts/debugger-shell/build-binary.js + + # Require this job in branch protection instead of a platform-specific build. + # Unlike the builds, it reports a result even when a platform is intentionally skipped. + native_builds_gate: + runs-on: ubuntu-latest + needs: [check_code_changes, build_android, test_ios_rntester] + if: ${{ always() && github.repository == 'react/react-native' }} + steps: + - name: Verify required native builds + shell: bash + env: + CODE_CHANGES_RESULT: ${{ needs.check_code_changes.result }} + ANY_CODE_CHANGE: ${{ needs.check_code_changes.outputs.any_code_change }} + SHOULD_TEST_ANDROID: ${{ needs.check_code_changes.outputs.should_test_android }} + SHOULD_TEST_IOS: ${{ needs.check_code_changes.outputs.should_test_ios }} + ANDROID_RESULT: ${{ needs.build_android.result }} + IOS_RESULT: ${{ needs.test_ios_rntester.result }} + run: | + set -e + + if [[ "$CODE_CHANGES_RESULT" != success ]]; then + echo "::error::Could not determine which native builds are required ($CODE_CHANGES_RESULT)" + exit 1 + fi + + check_build() { + local platform="$1" required="$2" result="$3" + if [[ "$required" == true ]]; then + if [[ "$result" != success ]]; then + echo "::error::$platform build required but finished with $result" + return 1 + fi + elif [[ "$result" != skipped && "$result" != success ]]; then + echo "::error::$platform build was not required but finished with $result" + return 1 + fi + echo "$platform build: $result (required: $required)" + } + + android_required=false + ios_required=false + if [[ "$ANY_CODE_CHANGE" == true ]]; then + android_required="$SHOULD_TEST_ANDROID" + ios_required="$SHOULD_TEST_IOS" + fi + + check_build Android "$android_required" "$ANDROID_RESULT" + check_build iOS "$ios_required" "$IOS_RESULT"