Skip to content

Commit 1ef0114

Browse files
committed
refactor(ci): Extract platform-check into a reusable composite action
The platform-check step that decides whether to skip a build based on detect-changes outputs was duplicated across sample app workflows (sample-application.yml, sample-application-expo.yml) and across the build and test jobs within sample-application.yml. Extract the logic into a composite action at .github/actions/platform-check that takes the platform name, a sample_changed flag, and the needs_ios/needs_android/needs_web outputs as inputs, and returns a single skip output. The action handles the macOS → needs_ios mapping and includes a warning for unknown platforms. Replaces three inline bash scripts with a single reusable action. Closes #5865
1 parent beeb5b9 commit 1ef0114

3 files changed

Lines changed: 81 additions & 52 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: 'Platform Check'
2+
description: 'Decides whether to skip a build/test based on detect-changes outputs'
3+
4+
inputs:
5+
platform:
6+
description: 'Target platform (ios, macos, android, web)'
7+
required: true
8+
sample_changed:
9+
description: 'Whether the sample app itself changed (true/false)'
10+
required: true
11+
needs_ios:
12+
description: 'detect-changes needs_ios output'
13+
required: false
14+
default: 'false'
15+
needs_android:
16+
description: 'detect-changes needs_android output'
17+
required: false
18+
default: 'false'
19+
needs_web:
20+
description: 'detect-changes needs_web output'
21+
required: false
22+
default: 'false'
23+
24+
outputs:
25+
skip:
26+
description: 'Whether to skip this platform (true/false)'
27+
value: ${{ steps.check.outputs.skip }}
28+
29+
runs:
30+
using: 'composite'
31+
steps:
32+
- name: Check if platform is needed
33+
id: check
34+
shell: bash
35+
run: |
36+
PLATFORM="${{ inputs.platform }}"
37+
SAMPLE_CHANGED="${{ inputs.sample_changed }}"
38+
39+
if [[ "$SAMPLE_CHANGED" == "true" ]]; then
40+
echo "skip=false" >> "$GITHUB_OUTPUT"
41+
echo "Sample app changed — building/testing $PLATFORM."
42+
exit 0
43+
fi
44+
45+
# macOS uses the iOS change-detection flag
46+
case "$PLATFORM" in
47+
ios|macos) NEEDS="${{ inputs.needs_ios }}" ;;
48+
android) NEEDS="${{ inputs.needs_android }}" ;;
49+
web) NEEDS="${{ inputs.needs_web }}" ;;
50+
*)
51+
echo "::warning::Unknown platform '$PLATFORM' — not skipping."
52+
echo "skip=false" >> "$GITHUB_OUTPUT"
53+
exit 0
54+
;;
55+
esac
56+
57+
if [[ "$NEEDS" != "true" ]]; then
58+
echo "skip=true" >> "$GITHUB_OUTPUT"
59+
echo "Skipping $PLATFORM — no relevant changes detected."
60+
else
61+
echo "skip=false" >> "$GITHUB_OUTPUT"
62+
fi

.github/workflows/sample-application-expo.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,13 @@ jobs:
6161
steps:
6262
- name: Check if platform is needed
6363
id: platform-check
64-
run: |
65-
SAMPLE_CHANGED="${{ needs.detect-changes.outputs.sample_expo }}"
66-
67-
if [[ "$SAMPLE_CHANGED" == "true" ]]; then
68-
echo "skip=false" >> "$GITHUB_OUTPUT"
69-
echo "Sample app changed — building ${{ matrix.platform }}."
70-
elif [[ "${{ matrix.platform }}" == "ios" && "${{ needs.detect-changes.outputs.needs_ios }}" != "true" ]]; then
71-
echo "skip=true" >> "$GITHUB_OUTPUT"
72-
echo "Skipping iOS — no relevant changes detected."
73-
elif [[ "${{ matrix.platform }}" == "android" && "${{ needs.detect-changes.outputs.needs_android }}" != "true" ]]; then
74-
echo "skip=true" >> "$GITHUB_OUTPUT"
75-
echo "Skipping Android — no relevant changes detected."
76-
elif [[ "${{ matrix.platform }}" == "web" && "${{ needs.detect-changes.outputs.needs_web }}" != "true" ]]; then
77-
echo "skip=true" >> "$GITHUB_OUTPUT"
78-
echo "Skipping Web — no relevant changes detected."
79-
fi
64+
uses: ./.github/actions/platform-check
65+
with:
66+
platform: ${{ matrix.platform }}
67+
sample_changed: ${{ needs.detect-changes.outputs.sample_expo }}
68+
needs_ios: ${{ needs.detect-changes.outputs.needs_ios }}
69+
needs_android: ${{ needs.detect-changes.outputs.needs_android }}
70+
needs_web: ${{ needs.detect-changes.outputs.needs_web }}
8071

