|
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 4 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 5 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 6 | + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } |
| 7 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 8 | + }); |
| 9 | +}; |
| 10 | +var __importStar = (this && this.__importStar) || function (mod) { |
| 11 | + if (mod && mod.__esModule) return mod; |
| 12 | + var result = {}; |
| 13 | + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; |
| 14 | + result["default"] = mod; |
| 15 | + return result; |
| 16 | +}; |
| 17 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 18 | +const core = __importStar(require("@actions/core")); |
| 19 | +const tc = __importStar(require("@actions/tool-cache")); |
| 20 | +const exec = __importStar(require("@actions/exec")); |
| 21 | +const path = __importStar(require("path")); |
| 22 | +const VersionInput = "version"; |
| 23 | +const ConfigInput = "config"; |
| 24 | +const ImageInput = "image"; |
| 25 | +const NameInput = "name"; |
| 26 | +const WaitInput = "wait"; |
| 27 | +const SkipClusterCreationInput = "skipClusterCreation"; |
| 28 | +const toolName = "kind"; |
| 29 | +class KindConfig { |
| 30 | + constructor(version, configFile, image, name, waitDuration, skipClusterCreation) { |
| 31 | + this.version = version; |
| 32 | + this.configFile = configFile; |
| 33 | + this.image = image; |
| 34 | + this.name = name; |
| 35 | + this.waitDuration = waitDuration; |
| 36 | + this.skipClusterCreation = (skipClusterCreation == 'true'); |
| 37 | + } |
| 38 | + // returns the arguments to pass to `kind create cluster` |
| 39 | + getCommand() { |
| 40 | + let args = ["create", "cluster"]; |
| 41 | + if (this.configFile != "") { |
| 42 | + const wd = process.env[`GITHUB_WORKSPACE`] || ""; |
| 43 | + const absPath = path.join(wd, this.configFile); |
| 44 | + args.push("--config", absPath); |
| 45 | + } |
| 46 | + if (this.image != "") { |
| 47 | + args.push("--image", this.image); |
| 48 | + } |
| 49 | + if (this.name != "") { |
| 50 | + args.push("--name", this.name); |
| 51 | + } |
| 52 | + if (this.waitDuration != "") { |
| 53 | + args.push("--wait", this.waitDuration); |
| 54 | + } |
| 55 | + return args; |
| 56 | + } |
| 57 | + createCluster() { |
| 58 | + return __awaiter(this, void 0, void 0, function* () { |
| 59 | + if (this.skipClusterCreation) |
| 60 | + return; |
| 61 | + console.log("Executing kind with args " + this.getCommand()); |
| 62 | + yield exec.exec("kind", this.getCommand()); |
| 63 | + }); |
| 64 | + } |
| 65 | +} |
| 66 | +exports.KindConfig = KindConfig; |
| 67 | +function getKindConfig() { |
| 68 | + const v = core.getInput(VersionInput); |
| 69 | + const c = core.getInput(ConfigInput); |
| 70 | + const i = core.getInput(ImageInput); |
| 71 | + const n = core.getInput(NameInput); |
| 72 | + const w = core.getInput(WaitInput); |
| 73 | + const s = core.getInput(SkipClusterCreationInput); |
| 74 | + return new KindConfig(v, c, i, n, w, s); |
| 75 | +} |
| 76 | +exports.getKindConfig = getKindConfig; |
| 77 | +// this action should always be run from a Linux worker |
| 78 | +function downloadKind(version) { |
| 79 | + return __awaiter(this, void 0, void 0, function* () { |
| 80 | + let url = `https://github.com/kubernetes-sigs/kind/releases/download/${version}/kind-linux-amd64`; |
| 81 | + console.log("downloading kind from " + url); |
| 82 | + let downloadPath = null; |
| 83 | + downloadPath = yield tc.downloadTool(url); |
| 84 | + yield exec.exec("chmod", ["+x", downloadPath]); |
| 85 | + let toolPath = yield tc.cacheFile(downloadPath, "kind", toolName, version); |
| 86 | + core.debug(`kind is cached under ${toolPath}`); |
| 87 | + return toolPath; |
| 88 | + }); |
| 89 | +} |
| 90 | +exports.downloadKind = downloadKind; |
| 91 | +function getKind(version) { |
| 92 | + return __awaiter(this, void 0, void 0, function* () { |
| 93 | + let toolPath = tc.find(toolName, version); |
| 94 | + if (toolPath === "") { |
| 95 | + toolPath = yield downloadKind(version); |
| 96 | + } |
| 97 | + return toolPath; |
| 98 | + }); |
| 99 | +} |
| 100 | +exports.getKind = getKind; |
0 commit comments