diff --git a/action.yaml b/action.yaml index b59e0a3..bcb919d 100644 --- a/action.yaml +++ b/action.yaml @@ -33,9 +33,12 @@ inputs: runs: using: composite steps: - - id: main - shell: bash - run: ${{ github.action_path }}/run.sh deploy + - uses: gacts/run-and-post-run@v1 + with: + run: | + ${{ github.action_path }}/run.sh deploy + post: | + ${{ github.action_path }}/run.sh teardown env: CLUSTER_NAME: ${{ inputs.cluster-name }} ARGS: ${{ inputs.args }} diff --git a/run.sh b/run.sh index 8d9f230..93ee6c7 100755 --- a/run.sh +++ b/run.sh @@ -38,6 +38,7 @@ usage(){ Usage: $(basename "$0") Commands: deploy deploy custom k3d cluster + teardown teardown custom k3d cluster Environment variables: deploy @@ -46,6 +47,8 @@ usage(){ ARGS (Optional) k3d arguments. K3D_VERSION (Optional) k3d version. + teardown + CLUSTER_NAME (Required) k3d cluster name. EOF } @@ -72,6 +75,17 @@ deploy(){ wait_for_nodes } +teardown(){ + local name=${CLUSTER_NAME} + + if [[ -z "${CLUSTER_NAME}" ]]; then + panic "CLUSTER_NAME must be set" + fi + + echo -e "\existing_network${YELLOW}Teardown cluster ${CYAN}$name ${NC}" + eval "k3d cluster delete $name" +} + # waits until all nodes are ready wait_for_nodes(){ echo -e "${YELLOW}wait until all agents are ready${NC}" @@ -121,6 +135,9 @@ case "$1" in "deploy") deploy ;; + "teardown") + teardown + ;; # "") # command_handler # ;;