chore: Add GitHub token authentication for API calls in update script

This commit is contained in:
sha
2026-07-24 12:28:46 +03:00
parent e2c73004db
commit 41296a1433
2 changed files with 12 additions and 3 deletions
+2
View File
@@ -20,6 +20,8 @@ jobs:
sudo apt-get install -y jq sudo apt-get install -y jq
- name: Run Update Script - name: Run Update Script
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
chmod +x scripts/update-charts.sh chmod +x scripts/update-charts.sh
./scripts/update-charts.sh ./scripts/update-charts.sh
+10 -3
View File
@@ -7,6 +7,13 @@ REPO_ROOT=$(git rev-parse --show-toplevel)
UPDATES_FOUND="" UPDATES_FOUND=""
ERRORS_FOUND="" ERRORS_FOUND=""
# Authenticate GitHub API calls when a token is available to avoid the 60/hr
# unauthenticated rate limit (shared across all Actions runners on the same IP).
GITHUB_AUTH_HEADER=()
if [ -n "$GITHUB_TOKEN" ]; then
GITHUB_AUTH_HEADER=(-H "Authorization: Bearer $GITHUB_TOKEN")
fi
# Fetch latest version from different sources # Fetch latest version from different sources
fetch_latest() { fetch_latest() {
local source_type=$1 local source_type=$1
@@ -15,15 +22,15 @@ fetch_latest() {
case "$source_type" in case "$source_type" in
"github-release") "github-release")
version=$(curl -sL "https://api.github.com/repos/$source_data/releases/latest" | jq -r '.tag_name // empty') version=$(curl -sL "${GITHUB_AUTH_HEADER[@]}" "https://api.github.com/repos/$source_data/releases/latest" | jq -r '.tag_name // empty')
;; ;;
"github-sha") "github-sha")
local repo="${source_data%%:*}" local repo="${source_data%%:*}"
local branch="${source_data#*:}" local branch="${source_data#*:}"
if [ "$branch" = "$source_data" ]; then if [ "$branch" = "$source_data" ]; then
branch=$(curl -sL "https://api.github.com/repos/$repo" | jq -r '.default_branch // "main"') branch=$(curl -sL "${GITHUB_AUTH_HEADER[@]}" "https://api.github.com/repos/$repo" | jq -r '.default_branch // "main"')
fi fi
version=$(curl -sL "https://api.github.com/repos/$repo/commits/$branch" | jq -r '.sha // empty' | cut -c1-7) version=$(curl -sL "${GITHUB_AUTH_HEADER[@]}" "https://api.github.com/repos/$repo/commits/$branch" | jq -r '.sha // empty' | cut -c1-7)
;; ;;
"dockerhub-tags") "dockerhub-tags")
version=$(curl -s "https://registry.hub.docker.com/v2/repositories/$source_data/tags?page_size=100" | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V -r | head -1) version=$(curl -s "https://registry.hub.docker.com/v2/repositories/$source_data/tags?page_size=100" | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V -r | head -1)