From 0b3202d989fbda75d480a992b8d9d9b8d340578b Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 11 Aug 2023 13:16:41 +0300 Subject: [PATCH] add dry-run --- README.md | 1 + action.yaml | 5 +++++ push_template.sh | 12 +++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f72cdc3..7737f84 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Update coder templates automatically | `activate` | Activate the new template version. | `true` | | `create` | Creates a new template if it does not exist | `true` | | `message` | Update message (similar to commit messages) | - | +| `dry_run` | Dry run mode. | `false` | ## Examples diff --git a/action.yaml b/action.yaml index a1c2d6e..0730ba0 100644 --- a/action.yaml +++ b/action.yaml @@ -34,6 +34,10 @@ inputs: description: "Creates a new template if it does not exist" required: false default: "true" + dry_run: + description: "Dry run" + required: false + default: "true" # make it false after testing TODO runs: using: "composite" @@ -54,3 +58,4 @@ runs: CODER_TEMPLATE_ACTIVATE: ${{ inputs.activate }} CODER_TEMPLATE_MESSAGE: ${{ inputs.message }} CODER_TEMPLATE_CREATE: ${{ inputs.create }} + CODER_TEMPLATE_DRY_RUN: ${{ inputs.dry_run }} diff --git a/push_template.sh b/push_template.sh index fa9a44a..805e53c 100755 --- a/push_template.sh +++ b/push_template.sh @@ -38,7 +38,13 @@ fi # Add confirmation flag to the push command push_command+=" --yes" -# Execute the push command -${push_command} - +# 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."