mirror of
https://github.com/shadoll/helm-charts.git
synced 2026-08-28 11:33:17 +00:00
chore: Add GitHub token authentication for API calls in update script
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user