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 153a373..1c0448b 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: "false" runs: using: "composite" @@ -43,7 +47,7 @@ runs: env: CODER_URL: ${{ inputs.url }} - - run: push_template.sh + - run: ${{ github.action_path }}/push_template.sh shell: bash env: CODER_SESSION_TOKEN: ${{ inputs.coder_session_token }} @@ -54,4 +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 old mode 100644 new mode 100755 index 3240b39..e209ff2 --- a/push_template.sh +++ b/push_template.sh @@ -12,7 +12,12 @@ echo "CODER_TEMPLATE_ID: ${CODER_TEMPLATE_ID}" echo "CODER_TEMPLATE_DIR: ${CODER_TEMPLATE_DIR}" # 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 if [ "${CODER_TEMPLATE_CREATE}" = "true" ]; then @@ -32,7 +37,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."