Skip to content

Commit 2eda398

Browse files
committed
refactor: replace git CLI calls with env vars for Docker-only execution
- get_base_url(): removed git remote checks, uses GALLERY_BASE_URL / GITHUB_REPOSITORY - get_git_source_url(): removed git remote checks, uses GITHUB_REPOSITORY / GITHUB_SERVER_URL - get_git_tag(): removed git describe, uses ACTION_REF env var - ping_aggregator(): log payload before sending - build.sh: pass GITHUB_REPOSITORY and GITHUB_SERVER_URL to Docker container
1 parent 85eb2be commit 2eda398

2 files changed

Lines changed: 16 additions & 68 deletions

File tree

scripts/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ step_gallery() {
6262
-e ACTION_PATH=/action \
6363
-e SEND_PING="${SEND_PING:-false}" \
6464
-e ACTION_REF="${ACTION_REF:-}" \
65+
-e GITHUB_REPOSITORY="${GITHUB_REPOSITORY:-}" \
66+
-e GITHUB_SERVER_URL="${GITHUB_SERVER_URL:-}" \
6567
-w /workspace \
6668
"${DOCKER_IMAGE}" \
6769
/action/scripts/build_gallery.py

scripts/build_gallery.py

Lines changed: 14 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -435,105 +435,48 @@ def format_iso8601(timestamp):
435435

436436

437437
def get_base_url():
438-
"""Derive base URL from git remote or environment variable.
439-
438+
"""Derive the gallery base URL from environment variables.
439+
440440
Priority:
441-
1. GALLERY_BASE_URL env var (user-provided)
442-
2. Extract from git remote (github.com/user/repo -> https://user.github.io/repo)
441+
1. GALLERY_BASE_URL env var (user-provided override)
442+
2. GITHUB_REPOSITORY env var (GitHub Actions, including Docker)
443443
3. Fallback to localhost
444444
"""
445445
base_url = os.environ.get('GALLERY_BASE_URL')
446446
if base_url:
447447
return base_url.rstrip('/')
448448

449-
# Try GITHUB_REPOSITORY env var (available in GitHub Actions, including Docker)
450449
gh_repo = os.environ.get('GITHUB_REPOSITORY') # e.g. "user/repo"
451450
if gh_repo:
452451
user, repo = gh_repo.split('/', 1)
453452
return f'https://{user}.github.io/{repo}'
454453

455-
# Try git remotes
456-
for remote_name in ('master', 'origin'):
457-
try:
458-
result = subprocess.run(
459-
['git', 'config', '--get', f'remote.{remote_name}.url'],
460-
capture_output=True, text=True, check=True
461-
)
462-
remote = result.stdout.strip()
463-
if 'github.com' in remote:
464-
parts = remote.replace(':', '/').replace('.git', '').split('/')
465-
user = parts[-2]
466-
repo = parts[-1]
467-
return f'https://{user}.github.io/{repo}'
468-
except Exception:
469-
pass
470-
471454
return 'http://localhost:8000' # Fallback
472455

473456

474457
AGGREGATOR_URL = "https://freecad-aggregator.fly.dev/ping"
475458

476459

477460
def get_git_source_url():
478-
"""Derive the HTTPS source URL from the git remote.
461+
"""Derive the HTTPS source URL from environment variables.
479462
480-
Handles both SSH (git@host:user/repo.git) and HTTPS remotes.
481-
Returns None if the remote cannot be determined.
463+
Uses GITHUB_REPOSITORY and GITHUB_SERVER_URL (set by GitHub Actions).
464+
Returns None if the variables are not set.
482465
"""
483-
# Try GITHUB_REPOSITORY env var first (works in Docker containers in GH Actions)
484466
gh_repo = os.environ.get('GITHUB_REPOSITORY') # e.g. "user/repo"
485467
if gh_repo:
486468
server = os.environ.get('GITHUB_SERVER_URL', 'https://github.com')
487469
return f'{server}/{gh_repo}'
488470

489-
# Try git remotes
490-
for remote_name in ('origin', 'master'):
491-
try:
492-
result = subprocess.run(
493-
['git', 'remote', 'get-url', remote_name],
494-
capture_output=True, text=True, check=True
495-
)
496-
remote = result.stdout.strip()
497-
if not remote:
498-
continue
499-
500-
# SSH: git@host:user/repo.git → https://host/user/repo
501-
if remote.startswith('git@'):
502-
remote = remote[len('git@'):]
503-
remote = remote.replace(':', '/', 1)
504-
remote = remote.rstrip('/')
505-
if remote.endswith('.git'):
506-
remote = remote[:-4]
507-
return f'https://{remote}'
508-
509-
# HTTPS
510-
if remote.startswith('http://') or remote.startswith('https://'):
511-
remote = remote.rstrip('/')
512-
if remote.endswith('.git'):
513-
remote = remote[:-4]
514-
return remote
515-
except Exception:
516-
continue
517-
518471
return None
519472

520473

521474
def get_git_tag():
522-
"""Get the current git tag (latest annotated tag).
523-
524-
Returns the tag name (e.g., 'v2.2.6') or 'main' as fallback.
475+
"""Get the current action version from the ACTION_REF env var.
476+
477+
Returns the tag/ref (e.g., 'v2.8.7') or 'dev' as fallback.
525478
"""
526-
try:
527-
result = subprocess.run(
528-
['git', 'describe', '--tags', '--abbrev=0'],
529-
capture_output=True, text=True, check=True
530-
)
531-
tag = result.stdout.strip()
532-
if tag:
533-
return tag
534-
except Exception:
535-
pass
536-
return 'main'
479+
return os.environ.get('ACTION_REF', 'dev')
537480

538481

539482
def build_discovery(config, models, profile, base_url):
@@ -607,6 +550,9 @@ def ping_aggregator(base_url):
607550
"event": "push",
608551
}).encode('utf-8')
609552

553+
safe_print(f"Aggregator ping to {AGGREGATOR_URL}")
554+
safe_print(f"Aggregator payload: {payload.decode()}")
555+
610556
req = urllib.request.Request(
611557
AGGREGATOR_URL,
612558
data=payload,

0 commit comments

Comments
 (0)