init
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
name: Select Go module proxy
|
||||
description: Select the fastest reachable Go module proxy for Docker builds
|
||||
inputs:
|
||||
go_mirrors:
|
||||
description: Newline-separated Go module proxies
|
||||
required: false
|
||||
default: |
|
||||
https://go.devneeds.ir/
|
||||
https://package-mirror.liara.ir/repository/go/
|
||||
https://go.reg.darano.ir/
|
||||
https://proxy.golang.org/
|
||||
outputs:
|
||||
go_proxy:
|
||||
description: Selected Go module proxy
|
||||
value: ${{ steps.select.outputs.go_proxy }}
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Select fastest reachable proxy
|
||||
id: select
|
||||
shell: bash
|
||||
env:
|
||||
GO_MIRRORS: ${{ inputs.go_mirrors }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
scores="$(mktemp)"
|
||||
fallback=""
|
||||
|
||||
while IFS= read -r mirror; do
|
||||
mirror="$(printf '%s' "$mirror" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
[[ -z "$mirror" || "$mirror" == \#* ]] && continue
|
||||
[[ -z "$fallback" ]] && fallback="$mirror"
|
||||
result="$(curl --location --silent --output /dev/null \
|
||||
--connect-timeout 3 --max-time 10 \
|
||||
--write-out '%{http_code} %{time_total}' "$mirror" 2>/dev/null || true)"
|
||||
read -r status duration <<< "$result"
|
||||
if [[ "$status" =~ ^(2|3)[0-9]{2}$ ]] && [[ "$duration" =~ ^[0-9]+([.][0-9]+)?$ ]]; then
|
||||
printf '%s\t%s\n' "$duration" "$mirror" >> "$scores"
|
||||
fi
|
||||
done <<< "$GO_MIRRORS"
|
||||
|
||||
if [[ -s "$scores" ]]; then
|
||||
go_proxy="$(sort -n -k1,1 "$scores" | head -n 1 | cut -f2-)"
|
||||
else
|
||||
go_proxy="$fallback"
|
||||
fi
|
||||
rm -f "$scores"
|
||||
|
||||
test -n "$go_proxy"
|
||||
echo "GOPROXY=$go_proxy" >> "$GITHUB_ENV"
|
||||
echo "go_proxy=$go_proxy" >> "$GITHUB_OUTPUT"
|
||||
echo "Selected Go proxy: $go_proxy"
|
||||
Reference in New Issue
Block a user