8172
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
8273
if: ${{ steps.platform-check.outputs.skip != 'true' }}

.github/workflows/sample-application.yml

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,12 @@ jobs:
7676
steps:
7777
- name: Check if platform is needed
7878
id: platform-check
79-
run: |
80-
# Sample app changes should always build all platforms (that's the
81-
# whole point of this workflow). The needs_ios/needs_android flags
82-
# only track SDK source & native code — not sample app files.
83-
SAMPLE_CHANGED="${{ needs.detect-changes.outputs.sample_react_native }}"
84-
85-
if [[ "$SAMPLE_CHANGED" == "true" ]]; then
86-
echo "skip=false" >> "$GITHUB_OUTPUT"
87-
echo "Sample app changed — building ${{ matrix.platform }}."
88-
elif [[ "${{ matrix.platform }}" == "ios" && "${{ needs.detect-changes.outputs.needs_ios }}" != "true" ]]; then
89-
echo "skip=true" >> "$GITHUB_OUTPUT"
90-
echo "Skipping iOS — no relevant changes detected."
91-
elif [[ "${{ matrix.platform }}" == "macos" && "${{ needs.detect-changes.outputs.needs_ios }}" != "true" ]]; then
92-
echo "skip=true" >> "$GITHUB_OUTPUT"
93-
echo "Skipping macOS — no relevant changes detected."
94-
elif [[ "${{ matrix.platform }}" == "android" && "${{ needs.detect-changes.outputs.needs_android }}" != "true" ]]; then
95-
echo "skip=true" >> "$GITHUB_OUTPUT"
96-
echo "Skipping Android — no relevant changes detected."
97-
else
98-
echo "skip=false" >> "$GITHUB_OUTPUT"
99-
fi
79+
uses: ./.github/actions/platform-check
80+
with:
81+
platform: ${{ matrix.platform }}
82+
sample_changed: ${{ needs.detect-changes.outputs.sample_react_native }}
83+
needs_ios: ${{ needs.detect-changes.outputs.needs_ios }}
84+
needs_android: ${{ needs.detect-changes.outputs.needs_android }}
10085

10186
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
10287
if: ${{ steps.platform-check.outputs.skip != 'true' }}
@@ -266,21 +251,12 @@ jobs:
266251
steps:
267252
- name: Check if platform is needed
268253
id: platform-check
269-
run: |
270-
SAMPLE_CHANGED="${{ needs.detect-changes.outputs.sample_react_native }}"
271-
272-
if [[ "$SAMPLE_CHANGED" == "true" ]]; then
273-
echo "skip=false" >> "$GITHUB_OUTPUT"
274-
echo "Sample app changed — testing ${{ matrix.platform }}."
275-
elif [[ "${{ matrix.platform }}" == "ios" && "${{ needs.detect-changes.outputs.needs_ios }}" != "true" ]]; then
276-
echo "skip=true" >> "$GITHUB_OUTPUT"
277-
echo "Skipping iOS — no relevant changes detected."
278-
elif [[ "${{ matrix.platform }}" == "android" && "${{ needs.detect-changes.outputs.needs_android }}" != "true" ]]; then
279-
echo "skip=true" >> "$GITHUB_OUTPUT"
280-
echo "Skipping Android — no relevant changes detected."
281-
else
282-
echo "skip=false" >> "$GITHUB_OUTPUT"
283-
fi
254+
uses: ./.github/actions/platform-check
255+
with:
256+
platform: ${{ matrix.platform }}
257+
sample_changed: ${{ needs.detect-changes.outputs.sample_react_native }}
258+
needs_ios: ${{ needs.detect-changes.outputs.needs_ios }}
259+
needs_android: ${{ needs.detect-changes.outputs.needs_android }}
284260

285261
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
286262
if: ${{ steps.platform-check.outputs.skip != 'true' }}

0 commit comments

Comments
 (0)