Skip to content

Commit 8962310

Browse files
committed
fix: authenticate sidecar fetch in release ci
1 parent 16d0338 commit 8962310

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ permissions:
99
contents: write
1010

1111
env:
12+
GITHUB_TOKEN: ${{ github.token }}
1213
MACOS_SIGNING_IDENTITY: ${{ secrets.MACOS_SIGNING_IDENTITY }}
1314
MACOS_NOTARY_KEY_ID: ${{ secrets.MACOS_NOTARY_KEY_ID }}
1415
MACOS_NOTARY_ISSUER_ID: ${{ secrets.MACOS_NOTARY_ISSUER_ID }}

scripts/fetch-sidecar.sh

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,37 @@ REPO="router-for-me/CLIProxyAPI"
1818
BINARY_NAME="cli-proxy-api"
1919
[[ "$GOOS" == "windows" ]] && BINARY_NAME="${BINARY_NAME}.exe"
2020

21+
curl_args=(
22+
--retry 5
23+
--retry-delay 2
24+
--retry-all-errors
25+
-fsSL
26+
-H "Accept: application/vnd.github+json"
27+
-H "User-Agent: GetTokens-Release-Script"
28+
)
29+
30+
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
31+
curl_args+=(
32+
-H "Authorization: Bearer ${GITHUB_TOKEN}"
33+
-H "X-GitHub-Api-Version: 2022-11-28"
34+
)
35+
fi
36+
2137
# Resolve latest tag if needed
2238
if [[ "$VERSION" == "latest" ]]; then
23-
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
24-
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name": "\(.*\)".*/\1/')
39+
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
40+
VERSION=$(curl "${curl_args[@]}" "https://api.github.com/repos/${REPO}/releases/latest" \
41+
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name": "\(.*\)".*/\1/')
42+
else
43+
VERSION=$(curl --retry 5 --retry-delay 2 --retry-all-errors -fsSIL -o /dev/null -w '%{url_effective}' \
44+
"https://github.com/${REPO}/releases/latest")
45+
VERSION="${VERSION##*/}"
46+
fi
47+
fi
48+
49+
if [[ -z "$VERSION" ]]; then
50+
echo "failed to resolve release version for ${REPO}" >&2
51+
exit 1
2552
fi
2653

2754
echo "→ Fetching CLIProxyAPI ${VERSION} for ${GOOS}/${GOARCH}"
@@ -37,7 +64,7 @@ URL="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET}"
3764
TMP=$(mktemp -d)
3865
trap 'rm -rf "$TMP"' EXIT
3966

40-
curl --retry 5 --retry-delay 2 --retry-all-errors -fsSL "$URL" -o "${TMP}/${ASSET}"
67+
curl "${curl_args[@]}" "$URL" -o "${TMP}/${ASSET}"
4168

4269
mkdir -p "$DEST_DIR"
4370

0 commit comments

Comments
 (0)