2023-08-11 16:21:22 +08:00
|
|
|
#!/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}"
|
2023-08-11 16:49:33 +08:00
|
|
|
: "${CODER_TEMPLATE_DIR:?CODER_TEMPLATE_DIR not set or empty}"
|
|
|
|
echo "CODER_TEMPLATE_DIR: ${CODER_TEMPLATE_DIR}"
|
2023-08-11 16:21:22 +08:00
|
|
|
|
|
|
|
# Construct push command
|
2023-08-11 18:12:37 +08:00
|
|
|
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
|
2023-08-11 18:22:41 +08:00
|
|
|
push_command+=" --message \"${CODER_TEMPLATE_MESSAGE}\""
|
2023-08-11 18:12:37 +08:00
|
|
|
fi
|
2023-08-11 16:21:22 +08:00
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
2023-08-11 18:16:41 +08:00
|
|
|
# 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}
|
2023-08-11 16:21:22 +08:00
|
|
|
echo "A new version of ${CODER_TEMPLATE_DIR} is pushed to ${CODER_URL} successfully."
|