Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
imranismail committed Mar 30, 2020
1 parent 155078e commit b03ae87
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 175 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/checkin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,5 @@ jobs:
steps:
- uses: actions/checkout@v1
- run: |
npm install
npm run all
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./
with:
milliseconds: 1000
npm ci
npm run all
126 changes: 71 additions & 55 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,103 +1,119 @@
import io = require('@actions/io');
import fs = require('fs');
import os = require('os');
import path = require('path');
import io = require('@actions/io')
import fs = require('fs')
import os = require('os')
import path = require('path')

const toolDir = path.join(__dirname, 'runner', 'tools');
const tempDir = path.join(__dirname, 'runner', 'temp');
const toolDir = path.join(__dirname, 'runner', 'tools')
const tempDir = path.join(__dirname, 'runner', 'temp')

process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir;
process.env['RUNNER_TOOL_CACHE'] = toolDir
process.env['RUNNER_TEMP'] = tempDir

import * as installer from '../src/installer';
import * as installer from '../src/installer'

const IS_WINDOWS = os.platform() === 'win32';
const IS_WINDOWS = os.platform() === 'win32'

describe('installer tests', () => {
beforeAll(async () => {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
}, 100000);
await io.rmRF(toolDir)
await io.rmRF(tempDir)
}, 100000)

afterAll(async () => {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
}, 100000);
await io.rmRF(toolDir)
await io.rmRF(tempDir)
}, 100000)

it('Acquires kustomize version 3.2.0 successfully', async () => {
await installer.getKustomize('3.2.0');
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.0', os.arch());
await installer.getKustomize('3.2.0')
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.0', os.arch())

expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true);
expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true)

if (IS_WINDOWS) {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true);
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true)
} else {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true);
expect(() => fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)).not.toThrow()
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true)
expect(() =>
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
).not.toThrow()
}
}, 100000);
}, 100000)

it ('Acquires kustomize version 3.2.1 successfully', async () => {
await installer.getKustomize('3.2.1');
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.1', os.arch());
it('Acquires kustomize version 3.2.1 successfully', async () => {
await installer.getKustomize('3.2.1')
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.1', os.arch())

expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true);
expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true)

if (IS_WINDOWS) {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true);
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true)
} else {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true);
expect(() => fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)).not.toThrow()
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true)
expect(() =>
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
).not.toThrow()
}
}, 100000)

it ('Acquires kustomize version 3.3.0 successfully', async () => {
await installer.getKustomize('3.3.0');
const kustomizeDir = path.join(toolDir, 'kustomize', '3.3.0', os.arch());
it('Acquires kustomize version 3.3.0 successfully', async () => {
await installer.getKustomize('3.3.0')
const kustomizeDir = path.join(toolDir, 'kustomize', '3.3.0', os.arch())

expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true);
expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true)

if (IS_WINDOWS) {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true);
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true)
} else {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true);
expect(() => fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)).not.toThrow()
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true)
expect(() =>
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
).not.toThrow()
}
}, 100000)

it('Throws if no location contains correct kustomize version', async () => {
let thrown = false;
let thrown = false

try {
await installer.getKustomize('1000');
await installer.getKustomize('1000')
} catch {
thrown = true;
thrown = true
}

expect(thrown).toBe(true);
});
expect(thrown).toBe(true)
})

it('Uses version of kustomize installed in cache', async () => {
const kustomizeDir: string = path.join(toolDir, 'kustomize', '3.2.0', os.arch());
const kustomizeDir: string = path.join(
toolDir,
'kustomize',
'3.2.0',
os.arch()
)

await io.mkdirP(kustomizeDir);
await io.mkdirP(kustomizeDir)

fs.writeFileSync(`${kustomizeDir}.complete`, 'hello');
fs.writeFileSync(`${kustomizeDir}.complete`, 'hello')

await installer.getKustomize('3.2.0');
await installer.getKustomize('3.2.0')

return;
});
return
})

