diff --git a/.github/workflows/TriggerIntegrationTests.sh b/.github/workflows/TriggerIntegrationTests.sh deleted file mode 100644 index 8d9a4ad..0000000 --- a/.github/workflows/TriggerIntegrationTests.sh +++ /dev/null @@ -1,33 +0,0 @@ -token=$1 -commit=$2 -repository=$3 -prNumber=$4 -frombranch=$5 -tobranch=$6 -patUser=$6 - -getPayLoad() { - cat < { test('getExecutableExtension() - return .exe when os is Windows', () => { jest.spyOn(os, 'type').mockReturnValue('Windows_NT'); - expect(helpers.getExecutableExtension()).toBe('.exe'); + expect(getExecutableExtension()).toBe('.exe'); expect(os.type).toBeCalled(); }); test('getExecutableExtension() - return empty string for non-windows OS', () => { jest.spyOn(os, 'type').mockReturnValue('Darwin'); - expect(helpers.getExecutableExtension()).toBe(''); + expect(getExecutableExtension()).toBe(''); expect(os.type).toBeCalled(); }); @@ -29,7 +29,7 @@ describe('Testing all functions in run file.', () => { ])("getKubectlArch() - return on %s os arch %s kubectl arch", (osArch, kubectlArch) => { jest.spyOn(os, 'arch').mockReturnValue(osArch); - expect(helpers.getKubectlArch()).toBe(kubectlArch); + expect(getKubectlArch()).toBe(kubectlArch); expect(os.arch).toBeCalled(); }); @@ -41,7 +41,7 @@ describe('Testing all functions in run file.', () => { jest.spyOn(os, 'type').mockReturnValue('Linux'); const kubectlLinuxUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/linux/%s/kubectl', arch); - expect(helpers.getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlLinuxUrl); + expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlLinuxUrl); expect(os.type).toBeCalled(); }); @@ -53,7 +53,7 @@ describe('Testing all functions in run file.', () => { jest.spyOn(os, 'type').mockReturnValue('Darwin'); const kubectlDarwinUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/darwin/%s/kubectl', arch); - expect(helpers.getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlDarwinUrl); + expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlDarwinUrl); expect(os.type).toBeCalled(); }); @@ -65,7 +65,7 @@ describe('Testing all functions in run file.', () => { jest.spyOn(os, 'type').mockReturnValue('Windows_NT'); const kubectlWindowsUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/windows/%s/kubectl.exe', arch); - expect(helpers.getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlWindowsUrl); + expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlWindowsUrl); expect(os.type).toBeCalled(); }); diff --git a/src/run.ts b/src/run.ts index fd44a90..5a2d2f6 100644 --- a/src/run.ts +++ b/src/run.ts @@ -5,7 +5,7 @@ import * as fs from 'fs'; import * as toolCache from '@actions/tool-cache'; import * as core from '@actions/core'; -import * as helpers from './helpers'; +import { getkubectlDownloadURL, getKubectlArch, getExecutableExtension } from './helpers'; const kubectlToolName = 'kubectl'; const stableKubectlVersion = 'v1.15.0'; @@ -20,7 +20,7 @@ export async function run() { core.addPath(path.dirname(cachedPath)); - console.log(`Kubectl tool version: '${version}' has been cached at ${cachedPath}`); + core.debug(`Kubectl tool version: '${version}' has been cached at ${cachedPath}`); core.setOutput('kubectl-path', cachedPath); } @@ -41,10 +41,10 @@ export async function getStableKubectlVersion(): Promise { export async function downloadKubectl(version: string): Promise { let cachedToolpath = toolCache.find(kubectlToolName, version); let kubectlDownloadPath = ''; - const arch = helpers.getKubectlArch(); + const arch = getKubectlArch(); if (!cachedToolpath) { try { - kubectlDownloadPath = await toolCache.downloadTool(helpers.getkubectlDownloadURL(version, arch)); + kubectlDownloadPath = await toolCache.downloadTool(getkubectlDownloadURL(version, arch)); } catch (exception) { if (exception instanceof toolCache.HTTPError && exception.httpStatusCode === 404) { throw new Error(util.format("Kubectl '%s' for '%s' arch not found.", version, arch)); @@ -53,10 +53,10 @@ export async function downloadKubectl(version: string): Promise { } } - cachedToolpath = await toolCache.cacheFile(kubectlDownloadPath, kubectlToolName + helpers.getExecutableExtension(), kubectlToolName, version); + cachedToolpath = await toolCache.cacheFile(kubectlDownloadPath, kubectlToolName + getExecutableExtension(), kubectlToolName, version); } - const kubectlPath = path.join(cachedToolpath, kubectlToolName + helpers.getExecutableExtension()); + const kubectlPath = path.join(cachedToolpath, kubectlToolName + getExecutableExtension()); fs.chmodSync(kubectlPath, '777'); return kubectlPath; } diff --git a/test/validateKubectl.py b/test/validateKubectl.py new file mode 100644 index 0000000..cff10a0 --- /dev/null +++ b/test/validateKubectl.py @@ -0,0 +1,31 @@ +import os, sys, json, requests, time + +version_to_check = sys.argv[1] +version_info = None +PASSED = False + +try: + print('kubectl version --client -o json') + version_info = json.load(os.popen('kubectl version --client -o json')) +except Exception as ex: + sys.exit('kubectl not installed') + +try: + if version_to_check == 'latest': + response = None + time_to_sleep = 2 + for _ in range(10): + response = requests.get('https://storage.googleapis.com/kubernetes-release/release/stable.txt') + if response.status_code == 200: + break + print('Failed to obtain latest version info, retrying.') + time.sleep(time_to_sleep) + time_to_sleep *= 2 + version_to_check = response.content.decode('utf-8') + PASSED = True if version_info['clientVersion']['gitVersion'] == version_to_check else False +except: + pass + +if not PASSED: + sys.exit('Setting up of '+version_to_check+' kubectl failed') +print('Test passed') \ No newline at end of file