Skip to content

Commit a6ffb93

Browse files
Itsusinnclaude
andcommitted
feat(rust-build): support private git deps via opt-in git-token secret
When git-token is provided, the compile job configures a github.com credential (url.insteadOf) and CARGO_NET_GIT_FETCH_WITH_CLI, then inits submodules manually. This lets private cross-repo submodules and cargo git dependencies resolve. Behaviour is unchanged when the secret is unset. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 83f5994 commit a6ffb93

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

.github/workflows/rust-build.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ on:
5656
sentry-dsn:
5757
description: 'Sentry DSN for error reporting'
5858
required: false
59+
git-token:
60+
description: 'Token (PAT or App token) with read access to private git dependencies / submodules. When set, the compile job configures git credentials so private cross-repo submodules and cargo git dependencies can be fetched. Leave unset for fully public projects.'
61+
required: false
5962

6063
defaults:
6164
run:
@@ -122,9 +125,27 @@ jobs:
122125
- name: Checkout code
123126
uses: actions/checkout@v6
124127
with:
125-
submodules: true
128+
# When a git-token is provided, submodules are initialised manually in
129+
# the next step (after credentials are configured) so that private
130+
# cross-repo submodules can be cloned. Otherwise behave as before.
131+
submodules: ${{ secrets.git-token != '' && 'false' || 'true' }}
126132
fetch-depth: 1
127133

134+
- name: Configure private git credentials
135+
if: ${{ secrets.git-token != '' }}
136+
env:
137+
GIT_TOKEN: ${{ secrets.git-token }}
138+
run: |
139+
# Authenticate all github.com access with the provided token so that
140+
# private cross-repo submodules and cargo git dependencies resolve.
141+
git config --global url."https://x-access-token:${GIT_TOKEN}@github.com/".insteadOf "https://github.com/"
142+
# Make cargo use the git CLI (which honours the credential above) when
143+
# fetching git dependencies.
144+
echo "CARGO_NET_GIT_FETCH_WITH_CLI=true" >> "$GITHUB_ENV"
145+
# Now that credentials are set, initialise submodules.
146+
git submodule sync --recursive
147+
git submodule update --init --recursive
148+
128149
# ── Sccache: restore/auto-save disk cache + local disk setup ──
129150
- name: Determine sccache directory
130151
if: inputs.enable-sccache

0 commit comments

Comments
 (0)