Skip to content

Commit 5b58052

Browse files
ci(mobile): dev client builds trust only this repository's commits and leave no token behind
- A dispatch builds only a commit that is a branch head here or on main. - The checkout token file is deleted, not only its git config reference. - Pull request runs do not mount the sticky disk. - One concurrency group per client, so waiting runs are not dropped. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent f85d785 commit 5b58052

1 file changed

Lines changed: 71 additions & 17 deletions

File tree

‎.github/workflows/mobile-dev-client.yml‎

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ jobs:
6969
# Pool emulators are x86_64; a dispatch builds the ABI it asks for.
7070
abi: ${{ github.event_name == 'workflow_dispatch' && fromJSON(format('["{0}"]', inputs.abi)) || fromJSON('["x86_64"]') }}
7171
concurrency:
72-
# Runs for one client queue up; the later one finds it in the cache.
73-
group: mobile-dev-client-android-${{ matrix.abi }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || 'shared' }}
72+
# One run per client: a second request for the same fingerprint waits and finds it
73+
# in the cache. A shared group would drop every waiting run but the newest.
74+
group: mobile-dev-client-android-${{ matrix.abi }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || inputs.fingerprint || github.sha }}
7475
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
7576
env:
7677
NODE_OPTIONS: --max-old-space-size=8192
@@ -86,15 +87,40 @@ jobs:
8687
with:
8788
ref: ${{ inputs.ref || github.sha }}
8889

89-
# The build runs dependency scripts; it gets no token. `persist-credentials: false`
90-
# fails here: its cleanup runs `git submodule foreach`, which stops at the vendored
91-
# gitlinks under .repos (no .gitmodules entry).
90+
# A dispatch names any commit GitHub has, including a fork's. Only a commit that
91+
# collaborators pushed here builds with the cache login and the shared disk.
92+
- name: Check the commit belongs to this repository
93+
if: github.event_name == 'workflow_dispatch'
94+
env:
95+
GH_TOKEN: ${{ github.token }}
96+
run: |
97+
sha="$(git rev-parse HEAD)"
98+
if git ls-remote --heads origin | grep -q "^$sha"; then
99+
exit 0
100+
fi
101+
status="$(gh api "repos/$GITHUB_REPOSITORY/compare/$sha...main" --jq .status || true)"
102+
if [ "$status" = "ahead" ] || [ "$status" = "identical" ]; then
103+
exit 0
104+
fi
105+
echo "::error::$sha is not the head of a branch in $GITHUB_REPOSITORY and not on main; build it locally."
106+
exit 1
107+
108+
# The build runs dependency scripts; it gets no token. checkout keeps the token in a
109+
# file under RUNNER_TEMP that .git/config includes, so both go. `persist-credentials:
110+
# false` fails here: its cleanup runs `git submodule foreach`, which stops at the
111+
# vendored gitlinks under .repos (no .gitmodules entry).
92112
- name: Drop checkout credentials
93113
run: |
94-
git config --local --name-only --get-regexp '^(http\..*\.extraheader|includeif\..*)$' \
95-
| while read -r key; do git config --local --unset-all "$key"; done
96-
if git config --local --get-regexp 'extraheader|includeif' ; then
97-
echo "::error::checkout credentials are still configured"
114+
git config --local --get-regexp '^includeif\..*\.path$' | while read -r key file; do
115+
rm -f "$file"
116+
git config --local --unset-all "$key"
117+
done
118+
git config --local --name-only --get-regexp '^http\..*\.extraheader$' | while read -r key; do
119+
git config --local --unset-all "$key"
120+
done
121+
rm -f "$RUNNER_TEMP"/git-credentials-*.config
122+
if git config --local --get-regexp 'extraheader|includeif' || ls "$RUNNER_TEMP"/git-credentials-*.config 2>/dev/null; then
123+
echo "::error::checkout credentials are still present"
98124
exit 1
99125
fi
100126
@@ -114,7 +140,10 @@ jobs:
114140
echo "CMAKE_CXX_COMPILER_LAUNCHER=ccache"
115141
} >> "$GITHUB_ENV"
116142
143+
# Pull requests build cold: their code must not write Gradle or ccache state that
144+
# the runs holding the cache login restore.
117145
- name: Mount build cache
146+
if: github.event_name != 'pull_request'
118147
uses: useblacksmith/stickydisk@v1
119148
with:
120149
key: ${{ github.repository }}-android-dev-client-${{ matrix.abi }}
@@ -193,7 +222,7 @@ jobs:
193222
runs-on: blacksmith-12vcpu-macos-26
194223
timeout-minutes: 60
195224
concurrency:
196-
group: mobile-dev-client-ios-${{ github.event_name == 'pull_request' && github.event.pull_request.number || 'shared' }}
225+
group: mobile-dev-client-ios-${{ github.event_name == 'pull_request' && github.event.pull_request.number || inputs.fingerprint || github.sha }}
197226
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
198227
env:
199228
NODE_OPTIONS: --max-old-space-size=8192
@@ -207,15 +236,40 @@ jobs:
207236
with:
208237
ref: ${{ inputs.ref || github.sha }}
209238

210-
# The build runs dependency scripts; it gets no token. `persist-credentials: false`
211-
# fails here: its cleanup runs `git submodule foreach`, which stops at the vendored
212-
# gitlinks under .repos (no .gitmodules entry).
239+
# A dispatch names any commit GitHub has, including a fork's. Only a commit that
240+
# collaborators pushed here builds with the cache login and the shared disk.
241+
- name: Check the commit belongs to this repository
242+
if: github.event_name == 'workflow_dispatch'
243+
env:
244+
GH_TOKEN: ${{ github.token }}
245+
run: |
246+
sha="$(git rev-parse HEAD)"
247+
if git ls-remote --heads origin | grep -q "^$sha"; then
248+
exit 0
249+
fi
250+
status="$(gh api "repos/$GITHUB_REPOSITORY/compare/$sha...main" --jq .status || true)"
251+
if [ "$status" = "ahead" ] || [ "$status" = "identical" ]; then
252+
exit 0
253+
fi
254+
echo "::error::$sha is not the head of a branch in $GITHUB_REPOSITORY and not on main; build it locally."
255+
exit 1
256+
257+
# The build runs dependency scripts; it gets no token. checkout keeps the token in a
258+
# file under RUNNER_TEMP that .git/config includes, so both go. `persist-credentials:
259+
# false` fails here: its cleanup runs `git submodule foreach`, which stops at the
260+
# vendored gitlinks under .repos (no .gitmodules entry).
213261
- name: Drop checkout credentials
214262
run: |
215-
git config --local --name-only --get-regexp '^(http\..*\.extraheader|includeif\..*)$' \
216-
| while read -r key; do git config --local --unset-all "$key"; done
217-
if git config --local --get-regexp 'extraheader|includeif' ; then
218-
echo "::error::checkout credentials are still configured"
263+
git config --local --get-regexp '^includeif\..*\.path$' | while read -r key file; do
264+
rm -f "$file"
265+
git config --local --unset-all "$key"
266+
done
267+
git config --local --name-only --get-regexp '^http\..*\.extraheader$' | while read -r key; do
268+
git config --local --unset-all "$key"
269+
done
270+
rm -f "$RUNNER_TEMP"/git-credentials-*.config
271+
if git config --local --get-regexp 'extraheader|includeif' || ls "$RUNNER_TEMP"/git-credentials-*.config 2>/dev/null; then
272+
echo "::error::checkout credentials are still present"
219273
exit 1
220274
fi
221275

0 commit comments

Comments
 (0)