diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 6a71334a..6a84250c 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -6,7 +6,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - uses: engineerd/setup-kind@v0.3.0 + - name: "npm install" + run: npm install + - name: "npm run build" + run: npm run build + - uses: ./ - name: Testing run: | kubectl cluster-info diff --git a/src/kind.ts b/src/kind.ts index 0a6cd499..61de4b2c 100644 --- a/src/kind.ts +++ b/src/kind.ts @@ -11,6 +11,8 @@ const NameInput: string = "name"; const WaitInput: string = "wait"; const SkipClusterCreationInput: string = "skipClusterCreation"; +const toolName: string = "kind"; + export class KindConfig { version: string configFile: string; @@ -69,16 +71,24 @@ export function getKindConfig(): KindConfig { } // this action should always be run from a Linux worker -export async function downloadKind(version: string) { +export async function downloadKind(version: string): Promise { let url: string = `https://github.com/kubernetes-sigs/kind/releases/download/${version}/kind-linux-amd64`; console.log("downloading kind from " + url); let downloadPath: string | null = null; downloadPath = await tc.downloadTool(url); - const binPath: string = "/home/runner/bin"; - await io.mkdirP(binPath); await exec.exec("chmod", ["+x", downloadPath]); - await io.mv(downloadPath, path.join(binPath, "kind")); + let toolPath: string = await tc.cacheFile(downloadPath, "kind", toolName, version); + core.debug(`kind is cached under ${toolPath}`); - core.addPath(binPath); + return toolPath; } +export async function getKind(version: string): Promise { + let toolPath: string = tc.find(toolName, version); + + if (toolPath === "") { + toolPath = await downloadKind(version); + } + + return toolPath; +} diff --git a/src/main.ts b/src/main.ts index d9fdd6a0..2db53013 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,10 +1,11 @@ import * as core from '@actions/core'; -import { KindConfig, getKindConfig, downloadKind } from './kind'; +import { KindConfig, getKindConfig, getKind } from './kind'; async function run() { try { let cfg: KindConfig = getKindConfig(); - await downloadKind(cfg.version); + let toolPath: string = await getKind(cfg.version); + core.addPath(toolPath); await cfg.createCluster(); } catch (error) { core.setFailed(error.message);