-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_env_secret.sh
More file actions
executable file
·54 lines (47 loc) · 1.15 KB
/
update_env_secret.sh
File metadata and controls
executable file
·54 lines (47 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# Set the repository secret from the local production environment file
# Requires GitHub CLI (gh) to be installed and authenticated
# Default values
ENV_FILE="prod.env"
SECRET_NAME="PRODUCTION_ENV_FILE"
REPO="SoleSearchAPI/api"
# Parse command line arguments
while (("$#")); do
case "$1" in
--file)
ENV_FILE="$2"
shift 2
;;
--secret)
SECRET_NAME="$2"
shift 2
;;
--repo)
REPO="$2"
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Check if env file exists
if [ ! -f "$ENV_FILE" ]; then
echo "Error: Environment file '$ENV_FILE' not found"
exit 1
fi
# Set the repository parameter if provided
REPO_PARAM=""
if [ -n "$REPO" ]; then
REPO_PARAM="--repo $REPO"
fi
# Update the secret using GitHub CLI
echo "Setting GitHub secret '$SECRET_NAME' from file '$ENV_FILE'..."
gh secret set "$SECRET_NAME" $REPO_PARAM <"$ENV_FILE"
if [ $? -eq 0 ]; then
echo "Secret '$SECRET_NAME' updated successfully!"
else
echo "Failed to update secret. Make sure GitHub CLI is installed and you're authenticated."
exit 1
fi