it('Resolves semantic versions of kustomize installed in cache', async () => {
const kustomizeDir: string = path.join(toolDir, 'kustomize', '3.0.0', os.arch());
const kustomizeDir: string = path.join(
toolDir,
'kustomize',
'3.0.0',
os.arch()
)

await io.mkdirP(kustomizeDir);
await io.mkdirP(kustomizeDir)

fs.writeFileSync(`${kustomizeDir}.complete`, 'hello');
fs.writeFileSync(`${kustomizeDir}.complete`, 'hello')

await installer.getKustomize('3.0.0');
await installer.getKustomize('3.0');
});
});
await installer.getKustomize('3.0.0')
await installer.getKustomize('3.0')
})
})
38 changes: 19 additions & 19 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,7 @@ function run() {
// Version is optional. If supplied, install / use from the tool cache
// If not supplied then task is still used to setup proxy, auth, etc...
//
let version = core.getInput('kustomize-version');
const version = core.getInput('kustomize-version');
if (version) {
yield installer.getKustomize(version);
}
Expand Down Expand Up @@ -6814,16 +6814,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
// Load tempDirectory before it gets wiped by tool-cache
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
const core = __importStar(__webpack_require__(470));
const tc = __importStar(__webpack_require__(533));
const restm = __importStar(__webpack_require__(105));
const os = __importStar(__webpack_require__(87));
const path = __importStar(__webpack_require__(622));
const semver = __importStar(__webpack_require__(876));
const fs = __importStar(__webpack_require__(747));
let osPlat = os.platform();
let osArch = os.arch();
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
const osPlat = os.platform();
const osArch = os.arch();
if (!tempDirectory) {
let baseLocation;
if (process.platform === 'win32') {
Expand Down Expand Up @@ -6891,18 +6891,18 @@ function queryLatestMatch(versionSpec) {
default:
dataFileName = `${dataFileName}_${osArch}`;
}
let versions = [];
let dataUrl = 'https://api.github.com/repos/kubernetes-sigs/kustomize/releases';
let rest = new restm.RestClient('setup-kustomize');
let kustomizeVersions = (yield rest.get(dataUrl)).result || [];
kustomizeVersions.forEach((kustomizeVersion) => {
const versions = [];
const dataUrl = 'https://api.github.com/repos/kubernetes-sigs/kustomize/releases';
const rest = new restm.RestClient('setup-kustomize');
const kustomizeVersions = (yield rest.get(dataUrl)).result || [];
for (const kustomizeVersion of kustomizeVersions) {
if (kustomizeVersion.assets.some(asset => asset.name.includes(dataFileName))) {
let version = semver.clean(kustomizeVersion.name);
const version = semver.clean(kustomizeVersion.name);
if (version != null) {
versions.push(version);
}
}
});
}
return evaluateVersions(versions, versionSpec);
});
}
Expand Down Expand Up @@ -6936,26 +6936,26 @@ function acquireKustomize(version) {
version = semver.clean(version) || '';
let downloadUrl;
let toolPath;
let toolFilename = "kustomize";
let toolName = "kustomize";
if (osPlat == "win32") {
let toolFilename = 'kustomize';
const toolName = 'kustomize';
if (osPlat === 'win32') {
toolFilename = `${toolFilename}.exe`;
}
if (semver.gte(version, "3.3.0")) {
if (semver.gte(version, '3.3.0')) {
downloadUrl = `https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${version}/kustomize_v${version}_%{os}_%{arch}.tar.gz`;
}
else if (semver.gte(version, "3.2.1")) {
else if (semver.gte(version, '3.2.1')) {
downloadUrl = `https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${version}/kustomize_kustomize.v${version}_%{os}_%{arch}`;
}
else {
downloadUrl = `https://github.com/kubernetes-sigs/kustomize/releases/download/v${version}/kustomize_${version}_%{os}_%{arch}`;
}
switch (osPlat) {
case 'win32':
if (semver.lte(version, "3.2.1"))
if (semver.lte(version, '3.2.1'))
throw new Error(`Unexpected OS '${osPlat}'`);
downloadUrl = downloadUrl.replace('%{os}', 'windows');
if (semver.lt(version, "3.3.0"))
if (semver.lt(version, '3.3.0'))
downloadUrl = `${downloadUrl}.exe`;
break;
case 'linux':
Expand All @@ -6977,7 +6977,7 @@ function acquireKustomize(version) {
}
catch (err) {
core.debug(err);
throw `Failed to download version ${version}: ${err}`;
throw new Error(`Failed to download version ${version}: ${err}`);
}
if (downloadUrl.endsWith('.tar.gz')) {
toolPath = yield tc.extractTar(toolPath);
Expand Down
Loading

0 comments on commit b03ae87

Please sign in to comment.