avisenna-landing-page/scripts/update-github-secrets.sh
Keyvan Ebrahimpour 900af910df - Automatically creates ghcr-creds secret in the appropriate namespace if missing
- Adds branch pattern triggers for k8s/** and scripts/** to enable CI/CD from infra or automation-related updates
- Improves workflow robustness and flexibility for feature and tooling branches
2025-04-11 22:37:14 +00:00

36 lines
852 B
Bash

#!/bin/bash
set -euo pipefail
REPO="kebrahimpour/avisenna-landing-page"
GHCR_PAT="${GHCR_PAT:-}"
TOKEN_SOURCE=""
# Try env or fallback to file
if [[ -z "$GHCR_PAT" ]]; then
TOKEN_PATH="$HOME/.secrets/g-token.txt"
if [[ -f "$TOKEN_PATH" ]]; then
GHCR_PAT=$(<"$TOKEN_PATH")
TOKEN_SOURCE="file"
fi
else
TOKEN_SOURCE="env"
fi
if [[ -z "$GHCR_PAT" ]]; then
echo "❌ GHCR_PAT not found. Set as env or in ~/.secrets/g-token.txt"
exit 1
fi
echo "🔐 Using GHCR_PAT from $TOKEN_SOURCE"
gh secret set GHCR_PAT --repo "$REPO" --body "$GHCR_PAT"
echo "✅ GHCR_PAT updated"
KCFG="$HOME/.kube/github-kubeconfig.yaml"
if [[ ! -f "$KCFG" ]]; then
echo "❌ Kubeconfig not found at $KCFG"
exit 1
fi
ENCODED_KCFG=$(base64 -w 0 "$KCFG")
gh secret set KUBECONFIG_B64 --repo "$REPO" --body "$ENCODED_KCFG"
echo "✅ KUBECONFIG_B64 updated"