Skip to content

Commit

Permalink
update the actions
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKhalif8254 committed Sep 20, 2024
1 parent 6fb39d4 commit aafaa3c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
environment: [production, preview]
environment: ${{ matrix.environment }}

steps:
- uses: actions/checkout@v3
Expand Down
58 changes: 58 additions & 0 deletions gh_set_secrects.sh
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!"

0 comments on commit aafaa3c

Please sign in to comment.