Skip to content

Commit c78b447

Browse files
authored
Merge pull request #5 from matifali/v3
2 parents a5f9f0e + 814d58e commit c78b447

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Update coder templates automatically
2525
| `activate` | Activate the new template version. | `true` |
2626
| `create` | Creates a new template if it does not exist | `true` |
2727
| `message` | Update message (similar to commit messages) | - |
28+
| `dry_run` | Dry run mode. | `false` |
2829

2930
## Examples
3031

action.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ inputs:
3434
description: "Creates a new template if it does not exist"
3535
required: false
3636
default: "true"
37+
dry_run:
38+
description: "Dry run"
39+
required: false
40+
default: "false"
3741

3842
runs:
3943
using: "composite"
@@ -43,7 +47,7 @@ runs:
4347
env:
4448
CODER_URL: ${{ inputs.url }}
4549

46-
- run: push_template.sh
50+
- run: ${{ github.action_path }}/push_template.sh
4751
shell: bash
4852
env:
4953
CODER_SESSION_TOKEN: ${{ inputs.coder_session_token }}
@@ -54,4 +58,4 @@ runs:
5458
CODER_TEMPLATE_ACTIVATE: ${{ inputs.activate }}
5559
CODER_TEMPLATE_MESSAGE: ${{ inputs.message }}
5660
CODER_TEMPLATE_CREATE: ${{ inputs.create }}
57-
61+
CODER_TEMPLATE_DRY_RUN: ${{ inputs.dry_run }}

push_template.sh

100644100755
+15-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ echo "CODER_TEMPLATE_ID: ${CODER_TEMPLATE_ID}"
1212
echo "CODER_TEMPLATE_DIR: ${CODER_TEMPLATE_DIR}"
1313

1414
# Construct push command
15-
push_command="coder templates push ${CODER_TEMPLATE_NAME} --directory ./${CODER_TEMPLATE_DIR}" --message ${CODER_TEMPLATE_MESSAGE}
15+
push_command="coder templates push ${CODER_TEMPLATE_ID} --directory ./${CODER_TEMPLATE_DIR}"
16+
17+
# Add message to the push command if specified
18+
if [ -n "${CODER_TEMPLATE_MESSAGE}" ]; then
19+
push_command+=" --message \"${CODER_TEMPLATE_MESSAGE}\""
20+
fi
1621

1722
# Append --create flag to the push command if CODER_TEMPLATE_CREATE is true
1823
if [ "${CODER_TEMPLATE_CREATE}" = "true" ]; then
@@ -32,7 +37,13 @@ fi
3237
# Add confirmation flag to the push command
3338
push_command+=" --yes"
3439

35-
# Execute the push command
36-
${push_command}
37-
40+
# Execute the push command if no dry run
41+
if [ "${CODER_TEMPLATE_DRY_RUN}" = "false" ]; then
42+
echo "Pushing ${CODER_TEMPLATE_DIR} to ${CODER_URL}..."
43+
eval ${push_command}
44+
echo "A new version of ${CODER_TEMPLATE_DIR} is pushed to ${CODER_URL} successfully."
45+
exit 0
46+
fi
47+
echo "Dry run is enabled. The following command will be executed:"
48+
echo ${push_command}
3849
echo "A new version of ${CODER_TEMPLATE_DIR} is pushed to ${CODER_URL} successfully."

0 commit comments

Comments
 (0)