Skip to content

Commit f393356

Browse files
committed
Clean up
1 parent ca135e6 commit f393356

4 files changed

Lines changed: 21 additions & 37 deletions

File tree

.gitlab/.pre/deps_fetch/deps_fetch.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# to reuse them in further jobs that need them.
55

66
# Keep GOPROXY entries usable from the current environment; drop the rest.
7-
# See tools/ci/sanitize-goproxy.sh.
87
.sanitize_goproxy:
98
- . tools/ci/sanitize-goproxy.sh
109

.gitlab/build/source_test/kmt_tasks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ test_kmt_local_setup_macos:
4040
before_script:
4141
- !reference [.vault_login]
4242
- !reference [.aws_retry_config]
43+
# Drop GOPROXY entries not usable from macOS runners, before any go command.
44+
- !reference [.sanitize_goproxy]
4345
- !reference [.setup_github_token_read]
4446
# Selecting the current Go version
4547
- |

tools/ci/sanitize-goproxy.ps1

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1-
# Normalize $env:GOPROXY on Windows: drop the entry that isn't usable here,
2-
# keeping the rest. Mirrors tools/ci/sanitize-goproxy.sh.
1+
# Normalize $env:GOPROXY on Windows: drop the entry that isn't usable here
2+
# (hosts ending in .fabric.dog), keeping the rest. Mirrors tools/ci/sanitize-goproxy.sh.
33
#
44
# Dot-source before `docker run ... -e GOPROXY` so the container inherits the
55
# cleaned value: . ./tools/ci/sanitize-goproxy.ps1
66

7-
$sgpHost = 'depot-read-api-go.rapid-dependency-management-depot.all-clusters.local-dc.fabric.dog'
8-
$sgpProbeUrl = "https://${sgpHost}:8443/magicmirror/magicmirror/@current/sumdb/sum.golang.org/supported"
7+
$sgpProbeUrl = 'https://depot-read-api-go.rapid-dependency-management-depot.all-clusters.local-dc.fabric.dog:8443/magicmirror/magicmirror/@current/sumdb/sum.golang.org/supported'
98

109
function Test-SgpUsable {
11-
param([string]$Url)
1210
try {
1311
# -SkipHttpErrorCheck (PS7+) so a non-2xx still counts as completed; any
1412
# failure throws and is caught below.
15-
Invoke-WebRequest -Uri $Url -Method Head -TimeoutSec 5 -SkipHttpErrorCheck -UseBasicParsing | Out-Null
13+
Invoke-WebRequest -Uri $sgpProbeUrl -Method Head -TimeoutSec 5 -SkipHttpErrorCheck -UseBasicParsing | Out-Null
1614
return $true
1715
} catch {
1816
return $false
1917
}
2018
}
2119

22-
if ($env:GOPROXY -and $env:GOPROXY.Contains('.fabric.dog')) {
23-
if (Test-SgpUsable -Url $sgpProbeUrl) {
24-
Write-Host "sanitize-goproxy: endpoint usable here; keeping it in GOPROXY"
25-
} else {
26-
$env:GOPROXY = (($env:GOPROXY -split '\|') |
27-
Where-Object { $_ -notmatch '^https?://[^/]*\.fabric\.dog(:\d+)?(/|$)' }) -join '|'
28-
Write-Host "sanitize-goproxy: endpoint unusable here; stripped it from GOPROXY"
29-
}
20+
if ($env:GOPROXY -and $env:GOPROXY.Contains('.fabric.dog') -and -not (Test-SgpUsable)) {
21+
$env:GOPROXY = (($env:GOPROXY -split '\|') |
22+
Where-Object { $_ -notmatch '^https?://[^/]*\.fabric\.dog(:\d+)?(/|$)' }) -join '|'
23+
Write-Host "sanitize-goproxy: endpoint unusable here; stripped it from GOPROXY"
3024
}

tools/ci/sanitize-goproxy.sh

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
11
# shellcheck shell=bash
2-
# Drop GOPROXY entries that aren't usable from the current environment, keeping
3-
# the rest. Probes the endpoint the way Go would (an HTTPS request with cert
4-
# verification) and strips it if that fails.
2+
# Drop the GOPROXY entry that isn't usable from the current environment (hosts
3+
# ending in .fabric.dog), keeping the rest. Probes the endpoint the way Go would
4+
# (an HTTPS request with cert verification) and strips it only if that fails;
5+
# missing curl counts as unusable.
56
#
67
# Source this file (don't execute) so the change is visible to the caller:
78
# . tools/ci/sanitize-goproxy.sh
89
# Safe to source repeatedly; never empties GOPROXY.
910

10-
__sgp_host='depot-read-api-go.rapid-dependency-management-depot.all-clusters.local-dc.fabric.dog'
11-
__sgp_probe_url="https://${__sgp_host}:8443/magicmirror/magicmirror/@current/sumdb/sum.golang.org/supported"
11+
__sgp_probe_url="https://depot-read-api-go.rapid-dependency-management-depot.all-clusters.local-dc.fabric.dog:8443/magicmirror/magicmirror/@current/sumdb/sum.golang.org/supported"
1212

1313
# Returns 0 if the endpoint completes a request over verified TLS. No --fail: we
14-
# only care that the request completes, not its HTTP status. Missing curl counts
15-
# as not usable.
14+
# only care that the request completes, not its HTTP status.
1615
__sgp_usable() {
17-
command -v curl >/dev/null 2>&1 || return 1
18-
curl --silent --output /dev/null --connect-timeout 3 --max-time 5 "$__sgp_probe_url"
19-
}
20-
21-
# Drop entries whose host ends in .fabric.dog, keeping the '|' separators and
22-
# every other entry.
23-
__sgp_strip() {
24-
printf '%s' "${1-}" \
25-
| tr '|' '\n' \
26-
| grep -vE '^https?://[^/]*\.fabric\.dog(:[0-9]+)?(/|$)' \
27-
| paste -sd '|' -
16+
command -v curl >/dev/null 2>&1 \
17+
&& curl --silent --output /dev/null --connect-timeout 3 --max-time 5 "$__sgp_probe_url"
2818
}
2919

3020
case "${GOPROXY-}" in
3121
*.fabric.dog*)
32-
if __sgp_usable; then
33-
echo "sanitize-goproxy: endpoint usable here; keeping it in GOPROXY" >&2
34-
else
35-
GOPROXY="$(__sgp_strip "${GOPROXY-}")"
22+
if ! __sgp_usable; then
23+
GOPROXY="$(printf '%s' "$GOPROXY" | tr '|' '\n' \
24+
| grep -vE '^https?://[^/]*\.fabric\.dog(:[0-9]+)?(/|$)' | paste -sd '|' -)"
3625
export GOPROXY
3726
echo "sanitize-goproxy: endpoint unusable here; stripped it from GOPROXY" >&2
3827
fi

0 commit comments

Comments
 (0)