Skip to content

Instantly share code, notes, and snippets.

@celeroncoder
Created January 13, 2025 08:20
Show Gist options
  • Save celeroncoder/9f890b10dd2899abff9cc323cce01b7c to your computer and use it in GitHub Desktop.
Save celeroncoder/9f890b10dd2899abff9cc323cce01b7c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check if .env file exists
if [ ! -f .env ]; then
echo ".env file not found!"
exit 1
fi
# Read the repository name and owner
REPO="your-username/your-repo" # Change this to your GitHub repo
# Alternatively, you can use the current repo
# REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
# Read the .env file and set GitHub secrets
while IFS='=' read -r key value; do
# Skip empty lines and comments
if [[ -z "$key" || "$key" == \#* ]]; then
continue
fi
# Trim whitespace
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
# Add secret to GitHub
echo "Adding secret: $key"
gh secret set "$key" --body "$value" --repo "$REPO"
done < .env
echo "All secrets added successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment