Skip to content

Commit 3f9cd16

Browse files
authored
Fix checkout script (project-chip#71811)
1 parent fb559db commit 3f9cd16

1 file changed

Lines changed: 24 additions & 26 deletions

File tree

integrations/compute_engine/run_alchemy_diff.sh

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ done
9898
GITHUB_PAT=""
9999
if [ -n "$USE_SECRET" ]; then
100100
echo "Fetching PAT from secret: $USE_SECRET"
101-
GITHUB_PAT=$(gcloud secrets versions access latest --secret="$USE_SECRET")
101+
# Trim newline from token
102+
GITHUB_PAT=$(gcloud secrets versions access latest --secret="$USE_SECRET" | tr -d '\n')
102103
fi
103104

104105
# Ensure output directory exists
@@ -115,44 +116,41 @@ update_or_clone() {
115116
return
116117
fi
117118

118-
# Setup GIT_ASKPASS if we have a token
119-
local cleanup_askpass=false
120-
if [ -n "$GITHUB_PAT" ]; then
121-
local askpass_path="out/askpass.sh"
122-
echo '#!/bin/sh' > "$askpass_path"
123-
echo 'echo "$GITHUB_PAT"' >> "$askpass_path"
124-
chmod +x "$askpass_path"
125-
export GIT_ASKPASS="$(pwd)/$askpass_path"
126-
cleanup_askpass=true
127-
128-
# Modify URL to include x-access-token username if it's an HTTPS URL
129-
if [[ "$url" == https://* ]]; then
130-
url="https://x-access-token@${url#https://}"
131-
fi
132-
fi
133-
134119
if [ -d "$dir" ]; then
135120
echo "Updating $name to $branch..."
136121
(
137122
cd "$dir"
123+
if [ -n "$GITHUB_PAT" ] && [[ "$url" == https://* ]]; then
124+
# Temporarily set URL with token for fetch
125+
git remote set-url origin "https://${GITHUB_PAT}@github.com/CHIP-Specifications/connectedhomeip-spec.git"
126+
fi
127+
138128
git fetch origin "$branch"
139129
git checkout FETCH_HEAD
130+
131+
if [ -n "$GITHUB_PAT" ] && [[ "$url" == https://* ]]; then
132+
# Restore clean URL
133+
git remote set-url origin "https://github.com/CHIP-Specifications/connectedhomeip-spec.git"
134+
fi
140135
)
141136
else
142137
echo "Cloning $name ($branch)..."
143-
git clone --branch "$branch" "$url" "$dir"
144-
fi
145-
146-
# Cleanup
147-
if [ "$cleanup_askpass" = true ]; then
148-
rm -f "out/askpass.sh"
149-
unset GIT_ASKPASS
138+
if [ -n "$GITHUB_PAT" ] && [[ "$url" == https://* ]]; then
139+
git clone --branch "$branch" "https://${GITHUB_PAT}@github.com/CHIP-Specifications/connectedhomeip-spec.git" "$dir"
140+
# Immediately restore clean URL in the cloned repo
141+
(
142+
cd "$dir"
143+
git remote set-url origin "https://github.com/CHIP-Specifications/connectedhomeip-spec.git"
144+
)
145+
else
146+
git clone --branch "$branch" "$url" "$dir"
147+
fi
150148
fi
151149
}
152150

153151
# Clone/Update Spec (Private)
154152
if [ -n "$GITHUB_PAT" ]; then
155-
update_or_clone "$SPEC_ROOT" "https://${GITHUB_PAT}@github.com/CHIP-Specifications/connectedhomeip-spec.git" "Spec" "$SPEC_BRANCH"
153+
update_or_clone "$SPEC_ROOT" "https://github.com/CHIP-Specifications/connectedhomeip-spec.git" "Spec" "$SPEC_BRANCH"
156154
else
157155
update_or_clone "$SPEC_ROOT" "git@github.com:CHIP-Specifications/connectedhomeip-spec.git" "Spec" "$SPEC_BRANCH"
158156
fi
@@ -166,7 +164,7 @@ if [ "$SKIP_UPDATE" = true ] && [ -f "out/alchemy" ]; then
166164
else
167165
echo "Downloading Alchemy v${ALCHEMY_VERSION}..."
168166
curl -L "$ALCHEMY_URL" -o "out/${ALCHEMY_ASSET}"
169-
167+
170168
echo "Extracting Alchemy..."
171169
tar -xzf "out/${ALCHEMY_ASSET}" -C out/
172170
chmod +x out/alchemy

0 commit comments

Comments
 (0)