copilot / entrypoint.sh
Kaballas's picture
www
d1ba854
#!/bin/bash
set -euo pipefail
echo "=== Copilot OpenAI Server Startup ==="
echo ""
# Support either GH_TOKEN or GITHUB_TOKEN as input and normalize to both.
if [ -z "${GH_TOKEN:-}" ] && [ -z "${GITHUB_TOKEN:-}" ]; then
echo "ERROR: GH_TOKEN environment variable is not set!"
echo "Set a Hugging Face Space Secret named GH_TOKEN (or GITHUB_TOKEN) with a valid GitHub token."
exit 1
fi
if [ -z "${GH_TOKEN:-}" ]; then
GH_TOKEN="${GITHUB_TOKEN}"
fi
echo "GH_TOKEN is set (${#GH_TOKEN} characters)"
echo ""
# Export token for copilot CLI and GitHub CLI
export GH_TOKEN
export GITHUB_TOKEN=$GH_TOKEN
# Ensure GitHub CLI is available (required for authentication).
if ! command -v gh >/dev/null 2>&1; then
echo "ERROR: GitHub CLI (gh) is not installed in this image."
exit 1
fi
# Verify GitHub token via gh using env-based auth.
# With GH_TOKEN set, gh authenticates from env and `gh auth login` should not be used.
echo "Verifying GitHub token..."
if ! gh api user >/dev/null 2>&1; then
echo "ERROR: GH_TOKEN is set but failed GitHub API auth check."
echo "Ensure the token is valid and has required scopes/entitlements."
exit 1
fi
echo "GitHub token verification succeeded"
echo ""
echo "Starting Copilot OpenAI Server..."
echo ""
# Run the server
exec /usr/local/bin/copilot-server "$@"