Skip to content

Commit 8e44134

Browse files
authored
Merge pull request #23 from r4y7s/feature/github-rate-limit
Add GitHub API authentication to avoid rate limit errors
2 parents 09c1566 + 44edc92 commit 8e44134

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

.github/workflows/check-caddy-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
id: check_script
3939
env:
4040
DOCKERHUB_REPOSITORY_NAME: ${{ env.DOCKERHUB_REPOSITORY_NAME }}
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4142
run: python scripts/check_caddy_status.py
4243

4344
- name: Trigger Build Workflow if Needed

scripts/check_caddy_status.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
OFFICIAL_CADDY_IMAGE = "library/caddy"
1111
# --- Can be set as a repository secret or variable ---
1212
CUSTOM_IMAGE = os.environ.get('DOCKERHUB_REPOSITORY_NAME', "caddybuilds/caddy-cloudflare")
13+
GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN', "")
1314
# DEPRECATED !!! CHANGE THIS if your tags start with 'v' (e.g., use 'v') !!!
1415
CUSTOM_TAG_PREFIX = ""
1516
# These are the platforms WE want to build and require the OFFICIAL image to have available.
@@ -63,13 +64,18 @@ def set_action_output(output_name, value):
6364
# Exiting might be safer if outputs are critical
6465
sys.exit(1)
6566

66-
6767
def get_latest_caddy_release():
6868
"""Fetches the latest release tag from the Caddy GitHub repository."""
6969
url = f'https://api.github.com/repos/{GITHUB_REPO}/releases/latest'
7070
log_info(f"Fetching latest release from {url}")
71+
headers = {}
72+
if GITHUB_TOKEN:
73+
headers['Authorization'] = f'token {GITHUB_TOKEN}'
74+
log_info("Using authenticated GitHub API request")
75+
else:
76+
log_info("::warning::No GITHUB_TOKEN found, using unauthenticated request (lower rate limit)")
7177
try:
72-
response = requests.get(url, timeout=30)
78+
response = requests.get(url, headers=headers, timeout=30)
7379
response.raise_for_status()
7480
release = response.json()
7581
tag_name = release.get('tag_name')
@@ -92,8 +98,6 @@ def get_latest_caddy_release():
9298
log_error(f"Error decoding GitHub API JSON response: {e}")
9399
sys.exit(1)
94100

95-
96-
97101
def check_docker_hub_tag(image_name, tag):
98102
"""Checks if a specific tag exists for a Docker Hub image. Returns tag data or None."""
99103
url = f"https://hub.docker.com/v2/repositories/{image_name}/tags/{tag}"
@@ -116,8 +120,6 @@ def check_docker_hub_tag(image_name, tag):
116120
log_error(f"Error decoding Docker Hub API response for tag '{tag}' of '{image_name}': {e}. Response: {response.text[:200]}")
117121
return None
118122

119-
120-
121123
def get_platforms_from_tag_data(tag_data):
122124
"""Extracts required linux platform strings from Docker Hub tag API response."""
123125
platforms = set()
@@ -146,7 +148,6 @@ def get_platforms_from_tag_data(tag_data):
146148

147149
return platforms
148150

149-
150151
def main():
151152
start_time = datetime.now(timezone.utc)
152153
log_info(f"--- Starting Caddy Check at {start_time.isoformat()} ---")

0 commit comments

Comments
 (0)