Refactoring Action for use with AKS Atlanta (#37)
* Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src. * Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src. * Grabbed the upstream integration tests and brought them here. Removed bash script. Added validateKubectl.py to /test folder for integration tests. * Ran npm run build * Ran npm run build * Updated on section for integration-tests.yml * Removing ruby commands from integration tests yaml. * Fixing discrepancies in integration test yaml. * Fixing discrepancies in integration test yaml. * Default to ubuntu-latest * renamed python script according to workflow. * renamed python script according to workflow. * Fixing path parameters. * Updated tsconfig.json * Testing for int test failure. * Validated that int tests work. * Added new workflows. * Testing release (#10) * Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src. * Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src. * Grabbed the upstream integration tests and brought them here. Removed bash script. Added validateKubectl.py to /test folder for integration tests. * Ran npm run build * Ran npm run build * Updated on section for integration-tests.yml * Removing ruby commands from integration tests yaml. * Fixing discrepancies in integration test yaml. * Fixing discrepancies in integration test yaml. * Default to ubuntu-latest * renamed python script according to workflow. * renamed python script according to workflow. * Fixing path parameters. * Updated tsconfig.json * Testing for int test failure. * Validated that int tests work. * Added new workflows. Co-authored-by: Tommy Barnes <thbarnes@microsoft.com> * made changes reflected in comments Co-authored-by: Tommy Barnes <thbarnes@microsoft.com>
This commit is contained in:
parent
dae4b3de7f
commit
a10d84bc2e
16 changed files with 590 additions and 194 deletions
51
src/run.ts
51
src/run.ts
|
@ -1,4 +1,3 @@
|
|||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
import * as fs from 'fs';
|
||||
|
@ -6,38 +5,23 @@ import * as fs from 'fs';
|
|||
import * as toolCache from '@actions/tool-cache';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import { getkubectlDownloadURL, getKubectlArch, getExecutableExtension } from './helpers';
|
||||
|
||||
const kubectlToolName = 'kubectl';
|
||||
const stableKubectlVersion = 'v1.15.0';
|
||||
const stableVersionUrl = 'https://storage.googleapis.com/kubernetes-release/release/stable.txt';
|
||||
|
||||
export function getExecutableExtension(): string {
|
||||
if (os.type().match(/^Win/)) {
|
||||
return '.exe';
|
||||
export async function run() {
|
||||
let version = core.getInput('version', { 'required': true });
|
||||
if (version.toLocaleLowerCase() === 'latest') {
|
||||
version = await getStableKubectlVersion();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
const cachedPath = await downloadKubectl(version);
|
||||
|
||||
export function getKubectlArch(): string {
|
||||
let arch = os.arch();
|
||||
if (arch === 'x64') {
|
||||
return 'amd64';
|
||||
}
|
||||
return arch;
|
||||
}
|
||||
core.addPath(path.dirname(cachedPath));
|
||||
|
||||
export function getkubectlDownloadURL(version: string, arch: string): string {
|
||||
switch (os.type()) {
|
||||
case 'Linux':
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/%s/kubectl', version, arch);
|
||||
|
||||
case 'Darwin':
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/darwin/%s/kubectl', version, arch);
|
||||
|
||||
case 'Windows_NT':
|
||||
default:
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/windows/%s/kubectl.exe', version, arch);
|
||||
|
||||
}
|
||||
core.debug(`Kubectl tool version: '${version}' has been cached at ${cachedPath}`);
|
||||
core.setOutput('kubectl-path', cachedPath);
|
||||
}
|
||||
|
||||
export async function getStableKubectlVersion(): Promise<string> {
|
||||
|
@ -57,7 +41,7 @@ export async function getStableKubectlVersion(): Promise<string> {
|
|||
export async function downloadKubectl(version: string): Promise<string> {
|
||||
let cachedToolpath = toolCache.find(kubectlToolName, version);
|
||||
let kubectlDownloadPath = '';
|
||||
let arch = getKubectlArch();
|
||||
const arch = getKubectlArch();
|
||||
if (!cachedToolpath) {
|
||||
try {
|
||||
kubectlDownloadPath = await toolCache.downloadTool(getkubectlDownloadURL(version, arch));
|
||||
|
@ -77,17 +61,4 @@ export async function downloadKubectl(version: string): Promise<string> {
|
|||
return kubectlPath;
|
||||
}
|
||||
|
||||
export async function run() {
|
||||
let version = core.getInput('version', { 'required': true });
|
||||
if (version.toLocaleLowerCase() === 'latest') {
|
||||
version = await getStableKubectlVersion();
|
||||
}
|
||||
let cachedPath = await downloadKubectl(version);
|
||||
|
||||
core.addPath(path.dirname(cachedPath));
|
||||
|
||||
console.log(`Kubectl tool version: '${version}' has been cached at ${cachedPath}`);
|
||||
core.setOutput('kubectl-path', cachedPath);
|
||||
}
|
||||
|
||||
run().catch(core.setFailed);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue