Skip to content

Commit 930a6d7

Browse files
committed
feat(action,install): add GitHub Enterprise support with optional authentication
Support GitHub Enterprise Server by allowing custom API and server URLs via GITHUB_API_URL and GITHUB_SERVER_URL environment variables. Add optional authentication support using GH_TOKEN or GITHUB_TOKEN environment variables in both the GitHub Action and install script. This enables the sr action and installer to work in GitHub Enterprise environments and respects user-provided tokens for API rate limit benefits.
1 parent 39e9879 commit 930a6d7

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

action.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ runs:
110110
# Resolve the action ref to a concrete release tag.
111111
# Floating tags (e.g. v1) are git tags — not releases — so we resolve
112112
# them to the latest release sharing the same major version.
113-
# API calls use no auth — the repo is public and the caller's token
114-
# may be scoped to a different repository (e.g. GitHub App tokens).
115113
resolve_release_tag() {
116114
local api="$1" ref="$2"
117115
@@ -120,10 +118,15 @@ runs:
120118
exit 1
121119
fi
122120
121+
local auth_args=()
122+
if [ -n "${GH_TOKEN:-}" ]; then
123+
auth_args+=(-H "Authorization: token ${GH_TOKEN}")
124+
fi
125+
123126
# Try exact tag match (works for non-floating refs like v1.2.3).
124127
# curl without -f so a 404 returns JSON instead of exit 22.
125128
local tag
126-
tag=$(curl -sSL -H "Accept: application/vnd.github+json" \
129+
tag=$(curl -sSL "${auth_args[@]}" -H "Accept: application/vnd.github+json" \
127130
"${api}/releases/tags/${ref}" 2>/dev/null \
128131
| jq -r '.tag_name // empty') || true
129132
@@ -134,7 +137,7 @@ runs:
134137
135138
echo "No exact release for ref=${ref}, searching by major version..." >&2
136139
local releases
137-
releases=$(curl -fsSL -H "Accept: application/vnd.github+json" \
140+
releases=$(curl -fsSL "${auth_args[@]}" -H "Accept: application/vnd.github+json" \
138141
"${api}/releases?per_page=20")
139142
140143
local major
@@ -153,7 +156,7 @@ runs:
153156
echo "$tag"
154157
}
155158
156-
API="https://api.github.com/repos/${SR_REPO}"
159+
API="${GITHUB_API_URL:-https://api.github.com}/repos/${SR_REPO}"
157160
echo "Resolving ref=${SR_REF} via ${API}"
158161
RELEASE_TAG=$(resolve_release_tag "$API" "$SR_REF")
159162
@@ -163,7 +166,7 @@ runs:
163166
fi
164167
165168
echo "Resolved release tag: ${RELEASE_TAG}"
166-
URL="https://github.com/${SR_REPO}/releases/download/${RELEASE_TAG}/${BINARY_NAME}"
169+
URL="${GITHUB_SERVER_URL:-https://github.com}/${SR_REPO}/releases/download/${RELEASE_TAG}/${BINARY_NAME}"
167170
echo "Downloading from ${URL}"
168171
curl -fsSL -H "Authorization: token $GH_TOKEN" "$URL" -o "$DEST"
169172

install.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ set -eu
1313

1414
REPO="urmzd/sr"
1515

16+
# curl with optional auth — uses GH_TOKEN or GITHUB_TOKEN if set.
17+
gh_curl() {
18+
token="${GH_TOKEN:-${GITHUB_TOKEN:-}}"
19+
if [ -n "$token" ]; then
20+
curl -fsSL -H "Authorization: token $token" "$@"
21+
else
22+
curl -fsSL "$@"
23+
fi
24+
}
25+
1626
main() {
1727
os=$(uname -s)
1828
arch=$(uname -m)
@@ -43,7 +53,7 @@ main() {
4353
if [ -n "${SR_VERSION:-}" ]; then
4454
tag="$SR_VERSION"
4555
else
46-
tag=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \
56+
tag=$(gh_curl "https://api.github.com/repos/$REPO/releases/latest" \
4757
| sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p')
4858
if [ -z "$tag" ]; then
4959
err "Failed to fetch latest release tag"
@@ -57,7 +67,7 @@ main() {
5767
mkdir -p "$install_dir"
5868

5969
echo "Downloading sr $tag for $target..."
60-
curl -fsSL "$url" -o "$install_dir/sr"
70+
gh_curl "$url" -o "$install_dir/sr"
6171

6272
if [ -n "${SR_SHA256:-}" ]; then
6373
if command -v sha256sum >/dev/null 2>&1; then

0 commit comments

Comments
 (0)