From cd1c4c7bb81103dd08fca8d236c42ca4aca7cc39 Mon Sep 17 00:00:00 2001 From: Tam Mach Date: Sat, 8 Aug 2020 19:21:41 +1000 Subject: [PATCH] Add post action cleanup to remove kind cluster (#21) --- .github/workflows/test.yaml | 16 ++++++++++++++++ action.yml | 1 + cleanup.js | 19 +++++++++++++++++++ cleanup.sh | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 cleanup.js create mode 100755 cleanup.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6f5c0b3..7495fa5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -20,3 +20,19 @@ jobs: run: | kubectl cluster-info kubectl get storageclass standard + + test-with-custom-name: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Create kind cluster with custom name + uses: ./ + with: + cluster_name: "custom-name" + + - name: Test + run: | + kubectl cluster-info + kubectl get storageclass standard diff --git a/action.yml b/action.yml index c154af4..9dc7d71 100644 --- a/action.yml +++ b/action.yml @@ -20,3 +20,4 @@ inputs: runs: using: "node12" main: "main.js" + post: "cleanup.js" diff --git a/cleanup.js b/cleanup.js new file mode 100644 index 0000000..47ee6fd --- /dev/null +++ b/cleanup.js @@ -0,0 +1,19 @@ +// Copyright The Helm Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// # You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// # See the License for the specific language governing permissions and +// limitations under the License. + +const spawnSync = require('child_process').spawnSync; +const path = require("path"); + +const proc = spawnSync('bash', [path.join(__dirname, 'cleanup.sh')], {stdio: 'inherit'}); +process.exit(proc.status) diff --git a/cleanup.sh b/cleanup.sh new file mode 100755 index 0000000..cb6c6a1 --- /dev/null +++ b/cleanup.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# Copyright The Helm Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +DEFAULT_CLUSTER_NAME=chart-testing + +main() { + args=() + + if [[ -n "${INPUT_CLUSTER_NAME:-}" ]]; then + args+=(--name "${INPUT_CLUSTER_NAME}") + else + args+=(--name "${DEFAULT_CLUSTER_NAME}") + fi + + kind delete cluster "${args[@]}" +} + +main +