mirror of
https://github.com/matifali/update-coder-template.git
synced 2024-09-20 06:46:04 +08:00
Merge pull request #5 from matifali/v3
This commit is contained in:
commit
c78b447a96
|
@ -25,6 +25,7 @@ Update coder templates automatically
|
||||||
| `activate` | Activate the new template version. | `true` |
|
| `activate` | Activate the new template version. | `true` |
|
||||||
| `create` | Creates a new template if it does not exist | `true` |
|
| `create` | Creates a new template if it does not exist | `true` |
|
||||||
| `message` | Update message (similar to commit messages) | - |
|
| `message` | Update message (similar to commit messages) | - |
|
||||||
|
| `dry_run` | Dry run mode. | `false` |
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,10 @@ inputs:
|
||||||
description: "Creates a new template if it does not exist"
|
description: "Creates a new template if it does not exist"
|
||||||
required: false
|
required: false
|
||||||
default: "true"
|
default: "true"
|
||||||
|
dry_run:
|
||||||
|
description: "Dry run"
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
|
@ -43,7 +47,7 @@ runs:
|
||||||
env:
|
env:
|
||||||
CODER_URL: ${{ inputs.url }}
|
CODER_URL: ${{ inputs.url }}
|
||||||
|
|
||||||
- run: push_template.sh
|
- run: ${{ github.action_path }}/push_template.sh
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
CODER_SESSION_TOKEN: ${{ inputs.coder_session_token }}
|
CODER_SESSION_TOKEN: ${{ inputs.coder_session_token }}
|
||||||
|
@ -54,4 +58,4 @@ runs:
|
||||||
CODER_TEMPLATE_ACTIVATE: ${{ inputs.activate }}
|
CODER_TEMPLATE_ACTIVATE: ${{ inputs.activate }}
|
||||||
CODER_TEMPLATE_MESSAGE: ${{ inputs.message }}
|
CODER_TEMPLATE_MESSAGE: ${{ inputs.message }}
|
||||||
CODER_TEMPLATE_CREATE: ${{ inputs.create }}
|
CODER_TEMPLATE_CREATE: ${{ inputs.create }}
|
||||||
|
CODER_TEMPLATE_DRY_RUN: ${{ inputs.dry_run }}
|
||||||
|
|
19
push_template.sh
Normal file → Executable file
19
push_template.sh
Normal file → Executable file
|
@ -12,7 +12,12 @@ echo "CODER_TEMPLATE_ID: ${CODER_TEMPLATE_ID}"
|
||||||
echo "CODER_TEMPLATE_DIR: ${CODER_TEMPLATE_DIR}"
|
echo "CODER_TEMPLATE_DIR: ${CODER_TEMPLATE_DIR}"
|
||||||
|
|
||||||
# Construct push command
|
# Construct push command
|
||||||
push_command="coder templates push ${CODER_TEMPLATE_NAME} --directory ./${CODER_TEMPLATE_DIR}" --message ${CODER_TEMPLATE_MESSAGE}
|
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
|
||||||
|
|
||||||
# Append --create flag to the push command if CODER_TEMPLATE_CREATE is true
|
# Append --create flag to the push command if CODER_TEMPLATE_CREATE is true
|
||||||
if [ "${CODER_TEMPLATE_CREATE}" = "true" ]; then
|
if [ "${CODER_TEMPLATE_CREATE}" = "true" ]; then
|
||||||
|
@ -32,7 +37,13 @@ fi
|
||||||
# Add confirmation flag to the push command
|
# Add confirmation flag to the push command
|
||||||
push_command+=" --yes"
|
push_command+=" --yes"
|
||||||
|
|
||||||
# Execute the push command
|
# Execute the push command if no dry run
|
||||||
${push_command}
|
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."
|
echo "A new version of ${CODER_TEMPLATE_DIR} is pushed to ${CODER_URL} successfully."
|
||||||
|
|
Loading…
Reference in a new issue