-
Notifications
You must be signed in to change notification settings - Fork 4
/
push_template.sh
executable file
·44 lines (37 loc) · 1.52 KB
/
push_template.sh
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
#!/bin/bash -l
set -euo pipefail
# check if required variables are set
: "${CODER_SESSION_TOKEN:?CODER_SESSION_TOKEN not set or empty}"
echo "CODER_SESSION_TOKEN is set."
: "${CODER_URL:?CODER_URL not set or empty}"
echo "CODER_URL is set."
: "${CODER_TEMPLATE_ID:?CODER_TEMPLATE_ID not set or empty}"
echo "CODER_TEMPLATE_ID: ${CODER_TEMPLATE_ID}"
: "${CODER_TEMPLATE_DIR:?CODER_TEMPLATE_DIR not set or empty}"
echo "CODER_TEMPLATE_DIR: ${CODER_TEMPLATE_DIR}"
# Construct push command
push_command="coder templates push ${CODER_TEMPLATE_ID} --directory ./${CODER_TEMPLATE_DIR}"
# Add message to the push command if specified
if [ -n "${CODER_TEMPLATE_MESSAGE}" ]; then
push_command+=" --message \"${CODER_TEMPLATE_MESSAGE}\""
fi
# Add version to the push command if specified
if [ -n "${CODER_TEMPLATE_VERSION_NAME}" ]; then
push_command+=" --name ${CODER_TEMPLATE_VERSION_NAME}"
fi
# Add activate flag to the push command if it is false
if [ "${CODER_TEMPLATE_ACTIVATE}" = "false" ]; then
push_command+=" --activate=false"
fi
# Add confirmation flag to the push command
push_command+=" --yes"
# Execute the push command if no dry run
if [ "${CODER_TEMPLATE_DRY_RUN}" = "false" ]; then
echo "Pushing ${CODER_TEMPLATE_DIR} to ${CODER_URL}..."
eval ${push_command}
echo "A new version of ${CODER_TEMPLATE_DIR} is pushed to ${CODER_URL} successfully."
exit 0
fi
echo "Dry run is enabled. The following command will be executed:"
echo ${push_command}
echo "A new version of ${CODER_TEMPLATE_DIR} is pushed to ${CODER_URL} successfully."