-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fb39d4
commit aafaa3c
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
|
||
# Path to your .env.local file | ||
ENV_FILE=".env.local" | ||
|
||
# Array of environments | ||
ENVIRONMENTS=("production" "preview") | ||
|
||
# Check if the file exists | ||
if [ ! -f "$ENV_FILE" ]; then | ||
echo "Error: $ENV_FILE not found" | ||
exit 1 | ||
fi | ||
|
||
# Function to create environment if it doesn't exist | ||
create_environment() { | ||
if ! gh environment view "$1" &>/dev/null; then | ||
echo "Environment $1 does not exist. Creating it..." | ||
gh environment create "$1" | ||
fi | ||
} | ||
|
||
# Function to set or update a secret | ||
set_or_update_secret() { | ||
local env=$1 | ||
local key=$2 | ||
local value=$3 | ||
|
||
echo "Setting/updating environment secret for $env: $key" | ||
gh secret set "$key" --env "$env" -b "$value" | ||
} | ||
|
||
# Create environments if they don't exist | ||
for env in "${ENVIRONMENTS[@]}"; do | ||
create_environment "$env" | ||
done | ||
|
||
# Read each line from .env.local | ||
while IFS= read -r line || [[ -n "$line" ]]; do | ||
# Skip empty lines and comments | ||
if [[ -z "$line" ]] || [[ "$line" =~ ^#.* ]]; then | ||
continue | ||
fi | ||
|
||
# Extract the key and value | ||
key=$(echo "$line" | cut -d '=' -f1) | ||
value=$(echo "$line" | cut -d '=' -f2-) | ||
|
||
# Remove surrounding quotes from the value if present | ||
value=$(echo "$value" | sed -e 's/^"//' -e 's/"$//') | ||
|
||
# Set or update the secret for each environment | ||
for env in "${ENVIRONMENTS[@]}"; do | ||
set_or_update_secret "$env" "$key" "$value": | ||
done | ||
done < "$ENV_FILE" | ||
|
||
echo "All environment secrets have been set/updated for production and preview!" |