@@ -11,7 +11,10 @@ description: 'Install a ready Release build of examples/test-app on the booted i
1111# Release build embedded may be stale — @expo/repack-app swaps in a bundle built
1212# from the current source. If no artifact exists yet (the producer has not run
1313# for this fingerprint), it falls back to building inline, so a caller is never
14- # left without an app.
14+ # left without an app. Callers that run alongside the producer can opt into a
15+ # bounded wait first, avoiding two simultaneous native builds on a cold key.
16+ # Artifact hits are accepted only from this repository's designated producer
17+ # workflow at the current head or from a default-branch push.
1518#
1619# The caller's job needs `permissions: actions: read` for the artifact lookup.
1720# Relevant to #320 (move replay coverage off system apps onto a stable fixture).
@@ -25,7 +28,10 @@ inputs:
2528 description : ' Install the app onto the booted simulator'
2629 required : false
2730 default : ' true'
28-
31+ wait-for-artifact-seconds :
32+ description : ' How long to poll for a concurrently produced artifact before building inline'
33+ required : false
34+ default : ' 0'
2935outputs :
3036 app-path :
3137 description : ' Path to the ready .app bundle'
@@ -40,11 +46,10 @@ outputs:
4046runs :
4147 using : ' composite'
4248 steps :
43- # Installed even on a hit, because the fingerprint is derived from the
44- # dependency graph and cannot be computed without it.
45- - name : Install test app dependencies
46- shell : bash
47- run : pnpm test-app:install
49+ # The fingerprint/repack commands need the dependency graph. This shared
50+ # action avoids recreating it on every warm native-artifact consumer.
51+ - name : Setup test app dependencies
52+ uses : ./.github/actions/setup-test-app-dependencies
4853
4954 - name : Fetch the cached Release binary
5055 id : fetch
@@ -53,19 +58,80 @@ runs:
5358 GH_TOKEN : ${{ github.token }}
5459 run : |
5560 set -euo pipefail
56- HASH="$(pnpm --dir examples/test-app exec fingerprint fingerprint:generate | jq -r .hash)"
57- NAME="fingerprint.${HASH}.ios"
61+ NAME="$(sh "$GITHUB_ACTION_PATH/resolve-artifact-name.sh" ios)"
5862 DEST="${{ github.workspace }}/.tmp/fixture-app"
63+ REPOSITORY="${{ github.repository }}"
64+ EXPECTED_HEAD_SHA="${{ github.event.pull_request.head.sha || github.sha }}"
65+ TRUSTED_ARTIFACT="$GITHUB_ACTION_PATH/trusted-artifact.mjs"
5966 rm -rf "$DEST"; mkdir -p "$DEST"
67+ WAIT_SECONDS="${{ inputs.wait-for-artifact-seconds }}"
68+ case "$WAIT_SECONDS" in
69+ ''|*[!0-9]*)
70+ echo "::error::wait-for-artifact-seconds must be a non-negative integer."
71+ exit 1
72+ ;;
73+ esac
6074
6175 # A lookup failure (API outage, auth, transient 5xx) must not fail the
62- # caller: it degrades to an inline build exactly as a cache miss does. The
63- # assignment sits in an `if` so `set -e` cannot exit on it, and an empty
64- # ART_ID then takes the same path as "no artifact found".
65- if ! ART_ID="$(gh api "repos/${{ github.repository }}/actions/artifacts?name=${NAME}&per_page=1" \
66- --jq '[.artifacts[] | select(.expired == false)][0].id // empty' 2>/dev/null)"; then
76+ # caller or trigger a pointless wait: it takes the inline-build path.
77+ query_artifact() {
78+ node "$TRUSTED_ARTIFACT" find "$REPOSITORY" "$NAME" "$EXPECTED_HEAD_SHA" 2>/dev/null
79+ }
80+ query_producer_state() {
81+ node "$TRUSTED_ARTIFACT" producer-state "$REPOSITORY" "$EXPECTED_HEAD_SHA" 2>/dev/null
82+ }
83+ if ! ART_ID="$(query_artifact)"; then
6784 echo "::warning::Could not query the build cache for $NAME; building inline."
6885 ART_ID=""
86+ WAIT_SECONDS=0
87+ fi
88+ if [ -z "$ART_ID" ] && [ "$WAIT_SECONDS" -gt 0 ]; then
89+ DEADLINE=$((SECONDS + WAIT_SECONDS))
90+ MISSING_PRODUCER_POLLS=0
91+ echo "$NAME is not available; waiting up to ${WAIT_SECONDS}s for its producer."
92+ while [ -z "$ART_ID" ] && [ "$SECONDS" -lt "$DEADLINE" ]; do
93+ if ! PRODUCER_STATE="$(query_producer_state)"; then
94+ echo "::warning::Could not inspect the fixture producer; building inline."
95+ break
96+ fi
97+ case "$PRODUCER_STATE" in
98+ queued)
99+ echo "Fixture producer is queued; building inline instead of waiting for a macOS runner."
100+ break
101+ ;;
102+ failed)
103+ echo "Fixture producer failed; building inline."
104+ break
105+ ;;
106+ success)
107+ echo "Fixture producer completed without $NAME; building inline."
108+ break
109+ ;;
110+ absent)
111+ MISSING_PRODUCER_POLLS=$((MISSING_PRODUCER_POLLS + 1))
112+ if [ "$MISSING_PRODUCER_POLLS" -ge 3 ]; then
113+ echo "No fixture producer appeared for $EXPECTED_HEAD_SHA; building inline."
114+ break
115+ fi
116+ ;;
117+ in_progress)
118+ MISSING_PRODUCER_POLLS=0
119+ ;;
120+ *)
121+ echo "::warning::Fixture producer returned unknown state '$PRODUCER_STATE'; building inline."
122+ break
123+ ;;
124+ esac
125+ sleep 30
126+ if ! ART_ID="$(query_artifact)"; then
127+ echo "::warning::Build cache polling failed for $NAME; building inline."
128+ ART_ID=""
129+ break
130+ fi
131+ if [ -n "$ART_ID" ]; then
132+ break
133+ fi
134+ done
69135 fi
70136
71137 SOURCE=build
84150 fi
85151 rm -rf "$STAGE"
86152 else
87- echo "$NAME not in the cache yet ; building inline."
153+ echo "$NAME not in the cache after the configured wait ; building inline."
88154 fi
89155 echo "source=$SOURCE" >> "$GITHUB_OUTPUT"
90156
0 commit comments