diff --git a/.github/actions/platform-check/action.yml b/.github/actions/platform-check/action.yml new file mode 100644 index 0000000000..aa422cdd76 --- /dev/null +++ b/.github/actions/platform-check/action.yml @@ -0,0 +1,62 @@ +name: 'Platform Check' +description: 'Decides whether to skip a build/test based on detect-changes outputs' + +inputs: + platform: + description: 'Target platform (ios, macos, android, web)' + required: true + sample_changed: + description: 'Whether the sample app itself changed (true/false)' + required: true + needs_ios: + description: 'detect-changes needs_ios output' + required: false + default: 'false' + needs_android: + description: 'detect-changes needs_android output' + required: false + default: 'false' + needs_web: + description: 'detect-changes needs_web output' + required: false + default: 'false' + +outputs: + skip: + description: 'Whether to skip this platform (true/false)' + value: ${{ steps.check.outputs.skip }} + +runs: + using: 'composite' + steps: + - name: Check if platform is needed + id: check + shell: bash + run: | + PLATFORM="${{ inputs.platform }}" + SAMPLE_CHANGED="${{ inputs.sample_changed }}" + + if [[ "$SAMPLE_CHANGED" == "true" ]]; then + echo "skip=false" >> "$GITHUB_OUTPUT" + echo "Sample app changed — building/testing $PLATFORM." + exit 0 + fi + + # macOS uses the iOS change-detection flag + case "$PLATFORM" in + ios|macos) NEEDS="${{ inputs.needs_ios }}" ;; + android) NEEDS="${{ inputs.needs_android }}" ;; + web) NEEDS="${{ inputs.needs_web }}" ;; + *) + echo "::warning::Unknown platform '$PLATFORM' — not skipping." + echo "skip=false" >> "$GITHUB_OUTPUT" + exit 0 + ;; + esac + + if [[ "$NEEDS" != "true" ]]; then + echo "skip=true" >> "$GITHUB_OUTPUT" + echo "Skipping $PLATFORM — no relevant changes detected." + else + echo "skip=false" >> "$GITHUB_OUTPUT" + fi diff --git a/.github/workflows/sample-application-expo.yml b/.github/workflows/sample-application-expo.yml index fa45424642..16c4138ef5 100644 --- a/.github/workflows/sample-application-expo.yml +++ b/.github/workflows/sample-application-expo.yml @@ -59,27 +59,17 @@ jobs: - platform: 'android' ios-use-frameworks: 'dynamic-frameworks' steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + - name: Check if platform is needed id: platform-check - run: | - SAMPLE_CHANGED="${{ needs.detect-changes.outputs.sample_expo }}" - - if [[ "$SAMPLE_CHANGED" == "true" ]]; then - echo "skip=false" >> "$GITHUB_OUTPUT" - echo "Sample app changed — building ${{ matrix.platform }}." - elif [[ "${{ matrix.platform }}" == "ios" && "${{ needs.detect-changes.outputs.needs_ios }}" != "true" ]]; then - echo "skip=true" >> "$GITHUB_OUTPUT" - echo "Skipping iOS — no relevant changes detected." - elif [[ "${{ matrix.platform }}" == "android" && "${{ needs.detect-changes.outputs.needs_android }}" != "true" ]]; then - echo "skip=true" >> "$GITHUB_OUTPUT" - echo "Skipping Android — no relevant changes detected." - elif [[ "${{ matrix.platform }}" == "web" && "${{ needs.detect-changes.outputs.needs_web }}" != "true" ]]; then - echo "skip=true" >> "$GITHUB_OUTPUT" - echo "Skipping Web — no relevant changes detected." - fi - - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - if: ${{ steps.platform-check.outputs.skip != 'true' }} + uses: ./.github/actions/platform-check + with: + platform: ${{ matrix.platform }} + sample_changed: ${{ needs.detect-changes.outputs.sample_expo }} + needs_ios: ${{ needs.detect-changes.outputs.needs_ios }} + needs_android: ${{ needs.detect-changes.outputs.needs_android }} + needs_web: ${{ needs.detect-changes.outputs.needs_web }} - name: Enable Corepack (NPM) if: ${{ steps.platform-check.outputs.skip != 'true' && matrix.platform != 'ios' }} diff --git a/.github/workflows/sample-application.yml b/.github/workflows/sample-application.yml index fe90ca546e..61653c65aa 100644 --- a/.github/workflows/sample-application.yml +++ b/.github/workflows/sample-application.yml @@ -74,32 +74,16 @@ jobs: - ios-use-frameworks: 'dynamic-frameworks' platform: 'macos' steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + - name: Check if platform is needed id: platform-check - run: | - # Sample app changes should always build all platforms (that's the - # whole point of this workflow). The needs_ios/needs_android flags - # only track SDK source & native code — not sample app files. - SAMPLE_CHANGED="${{ needs.detect-changes.outputs.sample_react_native }}" - - if [[ "$SAMPLE_CHANGED" == "true" ]]; then - echo "skip=false" >> "$GITHUB_OUTPUT" - echo "Sample app changed — building ${{ matrix.platform }}." - elif [[ "${{ matrix.platform }}" == "ios" && "${{ needs.detect-changes.outputs.needs_ios }}" != "true" ]]; then - echo "skip=true" >> "$GITHUB_OUTPUT" - echo "Skipping iOS — no relevant changes detected." - elif [[ "${{ matrix.platform }}" == "macos" && "${{ needs.detect-changes.outputs.needs_ios }}" != "true" ]]; then - echo "skip=true" >> "$GITHUB_OUTPUT" - echo "Skipping macOS — no relevant changes detected." - elif [[ "${{ matrix.platform }}" == "android" && "${{ needs.detect-changes.outputs.needs_android }}" != "true" ]]; then - echo "skip=true" >> "$GITHUB_OUTPUT" - echo "Skipping Android — no relevant changes detected." - else - echo "skip=false" >> "$GITHUB_OUTPUT" - fi - - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - if: ${{ steps.platform-check.outputs.skip != 'true' }} + uses: ./.github/actions/platform-check + with: + platform: ${{ matrix.platform }} + sample_changed: ${{ needs.detect-changes.outputs.sample_react_native }} + needs_ios: ${{ needs.detect-changes.outputs.needs_ios }} + needs_android: ${{ needs.detect-changes.outputs.needs_android }} - name: Enable Corepack (NPM) if: ${{ steps.platform-check.outputs.skip != 'true' && matrix.platform == 'android' }} @@ -264,26 +248,16 @@ jobs: build-type: 'production' steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + - name: Check if platform is needed id: platform-check - run: | - SAMPLE_CHANGED="${{ needs.detect-changes.outputs.sample_react_native }}" - - if [[ "$SAMPLE_CHANGED" == "true" ]]; then - echo "skip=false" >> "$GITHUB_OUTPUT" - echo "Sample app changed — testing ${{ matrix.platform }}." - elif [[ "${{ matrix.platform }}" == "ios" && "${{ needs.detect-changes.outputs.needs_ios }}" != "true" ]]; then - echo "skip=true" >> "$GITHUB_OUTPUT" - echo "Skipping iOS — no relevant changes detected." - elif [[ "${{ matrix.platform }}" == "android" && "${{ needs.detect-changes.outputs.needs_android }}" != "true" ]]; then - echo "skip=true" >> "$GITHUB_OUTPUT" - echo "Skipping Android — no relevant changes detected." - else - echo "skip=false" >> "$GITHUB_OUTPUT" - fi - - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - if: ${{ steps.platform-check.outputs.skip != 'true' }} + uses: ./.github/actions/platform-check + with: + platform: ${{ matrix.platform }} + sample_changed: ${{ needs.detect-changes.outputs.sample_react_native }} + needs_ios: ${{ needs.detect-changes.outputs.needs_ios }} + needs_android: ${{ needs.detect-changes.outputs.needs_android }} - name: Install Maestro if: ${{ steps.platform-check.outputs.skip != 'true' }}