mirror of
https://github.com/imranismail/setup-kustomize.git
synced 2026-09-15 12:18:44 +00:00
Fix linting
This commit is contained in:
11
.github/workflows/checkin.yml
vendored
11
.github/workflows/checkin.yml
vendored
@@ -12,12 +12,5 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- run: |
|
- run: |
|
||||||
npm install
|
npm ci
|
||||||
npm run all
|
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
|
|
||||||
@@ -1,103 +1,119 @@
|
|||||||
import io = require('@actions/io');
|
import io = require('@actions/io')
|
||||||
import fs = require('fs');
|
import fs = require('fs')
|
||||||
import os = require('os');
|
import os = require('os')
|
||||||
import path = require('path');
|
import path = require('path')
|
||||||
|
|
||||||
const toolDir = path.join(__dirname, 'runner', 'tools');
|
const toolDir = path.join(__dirname, 'runner', 'tools')
|
||||||
const tempDir = path.join(__dirname, 'runner', 'temp');
|
const tempDir = path.join(__dirname, 'runner', 'temp')
|
||||||
|
|
||||||
process.env['RUNNER_TOOL_CACHE'] = toolDir;
|
process.env['RUNNER_TOOL_CACHE'] = toolDir
|
||||||
process.env['RUNNER_TEMP'] = tempDir;
|
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', () => {
|
describe('installer tests', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await io.rmRF(toolDir);
|
await io.rmRF(toolDir)
|
||||||
await io.rmRF(tempDir);
|
await io.rmRF(tempDir)
|
||||||
}, 100000);
|
}, 100000)
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await io.rmRF(toolDir);
|
await io.rmRF(toolDir)
|
||||||
await io.rmRF(tempDir);
|
await io.rmRF(tempDir)
|
||||||
}, 100000);
|
}, 100000)
|
||||||
|
|
||||||
it('Acquires kustomize version 3.2.0 successfully', async () => {
|
it('Acquires kustomize version 3.2.0 successfully', async () => {
|
||||||
await installer.getKustomize('3.2.0');
|
await installer.getKustomize('3.2.0')
|
||||||
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.0', os.arch());
|
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) {
|
if (IS_WINDOWS) {
|
||||||
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true);
|
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true)
|
||||||
} else {
|
} else {
|
||||||
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true);
|
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true)
|
||||||
expect(() => fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)).not.toThrow()
|
expect(() =>
|
||||||
}
|
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
||||||
}, 100000);
|
).not.toThrow()
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (IS_WINDOWS) {
|
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
}, 100000)
|
}, 100000)
|
||||||
|
|
||||||
it ('Acquires kustomize version 3.3.0 successfully', async () => {
|
it('Acquires kustomize version 3.2.1 successfully', async () => {
|
||||||
await installer.getKustomize('3.3.0');
|
await installer.getKustomize('3.2.1')
|
||||||
const kustomizeDir = path.join(toolDir, 'kustomize', '3.3.0', os.arch());
|
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) {
|
if (IS_WINDOWS) {
|
||||||
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true);
|
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true)
|
||||||
} else {
|
} else {
|
||||||
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true);
|
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true)
|
||||||
expect(() => fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)).not.toThrow()
|
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())
|
||||||
|
|
||||||
|
expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true)
|
||||||
|
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
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()
|
||||||
}
|
}
|
||||||
}, 100000)
|
}, 100000)
|
||||||
|
|
||||||
it('Throws if no location contains correct kustomize version', async () => {
|
it('Throws if no location contains correct kustomize version', async () => {
|
||||||
let thrown = false;
|
let thrown = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await installer.getKustomize('1000');
|
await installer.getKustomize('1000')
|
||||||
} catch {
|
} catch {
|
||||||
thrown = true;
|
thrown = true
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(thrown).toBe(true);
|
expect(thrown).toBe(true)
|
||||||
});
|
})
|
||||||
|
|
||||||
it('Uses version of kustomize installed in cache', async () => {
|
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 () => {
|
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.0')
|
||||||
await installer.getKustomize('3.0');
|
await installer.getKustomize('3.0')
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|||||||
38
dist/index.js
vendored
38
dist/index.js
vendored
@@ -2516,7 +2516,7 @@ function run() {
|
|||||||
// Version is optional. If supplied, install / use from the tool cache
|
// Version is optional. If supplied, install / use from the tool cache
|
||||||
// If not supplied then task is still used to setup proxy, auth, etc...
|
// 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) {
|
if (version) {
|
||||||
yield installer.getKustomize(version);
|
yield installer.getKustomize(version);
|
||||||
}
|
}
|
||||||
@@ -6814,7 +6814,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
// Load tempDirectory before it gets wiped by tool-cache
|
// Load tempDirectory before it gets wiped by tool-cache
|
||||||
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const tc = __importStar(__webpack_require__(533));
|
const tc = __importStar(__webpack_require__(533));
|
||||||
const restm = __importStar(__webpack_require__(105));
|
const restm = __importStar(__webpack_require__(105));
|
||||||
@@ -6822,8 +6821,9 @@ const os = __importStar(__webpack_require__(87));
|
|||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const semver = __importStar(__webpack_require__(876));
|
const semver = __importStar(__webpack_require__(876));
|
||||||
const fs = __importStar(__webpack_require__(747));
|
const fs = __importStar(__webpack_require__(747));
|
||||||
let osPlat = os.platform();
|
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
||||||
let osArch = os.arch();
|
const osPlat = os.platform();
|
||||||
|
const osArch = os.arch();
|
||||||
if (!tempDirectory) {
|
if (!tempDirectory) {
|
||||||
let baseLocation;
|
let baseLocation;
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
@@ -6891,18 +6891,18 @@ function queryLatestMatch(versionSpec) {
|
|||||||
default:
|
default:
|
||||||
dataFileName = `${dataFileName}_${osArch}`;
|
dataFileName = `${dataFileName}_${osArch}`;
|
||||||
}
|
}
|
||||||
let versions = [];
|
const versions = [];
|
||||||
let dataUrl = 'https://api.github.com/repos/kubernetes-sigs/kustomize/releases';
|
const dataUrl = 'https://api.github.com/repos/kubernetes-sigs/kustomize/releases';
|
||||||
let rest = new restm.RestClient('setup-kustomize');
|
const rest = new restm.RestClient('setup-kustomize');
|
||||||
let kustomizeVersions = (yield rest.get(dataUrl)).result || [];
|
const kustomizeVersions = (yield rest.get(dataUrl)).result || [];
|
||||||
kustomizeVersions.forEach((kustomizeVersion) => {
|
for (const kustomizeVersion of kustomizeVersions) {
|
||||||
if (kustomizeVersion.assets.some(asset => asset.name.includes(dataFileName))) {
|
if (kustomizeVersion.assets.some(asset => asset.name.includes(dataFileName))) {
|
||||||
let version = semver.clean(kustomizeVersion.name);
|
const version = semver.clean(kustomizeVersion.name);
|
||||||
if (version != null) {
|
if (version != null) {
|
||||||
versions.push(version);
|
versions.push(version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return evaluateVersions(versions, versionSpec);
|
return evaluateVersions(versions, versionSpec);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -6936,15 +6936,15 @@ function acquireKustomize(version) {
|
|||||||
version = semver.clean(version) || '';
|
version = semver.clean(version) || '';
|
||||||
let downloadUrl;
|
let downloadUrl;
|
||||||
let toolPath;
|
let toolPath;
|
||||||
let toolFilename = "kustomize";
|
let toolFilename = 'kustomize';
|
||||||
let toolName = "kustomize";
|
const toolName = 'kustomize';
|
||||||
if (osPlat == "win32") {
|
if (osPlat === 'win32') {
|
||||||
toolFilename = `${toolFilename}.exe`;
|
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`;
|
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}`;
|
downloadUrl = `https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${version}/kustomize_kustomize.v${version}_%{os}_%{arch}`;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -6952,10 +6952,10 @@ function acquireKustomize(version) {
|
|||||||
}
|
}
|
||||||
switch (osPlat) {
|
switch (osPlat) {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
if (semver.lte(version, "3.2.1"))
|
if (semver.lte(version, '3.2.1'))
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`);
|
throw new Error(`Unexpected OS '${osPlat}'`);
|
||||||
downloadUrl = downloadUrl.replace('%{os}', 'windows');
|
downloadUrl = downloadUrl.replace('%{os}', 'windows');
|
||||||
if (semver.lt(version, "3.3.0"))
|
if (semver.lt(version, '3.3.0'))
|
||||||
downloadUrl = `${downloadUrl}.exe`;
|
downloadUrl = `${downloadUrl}.exe`;
|
||||||
break;
|
break;
|
||||||
case 'linux':
|
case 'linux':
|
||||||
@@ -6977,7 +6977,7 @@ function acquireKustomize(version) {
|
|||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
core.debug(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')) {
|
if (downloadUrl.endsWith('.tar.gz')) {
|
||||||
toolPath = yield tc.extractTar(toolPath);
|
toolPath = yield tc.extractTar(toolPath);
|
||||||
|
|||||||
175
src/installer.ts
175
src/installer.ts
@@ -1,197 +1,202 @@
|
|||||||
// Load tempDirectory before it gets wiped by tool-cache
|
// Load tempDirectory before it gets wiped by tool-cache
|
||||||
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
import * as core from '@actions/core'
|
||||||
import * as core from '@actions/core';
|
import * as tc from '@actions/tool-cache'
|
||||||
import * as tc from '@actions/tool-cache';
|
import * as restm from 'typed-rest-client/RestClient'
|
||||||
import * as restm from 'typed-rest-client/RestClient';
|
import * as os from 'os'
|
||||||
import * as os from 'os';
|
import * as path from 'path'
|
||||||
import * as path from 'path';
|
import * as semver from 'semver'
|
||||||
import * as semver from 'semver';
|
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
|
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''
|
||||||
|
|
||||||
let osPlat: string = os.platform();
|
const osPlat: string = os.platform()
|
||||||
let osArch: string = os.arch();
|
const osArch: string = os.arch()
|
||||||
|
|
||||||
if (!tempDirectory) {
|
if (!tempDirectory) {
|
||||||
let baseLocation;
|
let baseLocation
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
// On windows use the USERPROFILE env variable
|
// On windows use the USERPROFILE env variable
|
||||||
baseLocation = process.env['USERPROFILE'] || 'C:\\';
|
baseLocation = process.env['USERPROFILE'] || 'C:\\'
|
||||||
} else {
|
} else {
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
baseLocation = '/Users';
|
baseLocation = '/Users'
|
||||||
} else {
|
} else {
|
||||||
baseLocation = '/home';
|
baseLocation = '/home'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tempDirectory = path.join(baseLocation, 'actions', 'temp');
|
tempDirectory = path.join(baseLocation, 'actions', 'temp')
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getKustomize(versionSpec: string) {
|
export async function getKustomize(versionSpec: string): Promise<void> {
|
||||||
// check cache
|
// check cache
|
||||||
let toolPath: string;
|
let toolPath: string
|
||||||
|
|
||||||
toolPath = tc.find('kustomize', versionSpec);
|
toolPath = tc.find('kustomize', versionSpec)
|
||||||
|
|
||||||
// If not found in cache, download
|
// If not found in cache, download
|
||||||
if (!toolPath) {
|
if (!toolPath) {
|
||||||
let version: string;
|
let version: string
|
||||||
const c = semver.clean(versionSpec) || '';
|
const c = semver.clean(versionSpec) || ''
|
||||||
// If explicit version
|
// If explicit version
|
||||||
if (semver.valid(c) != null) {
|
if (semver.valid(c) != null) {
|
||||||
// version to download
|
// version to download
|
||||||
version = versionSpec;
|
version = versionSpec
|
||||||
} else {
|
} else {
|
||||||
// query kustomize for a matching version
|
// query kustomize for a matching version
|
||||||
version = await queryLatestMatch(versionSpec);
|
version = await queryLatestMatch(versionSpec)
|
||||||
if (!version) {
|
if (!version) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unable to find Kustomize version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
|
`Unable to find Kustomize version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check cache
|
// check cache
|
||||||
toolPath = tc.find('kustomize', version);
|
toolPath = tc.find('kustomize', version)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!toolPath) {
|
if (!toolPath) {
|
||||||
// download, extract, cache
|
// download, extract, cache
|
||||||
toolPath = await acquireKustomize(version);
|
toolPath = await acquireKustomize(version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
core.addPath(toolPath);
|
core.addPath(toolPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IAsset {
|
interface IAsset {
|
||||||
browser_download_url: string;
|
browser_download_url: string
|
||||||
name: string;
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IKustomizeVersion {
|
interface IKustomizeVersion {
|
||||||
name: string;
|
name: string
|
||||||
assets: IAsset[];
|
assets: IAsset[]
|
||||||
}
|
}
|
||||||
|
|
||||||
async function queryLatestMatch(versionSpec: string): Promise<string> {
|
async function queryLatestMatch(versionSpec: string): Promise<string> {
|
||||||
let dataFileName: string;
|
let dataFileName: string
|
||||||
|
|
||||||
switch (osPlat) {
|
switch (osPlat) {
|
||||||
case 'linux':
|
case 'linux':
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
case 'win32':
|
case 'win32':
|
||||||
dataFileName = osPlat;
|
dataFileName = osPlat
|
||||||
break;
|
break
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`);
|
throw new Error(`Unexpected OS '${osPlat}'`)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (osArch) {
|
switch (osArch) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
dataFileName = `${dataFileName}_amd64`;
|
dataFileName = `${dataFileName}_amd64`
|
||||||
break;
|
break
|
||||||
default:
|
default:
|
||||||
dataFileName = `${dataFileName}_${osArch}`;
|
dataFileName = `${dataFileName}_${osArch}`
|
||||||
}
|
}
|
||||||
|
|
||||||
let versions: string[] = [];
|
const versions: string[] = []
|
||||||
let dataUrl = 'https://api.github.com/repos/kubernetes-sigs/kustomize/releases';
|
const dataUrl =
|
||||||
let rest: restm.RestClient = new restm.RestClient('setup-kustomize');
|
'https://api.github.com/repos/kubernetes-sigs/kustomize/releases'
|
||||||
let kustomizeVersions: IKustomizeVersion[] = (await rest.get<IKustomizeVersion[]>(dataUrl)).result || [];
|
const rest: restm.RestClient = new restm.RestClient('setup-kustomize')
|
||||||
|
const kustomizeVersions: IKustomizeVersion[] =
|
||||||
|
(await rest.get<IKustomizeVersion[]>(dataUrl)).result || []
|
||||||
|
|
||||||
kustomizeVersions.forEach((kustomizeVersion: IKustomizeVersion) => {
|
for (const kustomizeVersion of kustomizeVersions) {
|
||||||
if (kustomizeVersion.assets.some(asset => asset.name.includes(dataFileName))) {
|
if (
|
||||||
let version = semver.clean(kustomizeVersion.name);
|
kustomizeVersion.assets.some(asset => asset.name.includes(dataFileName))
|
||||||
|
) {
|
||||||
|
const version = semver.clean(kustomizeVersion.name)
|
||||||
|
|
||||||
if (version != null) {
|
if (version != null) {
|
||||||
versions.push(version);
|
versions.push(version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return evaluateVersions(versions, versionSpec);
|
return evaluateVersions(versions, versionSpec)
|
||||||
}
|
}
|
||||||
|
|
||||||
function evaluateVersions(versions: string[], versionSpec: string): string {
|
function evaluateVersions(versions: string[], versionSpec: string): string {
|
||||||
let version = '';
|
let version = ''
|
||||||
|
|
||||||
core.debug(`evaluating ${versions.length} versions`);
|
core.debug(`evaluating ${versions.length} versions`)
|
||||||
|
|
||||||
versions = versions.sort((a, b) => {
|
versions = versions.sort((a, b) => {
|
||||||
if (semver.gt(a, b)) {
|
if (semver.gt(a, b)) {
|
||||||
return 1;
|
return 1
|
||||||
}
|
}
|
||||||
return -1;
|
return -1
|
||||||
});
|
})
|
||||||
|
|
||||||
for (let i = versions.length - 1; i >= 0; i--) {
|
for (let i = versions.length - 1; i >= 0; i--) {
|
||||||
const potential: string = versions[i];
|
const potential: string = versions[i]
|
||||||
const satisfied: boolean = semver.satisfies(potential, versionSpec);
|
const satisfied: boolean = semver.satisfies(potential, versionSpec)
|
||||||
if (satisfied) {
|
if (satisfied) {
|
||||||
version = potential;
|
version = potential
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version) {
|
if (version) {
|
||||||
core.debug(`matched: ${version}`);
|
core.debug(`matched: ${version}`)
|
||||||
} else {
|
} else {
|
||||||
core.debug('match not found');
|
core.debug('match not found')
|
||||||
}
|
}
|
||||||
|
|
||||||
return version;
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
async function acquireKustomize(version: string): Promise<string> {
|
async function acquireKustomize(version: string): Promise<string> {
|
||||||
version = semver.clean(version) || '';
|
version = semver.clean(version) || ''
|
||||||
|
|
||||||
let downloadUrl: string;
|
let downloadUrl: string
|
||||||
let toolPath: string;
|
let toolPath: string
|
||||||
let toolFilename = "kustomize";
|
let toolFilename = 'kustomize'
|
||||||
let toolName = "kustomize";
|
const toolName = 'kustomize'
|
||||||
|
|
||||||
if (osPlat == "win32") {
|
if (osPlat === 'win32') {
|
||||||
toolFilename = `${toolFilename}.exe`
|
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`;
|
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}`;
|
downloadUrl = `https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${version}/kustomize_kustomize.v${version}_%{os}_%{arch}`
|
||||||
} else {
|
} else {
|
||||||
downloadUrl = `https://github.com/kubernetes-sigs/kustomize/releases/download/v${version}/kustomize_${version}_%{os}_%{arch}`
|
downloadUrl = `https://github.com/kubernetes-sigs/kustomize/releases/download/v${version}/kustomize_${version}_%{os}_%{arch}`
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (osPlat) {
|
switch (osPlat) {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
if (semver.lte(version, "3.2.1")) throw new Error(`Unexpected OS '${osPlat}'`);
|
if (semver.lte(version, '3.2.1'))
|
||||||
downloadUrl = downloadUrl.replace('%{os}', 'windows');
|
throw new Error(`Unexpected OS '${osPlat}'`)
|
||||||
if (semver.lt(version, "3.3.0")) downloadUrl = `${downloadUrl}.exe`;
|
downloadUrl = downloadUrl.replace('%{os}', 'windows')
|
||||||
break;
|
if (semver.lt(version, '3.3.0')) downloadUrl = `${downloadUrl}.exe`
|
||||||
|
break
|
||||||
case 'linux':
|
case 'linux':
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
downloadUrl = downloadUrl.replace('%{os}', osPlat);
|
downloadUrl = downloadUrl.replace('%{os}', osPlat)
|
||||||
break;
|
break
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`);
|
throw new Error(`Unexpected OS '${osPlat}'`)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (osArch) {
|
switch (osArch) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
downloadUrl = downloadUrl.replace('%{arch}', 'amd64');
|
downloadUrl = downloadUrl.replace('%{arch}', 'amd64')
|
||||||
break;
|
break
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unexpected Arch '${osArch}'`);
|
throw new Error(`Unexpected Arch '${osArch}'`)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
toolPath = await tc.downloadTool(downloadUrl);
|
toolPath = await tc.downloadTool(downloadUrl)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.debug(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')) {
|
if (downloadUrl.endsWith('.tar.gz')) {
|
||||||
toolPath = await tc.extractTar(toolPath);
|
toolPath = await tc.extractTar(toolPath)
|
||||||
toolPath = path.join(toolPath, toolFilename)
|
toolPath = path.join(toolPath, toolFilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,8 +204,8 @@ async function acquireKustomize(version: string): Promise<string> {
|
|||||||
case 'linux':
|
case 'linux':
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
fs.chmodSync(toolPath, 0o755)
|
fs.chmodSync(toolPath, 0o755)
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
return await tc.cacheFile(toolPath, toolFilename, toolName, version);
|
return await tc.cacheFile(toolPath, toolFilename, toolName, version)
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/main.ts
14
src/main.ts
@@ -1,20 +1,20 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core'
|
||||||
import * as installer from './installer';
|
import * as installer from './installer'
|
||||||
|
|
||||||
async function run() {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
// Version is optional. If supplied, install / use from the tool cache
|
// Version is optional. If supplied, install / use from the tool cache
|
||||||
// If not supplied then task is still used to setup proxy, auth, etc...
|
// 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) {
|
if (version) {
|
||||||
await installer.getKustomize(version);
|
await installer.getKustomize(version)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run();
|
run()
|
||||||
|
|||||||
Reference in New Issue
Block a user