From 984aa8c7d0a7799bf53f52216491791f7aa588dc Mon Sep 17 00:00:00 2001 From: Kazuki Suda Date: Tue, 25 Feb 2020 16:56:08 +0900 Subject: [PATCH 1/3] Fix permission denied, mkdir '/home/runner' on a self-hosted runner Signed-off-by: Kazuki Suda --- .github/workflows/e2e.yml | 6 +++++- src/kind.ts | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) 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..4ba59d26 100644 --- a/src/kind.ts +++ b/src/kind.ts @@ -74,11 +74,10 @@ export async function downloadKind(version: string) { 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 = await tc.cacheFile(downloadPath, "kind", "kind", version); + core.debug(`kind is cached under ${toolPath}`); - core.addPath(binPath); + core.addPath(toolPath); } From 8eaabe6796ba4409f74ee264a54cc9a8daac7719 Mon Sep 17 00:00:00 2001 From: Kazuki Suda Date: Wed, 26 Feb 2020 19:21:34 +0900 Subject: [PATCH 2/3] Use a cached file if it exists --- src/kind.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/kind.ts b/src/kind.ts index 4ba59d26..62130483 100644 --- a/src/kind.ts +++ b/src/kind.ts @@ -70,13 +70,19 @@ export function getKindConfig(): KindConfig { // this action should always be run from a Linux worker export async function downloadKind(version: string) { - 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); - await exec.exec("chmod", ["+x", downloadPath]); - let toolPath = await tc.cacheFile(downloadPath, "kind", "kind", version); - core.debug(`kind is cached under ${toolPath}`); + let toolPath: string = tc.find("kind", version); + + if (toolPath !== "") { + console.log(`found a cached file in ${toolPath}`) + } else { + 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); + await exec.exec("chmod", ["+x", downloadPath]); + toolPath = await tc.cacheFile(downloadPath, "kind", "kind", version); + core.debug(`kind is cached under ${toolPath}`); + } core.addPath(toolPath); } From 2db0c02ee4cfc2e79354abb97a659c85fe0a19d7 Mon Sep 17 00:00:00 2001 From: Kazuki Suda Date: Thu, 27 Feb 2020 21:53:03 +0900 Subject: [PATCH 3/3] fixup! Use a cached file if it exists --- src/kind.ts | 35 ++++++++++++++++++++--------------- src/main.ts | 5 +++-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/kind.ts b/src/kind.ts index 62130483..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,21 +71,24 @@ export function getKindConfig(): KindConfig { } // this action should always be run from a Linux worker -export async function downloadKind(version: string) { - let toolPath: string = tc.find("kind", version); - - if (toolPath !== "") { - console.log(`found a cached file in ${toolPath}`) - } else { - 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); - await exec.exec("chmod", ["+x", downloadPath]); - toolPath = await tc.cacheFile(downloadPath, "kind", "kind", version); - core.debug(`kind is cached under ${toolPath}`); - } +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); + await exec.exec("chmod", ["+x", downloadPath]); + let toolPath: string = await tc.cacheFile(downloadPath, "kind", toolName, version); + core.debug(`kind is cached under ${toolPath}`); - core.addPath(toolPath); + 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);