Skip to content

Commit a304b46

Browse files
ci(mobile): keep the write token out of store build steps
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b9aad78 commit a304b46

1 file changed

Lines changed: 40 additions & 28 deletions

File tree

‎.github/workflows/mobile-eas-production.yml‎

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ jobs:
504504
with:
505505
ref: ${{ needs.production.outputs.android_sha }}
506506
fetch-depth: 0
507+
# Dependency scripts and the build run in this job; only Record build gets a token.
508+
persist-credentials: false
507509

508510
# A queued run can follow a build of the same fingerprint; manual runs always build.
509511
- id: record
@@ -635,21 +637,25 @@ jobs:
635637
# pushed, the next merge rebuilds with a new build number; nothing is lost.
636638
- name: Record build
637639
if: steps.record.outputs.built != 'true'
640+
env:
641+
GH_TOKEN: ${{ github.token }}
638642
run: |
639-
if git ls-remote --exit-code --tags origin "refs/tags/$BUILD_TAG" >/dev/null; then
640-
echo "$BUILD_TAG already exists."
641-
else
642-
git tag "$BUILD_TAG" HEAD
643-
# GitHub occasionally fails ref pushes server-side ("fatal error in commit_refs").
644-
for attempt in 1 2 3; do
645-
git push origin "refs/tags/$BUILD_TAG" && break
646-
if [ "$attempt" = 3 ]; then
647-
echo "::error::Submitted, but could not push $BUILD_TAG; the next merge will rebuild."
648-
exit 1
649-
fi
650-
sleep $((attempt * 15))
651-
done
652-
fi
643+
sha="$(git rev-parse HEAD)"
644+
# GitHub occasionally fails ref writes server-side ("fatal error in commit_refs").
645+
for attempt in 1 2 3; do
646+
if gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$BUILD_TAG" >/dev/null 2>&1; then
647+
echo "$BUILD_TAG exists."
648+
break
649+
fi
650+
if gh api "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/tags/$BUILD_TAG" -f sha="$sha" >/dev/null; then
651+
break
652+
fi
653+
if [ "$attempt" = 3 ]; then
654+
echo "::error::Submitted, but could not create $BUILD_TAG; the next merge will rebuild."
655+
exit 1
656+
fi
657+
sleep $((attempt * 15))
658+
done
653659
echo ":rocket: android: submitted and recorded \`$BUILD_TAG\`" >> "$GITHUB_STEP_SUMMARY"
654660
655661
# Off unless the MOBILE_IOS_LOCAL_BUILDS repository variable is `true`; the
@@ -681,6 +687,8 @@ jobs:
681687
with:
682688
ref: ${{ needs.production.outputs.ios_sha }}
683689
fetch-depth: 0
690+
# Dependency scripts and the build run in this job; only Record build gets a token.
691+
persist-credentials: false
684692

685693
# A queued run can follow a build of the same fingerprint; manual runs always build.
686694
- id: record
@@ -778,19 +786,23 @@ jobs:
778786
# pushed, the next merge rebuilds with a new build number; nothing is lost.
779787
- name: Record build
780788
if: steps.record.outputs.built != 'true'
789+
env:
790+
GH_TOKEN: ${{ github.token }}
781791
run: |
782-
if git ls-remote --exit-code --tags origin "refs/tags/$BUILD_TAG" >/dev/null; then
783-
echo "$BUILD_TAG already exists."
784-
else
785-
git tag "$BUILD_TAG" HEAD
786-
# GitHub occasionally fails ref pushes server-side ("fatal error in commit_refs").
787-
for attempt in 1 2 3; do
788-
git push origin "refs/tags/$BUILD_TAG" && break
789-
if [ "$attempt" = 3 ]; then
790-
echo "::error::Submitted, but could not push $BUILD_TAG; the next merge will rebuild."
791-
exit 1
792-
fi
793-
sleep $((attempt * 15))
794-
done
795-
fi
792+
sha="$(git rev-parse HEAD)"
793+
# GitHub occasionally fails ref writes server-side ("fatal error in commit_refs").
794+
for attempt in 1 2 3; do
795+
if gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$BUILD_TAG" >/dev/null 2>&1; then
796+
echo "$BUILD_TAG exists."
797+
break
798+
fi
799+
if gh api "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/tags/$BUILD_TAG" -f sha="$sha" >/dev/null; then
800+
break
801+
fi
802+
if [ "$attempt" = 3 ]; then
803+
echo "::error::Submitted, but could not create $BUILD_TAG; the next merge will rebuild."
804+
exit 1
805+
fi
806+
sleep $((attempt * 15))
807+
done
796808
echo ":rocket: ios: submitted and recorded \`$BUILD_TAG\`" >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)