mirror of
https://github.com/imranismail/setup-kustomize.git
synced 2026-07-18 00:12:07 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13cc3947ac | ||
|
|
548304dcdd | ||
|
|
366ebb426b | ||
|
|
0b4205889c | ||
|
|
509da12cc4 | ||
|
|
b7c602d150 | ||
|
|
d6406c9ed5 | ||
|
|
965f29eaf7 | ||
|
|
41e7f9975d | ||
|
|
45c217953c | ||
|
|
ae749a83d7 | ||
|
|
0c2f32dde2 | ||
|
|
59f3d52ca7 | ||
|
|
ff25099d8b | ||
|
|
359e84cbc9 | ||
|
|
430fa071e8 | ||
|
|
b0afa08459 | ||
|
|
9503343f5a | ||
|
|
51957eba2f | ||
|
|
399ab9d4d6 |
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -3,7 +3,7 @@ on: # rebuild any PRs and main branch changes
|
|||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
- 'releases/*'
|
- 'releases/*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
## TLDR
|

|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Install any kustomize version as a step in your workflow
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ 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'
|
||||||
import * as semver from 'semver'
|
|
||||||
|
|
||||||
const IS_WINDOWS = os.platform() === 'win32'
|
const IS_WINDOWS = os.platform() === 'win32'
|
||||||
|
|
||||||
@@ -18,18 +17,24 @@ describe('installer tests', () => {
|
|||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await io.rmRF(toolDir)
|
await io.rmRF(toolDir)
|
||||||
await io.rmRF(tempDir)
|
await io.rmRF(tempDir)
|
||||||
}, 100000)
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it('Acquires the max satisfying version range', async () => {
|
||||||
await io.rmRF(toolDir)
|
await installer.getKustomize('~> 3.0')
|
||||||
await io.rmRF(tempDir)
|
const kustomizeDir = path.join(toolDir, 'kustomize', '~> 3.0', os.arch())
|
||||||
}, 100000)
|
expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true)
|
||||||
|
|
||||||
it('Acquires the latest kustomize version 3.x successfully', () => {
|
if (IS_WINDOWS) {
|
||||||
expect(async () => await installer.getKustomize('3.x')).not.toThrow()
|
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true)
|
||||||
}, 100000)
|
} else {
|
||||||
|
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true)
|
||||||
|
expect(() =>
|
||||||
|
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
||||||
|
).not.toThrow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it('Acquires kustomize version 3.2.0 successfully', async () => {
|
it('Acquires kustomize version 3.2.0', 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())
|
||||||
|
|
||||||
@@ -43,9 +48,9 @@ describe('installer tests', () => {
|
|||||||
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
||||||
).not.toThrow()
|
).not.toThrow()
|
||||||
}
|
}
|
||||||
}, 100000)
|
})
|
||||||
|
|
||||||
it('Acquires kustomize version 3.2.1 successfully', async () => {
|
it('Acquires kustomize version 3.2.1', async () => {
|
||||||
await installer.getKustomize('3.2.1')
|
await installer.getKustomize('3.2.1')
|
||||||
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.1', os.arch())
|
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.1', os.arch())
|
||||||
|
|
||||||
@@ -59,9 +64,9 @@ describe('installer tests', () => {
|
|||||||
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
||||||
).not.toThrow()
|
).not.toThrow()
|
||||||
}
|
}
|
||||||
}, 100000)
|
})
|
||||||
|
|
||||||
it('Acquires kustomize version 3.3.0 successfully', async () => {
|
it('Acquires kustomize version 3.3.0', async () => {
|
||||||
await installer.getKustomize('3.3.0')
|
await installer.getKustomize('3.3.0')
|
||||||
const kustomizeDir = path.join(toolDir, 'kustomize', '3.3.0', os.arch())
|
const kustomizeDir = path.join(toolDir, 'kustomize', '3.3.0', os.arch())
|
||||||
|
|
||||||
@@ -75,7 +80,7 @@ describe('installer tests', () => {
|
|||||||
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
||||||
).not.toThrow()
|
).not.toThrow()
|
||||||
}
|
}
|
||||||
}, 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
|
||||||
|
|||||||
255
dist/index.js
vendored
255
dist/index.js
vendored
@@ -19,7 +19,13 @@ require('./sourcemap-register.js');module.exports =
|
|||||||
/******/ };
|
/******/ };
|
||||||
/******/
|
/******/
|
||||||
/******/ // Execute the module function
|
/******/ // Execute the module function
|
||||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
/******/ var threw = true;
|
||||||
|
/******/ try {
|
||||||
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||||
|
/******/ threw = false;
|
||||||
|
/******/ } finally {
|
||||||
|
/******/ if(threw) delete installedModules[moduleId];
|
||||||
|
/******/ }
|
||||||
/******/
|
/******/
|
||||||
/******/ // Flag the module as loaded
|
/******/ // Flag the module as loaded
|
||||||
/******/ module.l = true;
|
/******/ module.l = true;
|
||||||
@@ -1041,9 +1047,9 @@ module.exports = require("tls");
|
|||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 18:
|
/***/ 18:
|
||||||
/***/ (function() {
|
/***/ (function(module) {
|
||||||
|
|
||||||
eval("require")("encoding");
|
module.exports = eval("require")("encoding");
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -1505,6 +1511,32 @@ class SemVer {
|
|||||||
module.exports = SemVer
|
module.exports = SemVer
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 82:
|
||||||
|
/***/ (function(__unusedmodule, exports) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// We use any as a valid input type
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
/**
|
||||||
|
* Sanitizes an input into a string so it can be passed into issueCommand safely
|
||||||
|
* @param input input to sanitize into a string
|
||||||
|
*/
|
||||||
|
function toCommandValue(input) {
|
||||||
|
if (input === null || input === undefined) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
else if (typeof input === 'string' || input instanceof String) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
return JSON.stringify(input);
|
||||||
|
}
|
||||||
|
exports.toCommandValue = toCommandValue;
|
||||||
|
//# sourceMappingURL=utils.js.map
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 87:
|
/***/ 87:
|
||||||
@@ -1514,6 +1546,42 @@ module.exports = require("os");
|
|||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 102:
|
||||||
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// For internal use, subject to change.
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||||
|
result["default"] = mod;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
// We use any as a valid input type
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
const fs = __importStar(__webpack_require__(747));
|
||||||
|
const os = __importStar(__webpack_require__(87));
|
||||||
|
const utils_1 = __webpack_require__(82);
|
||||||
|
function issueCommand(command, message) {
|
||||||
|
const filePath = process.env[`GITHUB_${command}`];
|
||||||
|
if (!filePath) {
|
||||||
|
throw new Error(`Unable to find environment variable for file command ${command}`);
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(filePath)) {
|
||||||
|
throw new Error(`Missing file at path: ${filePath}`);
|
||||||
|
}
|
||||||
|
fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
|
||||||
|
encoding: 'utf8'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.issueCommand = issueCommand;
|
||||||
|
//# sourceMappingURL=file-command.js.map
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
/***/ 120:
|
/***/ 120:
|
||||||
/***/ (function(module, __unusedexports, __webpack_require__) {
|
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||||
|
|
||||||
@@ -2552,7 +2620,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
if (mod && mod.__esModule) return mod;
|
if (mod && mod.__esModule) return mod;
|
||||||
var result = {};
|
var result = {};
|
||||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||||
__setModuleDefault(result, mod);
|
__setModuleDefault(result, mod);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -3267,6 +3335,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const os = __importStar(__webpack_require__(87));
|
const os = __importStar(__webpack_require__(87));
|
||||||
|
const utils_1 = __webpack_require__(82);
|
||||||
/**
|
/**
|
||||||
* Commands
|
* Commands
|
||||||
*
|
*
|
||||||
@@ -3320,28 +3389,14 @@ class Command {
|
|||||||
return cmdStr;
|
return cmdStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Sanitizes an input into a string so it can be passed into issueCommand safely
|
|
||||||
* @param input input to sanitize into a string
|
|
||||||
*/
|
|
||||||
function toCommandValue(input) {
|
|
||||||
if (input === null || input === undefined) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
else if (typeof input === 'string' || input instanceof String) {
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
return JSON.stringify(input);
|
|
||||||
}
|
|
||||||
exports.toCommandValue = toCommandValue;
|
|
||||||
function escapeData(s) {
|
function escapeData(s) {
|
||||||
return toCommandValue(s)
|
return utils_1.toCommandValue(s)
|
||||||
.replace(/%/g, '%25')
|
.replace(/%/g, '%25')
|
||||||
.replace(/\r/g, '%0D')
|
.replace(/\r/g, '%0D')
|
||||||
.replace(/\n/g, '%0A');
|
.replace(/\n/g, '%0A');
|
||||||
}
|
}
|
||||||
function escapeProperty(s) {
|
function escapeProperty(s) {
|
||||||
return toCommandValue(s)
|
return utils_1.toCommandValue(s)
|
||||||
.replace(/%/g, '%25')
|
.replace(/%/g, '%25')
|
||||||
.replace(/\r/g, '%0D')
|
.replace(/\r/g, '%0D')
|
||||||
.replace(/\n/g, '%0A')
|
.replace(/\n/g, '%0A')
|
||||||
@@ -5390,6 +5445,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const command_1 = __webpack_require__(431);
|
const command_1 = __webpack_require__(431);
|
||||||
|
const file_command_1 = __webpack_require__(102);
|
||||||
|
const utils_1 = __webpack_require__(82);
|
||||||
const os = __importStar(__webpack_require__(87));
|
const os = __importStar(__webpack_require__(87));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
/**
|
/**
|
||||||
@@ -5416,9 +5473,17 @@ var ExitCode;
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
function exportVariable(name, val) {
|
function exportVariable(name, val) {
|
||||||
const convertedVal = command_1.toCommandValue(val);
|
const convertedVal = utils_1.toCommandValue(val);
|
||||||
process.env[name] = convertedVal;
|
process.env[name] = convertedVal;
|
||||||
command_1.issueCommand('set-env', { name }, convertedVal);
|
const filePath = process.env['GITHUB_ENV'] || '';
|
||||||
|
if (filePath) {
|
||||||
|
const delimiter = '_GitHubActionsFileCommandDelimeter_';
|
||||||
|
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
|
||||||
|
file_command_1.issueCommand('ENV', commandValue);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
command_1.issueCommand('set-env', { name }, convertedVal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.exportVariable = exportVariable;
|
exports.exportVariable = exportVariable;
|
||||||
/**
|
/**
|
||||||
@@ -5434,7 +5499,13 @@ exports.setSecret = setSecret;
|
|||||||
* @param inputPath
|
* @param inputPath
|
||||||
*/
|
*/
|
||||||
function addPath(inputPath) {
|
function addPath(inputPath) {
|
||||||
command_1.issueCommand('add-path', {}, inputPath);
|
const filePath = process.env['GITHUB_PATH'] || '';
|
||||||
|
if (filePath) {
|
||||||
|
file_command_1.issueCommand('PATH', inputPath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
command_1.issueCommand('add-path', {}, inputPath);
|
||||||
|
}
|
||||||
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
|
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
|
||||||
}
|
}
|
||||||
exports.addPath = addPath;
|
exports.addPath = addPath;
|
||||||
@@ -9057,7 +9128,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
if (mod && mod.__esModule) return mod;
|
if (mod && mod.__esModule) return mod;
|
||||||
var result = {};
|
var result = {};
|
||||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||||
__setModuleDefault(result, mod);
|
__setModuleDefault(result, mod);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -9082,16 +9153,16 @@ exports.getKustomize = void 0;
|
|||||||
// Load tempDirectory before it gets wiped by tool-cache
|
// Load tempDirectory before it gets wiped by tool-cache
|
||||||
const rest_1 = __webpack_require__(889);
|
const rest_1 = __webpack_require__(889);
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const tc = __importStar(__webpack_require__(533));
|
const cache = __importStar(__webpack_require__(533));
|
||||||
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 tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
||||||
const osPlat = os.platform();
|
|
||||||
const osArch = os.arch();
|
|
||||||
const octokit = new rest_1.Octokit();
|
const octokit = new rest_1.Octokit();
|
||||||
const versionRegex = /\d+\.?\d*\.?\d*/;
|
const versionRegex = /\d+\.?\d*\.?\d*/;
|
||||||
|
const toolName = 'kustomize';
|
||||||
|
const platform = process.platform;
|
||||||
|
const arch = process.arch === 'x64' ? 'amd64' : process.arch;
|
||||||
if (!tempDirectory) {
|
if (!tempDirectory) {
|
||||||
let baseLocation;
|
let baseLocation;
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
@@ -9108,58 +9179,24 @@ if (!tempDirectory) {
|
|||||||
}
|
}
|
||||||
tempDirectory = path.join(baseLocation, 'actions', 'temp');
|
tempDirectory = path.join(baseLocation, 'actions', 'temp');
|
||||||
}
|
}
|
||||||
function getKustomize(versionSpec) {
|
function getKustomize(targetVersion) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// check cache
|
if (!semver.validRange(targetVersion))
|
||||||
let toolPath;
|
throw new Error(`invalid semver requested: ${targetVersion}`);
|
||||||
toolPath = tc.find('kustomize', versionSpec);
|
let kustomizePath = cache.find('kustomize', targetVersion);
|
||||||
// If not found in cache, download
|
if (!kustomizePath) {
|
||||||
if (!toolPath) {
|
const version = yield getMaxSatisfyingVersion(targetVersion);
|
||||||
let version;
|
kustomizePath = yield acquireVersion(version);
|
||||||
const c = semver.clean(versionSpec) || '';
|
|
||||||
// If explicit version
|
|
||||||
if (semver.valid(c) != null) {
|
|
||||||
// version to download
|
|
||||||
version = versionSpec;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// query kustomize for a matching version
|
|
||||||
const match = yield queryLatestMatch(versionSpec);
|
|
||||||
if (!match) {
|
|
||||||
throw new Error(`Unable to find Kustomize version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
|
|
||||||
}
|
|
||||||
version = match;
|
|
||||||
}
|
|
||||||
if (!toolPath) {
|
|
||||||
// download, extract, cache
|
|
||||||
toolPath = yield acquireKustomize(version);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
core.addPath(toolPath);
|
return core.addPath(kustomizePath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getKustomize = getKustomize;
|
exports.getKustomize = getKustomize;
|
||||||
function queryLatestMatch(versionSpec) {
|
function getMaxSatisfyingVersion(targetVersion) {
|
||||||
var e_1, _a;
|
var e_1, _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let dataFileName;
|
const version = { target: targetVersion };
|
||||||
switch (osPlat) {
|
const availableVersions = new Map();
|
||||||
case 'linux':
|
|
||||||
case 'darwin':
|
|
||||||
case 'win32':
|
|
||||||
dataFileName = osPlat;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`);
|
|
||||||
}
|
|
||||||
switch (osArch) {
|
|
||||||
case 'x64':
|
|
||||||
dataFileName = `${dataFileName}_amd64`;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dataFileName = `${dataFileName}_${osArch}`;
|
|
||||||
}
|
|
||||||
const versions = [];
|
|
||||||
try {
|
try {
|
||||||
for (var _b = __asyncValues(octokit.paginate.iterator(octokit.repos.listReleases, {
|
for (var _b = __asyncValues(octokit.paginate.iterator(octokit.repos.listReleases, {
|
||||||
owner: 'kubernetes-sigs',
|
owner: 'kubernetes-sigs',
|
||||||
@@ -9167,11 +9204,13 @@ function queryLatestMatch(versionSpec) {
|
|||||||
})), _c; _c = yield _b.next(), !_c.done;) {
|
})), _c; _c = yield _b.next(), !_c.done;) {
|
||||||
const response = _c.value;
|
const response = _c.value;
|
||||||
for (const release of response.data) {
|
for (const release of response.data) {
|
||||||
if (release.assets.some(asset => asset.name.includes(dataFileName) &&
|
const matchingAsset = release.assets.find(asset => asset.name.includes('kustomize') &&
|
||||||
asset.name.includes('kustomize'))) {
|
asset.name.includes(platform) &&
|
||||||
const version = (versionRegex.exec(release.name) || []).shift();
|
asset.name.includes(arch));
|
||||||
if (version != null) {
|
if (matchingAsset) {
|
||||||
versions.push(version);
|
const kustomizeVersion = (versionRegex.exec(release.name) || []).shift();
|
||||||
|
if (kustomizeVersion != null) {
|
||||||
|
availableVersions.set(kustomizeVersion, matchingAsset.browser_download_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9184,68 +9223,36 @@ function queryLatestMatch(versionSpec) {
|
|||||||
}
|
}
|
||||||
finally { if (e_1) throw e_1.error; }
|
finally { if (e_1) throw e_1.error; }
|
||||||
}
|
}
|
||||||
return semver.maxSatisfying(versions, versionSpec);
|
const resolved = semver.maxSatisfying([...availableVersions.keys()], version.target);
|
||||||
|
if (!resolved) {
|
||||||
|
throw new Error(`Unable to find Kustomize version '${version.target}' for platform '${platform}' and architecture ${arch}.`);
|
||||||
|
}
|
||||||
|
const url = availableVersions.get(resolved);
|
||||||
|
return Object.assign(Object.assign({}, version), { resolved, url });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function acquireKustomize(version) {
|
function acquireVersion(version) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
version = semver.clean(version) || '';
|
const toolFilename = process.platform === 'win32' ? `${toolName}.exe` : toolName;
|
||||||
let downloadUrl;
|
|
||||||
let toolPath;
|
let toolPath;
|
||||||
let toolFilename = 'kustomize';
|
|
||||||
const toolName = 'kustomize';
|
|
||||||
if (osPlat === 'win32') {
|
|
||||||
toolFilename = `${toolFilename}.exe`;
|
|
||||||
}
|
|
||||||
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')) {
|
|
||||||
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'))
|
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`);
|
|
||||||
downloadUrl = downloadUrl.replace('%{os}', 'windows');
|
|
||||||
if (semver.lt(version, '3.3.0'))
|
|
||||||
downloadUrl = `${downloadUrl}.exe`;
|
|
||||||
break;
|
|
||||||
case 'linux':
|
|
||||||
case 'darwin':
|
|
||||||
downloadUrl = downloadUrl.replace('%{os}', osPlat);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`);
|
|
||||||
}
|
|
||||||
switch (osArch) {
|
|
||||||
case 'x64':
|
|
||||||
downloadUrl = downloadUrl.replace('%{arch}', 'amd64');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected Arch '${osArch}'`);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
toolPath = yield tc.downloadTool(downloadUrl);
|
toolPath = yield cache.downloadTool(version.url);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
core.debug(err);
|
core.debug(err);
|
||||||
throw new Error(`Failed to download version ${version}: ${err}`);
|
throw new Error(`Failed to download version ${version.target}: ${err}`);
|
||||||
}
|
}
|
||||||
if (downloadUrl.endsWith('.tar.gz')) {
|
if (version.url.endsWith('.tar.gz')) {
|
||||||
toolPath = yield tc.extractTar(toolPath);
|
toolPath = yield cache.extractTar(toolPath);
|
||||||
toolPath = path.join(toolPath, toolFilename);
|
toolPath = path.join(toolPath, toolFilename);
|
||||||
}
|
}
|
||||||
switch (osPlat) {
|
switch (process.platform) {
|
||||||
case 'linux':
|
case 'linux':
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
fs.chmodSync(toolPath, 0o755);
|
fs.chmodSync(toolPath, 0o755);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return yield tc.cacheFile(toolPath, toolFilename, toolName, version);
|
return yield cache.cacheFile(toolPath, toolFilename, toolName, version.target);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
8
dist/sourcemap-register.js
vendored
8
dist/sourcemap-register.js
vendored
@@ -19,7 +19,13 @@ module.exports =
|
|||||||
/******/ };
|
/******/ };
|
||||||
/******/
|
/******/
|
||||||
/******/ // Execute the module function
|
/******/ // Execute the module function
|
||||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
/******/ var threw = true;
|
||||||
|
/******/ try {
|
||||||
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||||
|
/******/ threw = false;
|
||||||
|
/******/ } finally {
|
||||||
|
/******/ if(threw) delete installedModules[moduleId];
|
||||||
|
/******/ }
|
||||||
/******/
|
/******/
|
||||||
/******/ // Flag the module as loaded
|
/******/ // Flag the module as loaded
|
||||||
/******/ module.l = true;
|
/******/ module.l = true;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ module.exports = {
|
|||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
testMatch: ['**/*.test.ts'],
|
testMatch: ['**/*.test.ts'],
|
||||||
testRunner: 'jest-circus/runner',
|
testRunner: 'jest-circus/runner',
|
||||||
|
testTimeout: 60000,
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.ts$': 'ts-jest'
|
'^.+\\.ts$': 'ts-jest'
|
||||||
},
|
},
|
||||||
|
|||||||
1192
package-lock.json
generated
1192
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@@ -10,7 +10,7 @@
|
|||||||
"format-check": "prettier --check **/*.ts",
|
"format-check": "prettier --check **/*.ts",
|
||||||
"lint": "eslint src/**/*.ts",
|
"lint": "eslint src/**/*.ts",
|
||||||
"package": "ncc build --source-map",
|
"package": "ncc build --source-map",
|
||||||
"test": "jest",
|
"test": "jest -i",
|
||||||
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
|
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -25,26 +25,26 @@
|
|||||||
"author": "Imran Ismail",
|
"author": "Imran Ismail",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.4",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"@actions/tool-cache": "^1.3.3",
|
"@actions/tool-cache": "^1.3.3",
|
||||||
"@octokit/rest": "^18.0.6",
|
"@octokit/rest": "^18.0.6",
|
||||||
"semver": "^7.3.2"
|
"semver": "^7.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.5",
|
"@types/jest": "^26.0.14",
|
||||||
"@types/node": "^14.0.23",
|
"@types/node": "^14.11.8",
|
||||||
"@types/semver": "^7.3.4",
|
"@types/semver": "^7.3.4",
|
||||||
"@typescript-eslint/parser": "^2.8.0",
|
"@typescript-eslint/parser": "^4.4.1",
|
||||||
"@zeit/ncc": "^0.20.5",
|
"@zeit/ncc": "^0.22.3",
|
||||||
"eslint": "^7.5.0",
|
"eslint": "^7.10.0",
|
||||||
"eslint-plugin-github": "^4.0.1",
|
"eslint-plugin-github": "^4.0.1",
|
||||||
"eslint-plugin-jest": "^23.18.0",
|
"eslint-plugin-jest": "^24.1.0",
|
||||||
"jest": "^24.9.0",
|
"jest": "^24.9.0",
|
||||||
"jest-circus": "^26.1.0",
|
"jest-circus": "^26.5.3",
|
||||||
"js-yaml": "^3.13.1",
|
"js-yaml": "^3.13.1",
|
||||||
"prettier": "^2.0.5",
|
"prettier": "^2.1.2",
|
||||||
"ts-jest": "^24.2.0",
|
"ts-jest": "^24.2.0",
|
||||||
"typescript": "^3.9.4"
|
"typescript": "^4.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
172
src/installer.ts
172
src/installer.ts
@@ -1,17 +1,17 @@
|
|||||||
// Load tempDirectory before it gets wiped by tool-cache
|
// Load tempDirectory before it gets wiped by tool-cache
|
||||||
import {Octokit} from '@octokit/rest'
|
import {Octokit} from '@octokit/rest'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as tc from '@actions/tool-cache'
|
import * as cache from '@actions/tool-cache'
|
||||||
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 tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''
|
||||||
|
|
||||||
const osPlat: string = os.platform()
|
|
||||||
const osArch: string = os.arch()
|
|
||||||
const octokit = new Octokit()
|
const octokit = new Octokit()
|
||||||
const versionRegex = /\d+\.?\d*\.?\d*/
|
const versionRegex = /\d+\.?\d*\.?\d*/
|
||||||
|
const toolName = 'kustomize'
|
||||||
|
const platform = process.platform
|
||||||
|
const arch = process.arch === 'x64' ? 'amd64' : process.arch
|
||||||
|
|
||||||
if (!tempDirectory) {
|
if (!tempDirectory) {
|
||||||
let baseLocation
|
let baseLocation
|
||||||
@@ -28,64 +28,31 @@ if (!tempDirectory) {
|
|||||||
tempDirectory = path.join(baseLocation, 'actions', 'temp')
|
tempDirectory = path.join(baseLocation, 'actions', 'temp')
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getKustomize(versionSpec: string): Promise<void> {
|
export async function getKustomize(targetVersion: string): Promise<void> {
|
||||||
// check cache
|
if (!semver.validRange(targetVersion))
|
||||||
let toolPath: string
|
throw new Error(`invalid semver requested: ${targetVersion}`)
|
||||||
|
|
||||||
toolPath = tc.find('kustomize', versionSpec)
|
let kustomizePath = cache.find('kustomize', targetVersion)
|
||||||
|
|
||||||
// If not found in cache, download
|
if (!kustomizePath) {
|
||||||
if (!toolPath) {
|
const version = await getMaxSatisfyingVersion(targetVersion)
|
||||||
let version: string
|
kustomizePath = await acquireVersion(version)
|
||||||
const c = semver.clean(versionSpec) || ''
|
|
||||||
// If explicit version
|
|
||||||
if (semver.valid(c) != null) {
|
|
||||||
// version to download
|
|
||||||
version = versionSpec
|
|
||||||
} else {
|
|
||||||
// query kustomize for a matching version
|
|
||||||
const match = await queryLatestMatch(versionSpec)
|
|
||||||
|
|
||||||
if (!match) {
|
|
||||||
throw new Error(
|
|
||||||
`Unable to find Kustomize version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
version = match
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!toolPath) {
|
|
||||||
// download, extract, cache
|
|
||||||
toolPath = await acquireKustomize(version)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core.addPath(toolPath)
|
return core.addPath(kustomizePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function queryLatestMatch(versionSpec: string): Promise<string | null> {
|
interface Version {
|
||||||
let dataFileName: string
|
resolved: string
|
||||||
|
target: string
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
|
||||||
switch (osPlat) {
|
async function getMaxSatisfyingVersion(
|
||||||
case 'linux':
|
targetVersion: string
|
||||||
case 'darwin':
|
): Promise<Version> {
|
||||||
case 'win32':
|
const version = {target: targetVersion}
|
||||||
dataFileName = osPlat
|
const availableVersions: Map<string, string> = new Map()
|
||||||
break
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (osArch) {
|
|
||||||
case 'x64':
|
|
||||||
dataFileName = `${dataFileName}_amd64`
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
dataFileName = `${dataFileName}_${osArch}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const versions: string[] = []
|
|
||||||
|
|
||||||
for await (const response of octokit.paginate.iterator(
|
for await (const response of octokit.paginate.iterator(
|
||||||
octokit.repos.listReleases,
|
octokit.repos.listReleases,
|
||||||
@@ -95,86 +62,65 @@ async function queryLatestMatch(versionSpec: string): Promise<string | null> {
|
|||||||
}
|
}
|
||||||
)) {
|
)) {
|
||||||
for (const release of response.data) {
|
for (const release of response.data) {
|
||||||
if (
|
const matchingAsset = release.assets.find(
|
||||||
release.assets.some(
|
asset =>
|
||||||
asset =>
|
asset.name.includes('kustomize') &&
|
||||||
asset.name.includes(dataFileName) &&
|
asset.name.includes(platform) &&
|
||||||
asset.name.includes('kustomize')
|
asset.name.includes(arch)
|
||||||
)
|
)
|
||||||
) {
|
|
||||||
const version = (versionRegex.exec(release.name) || []).shift()
|
|
||||||
|
|
||||||
if (version != null) {
|
if (matchingAsset) {
|
||||||
versions.push(version)
|
const kustomizeVersion = (versionRegex.exec(release.name) || []).shift()
|
||||||
|
|
||||||
|
if (kustomizeVersion != null) {
|
||||||
|
availableVersions.set(
|
||||||
|
kustomizeVersion,
|
||||||
|
matchingAsset.browser_download_url
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return semver.maxSatisfying(versions, versionSpec)
|
const resolved = semver.maxSatisfying(
|
||||||
|
[...availableVersions.keys()],
|
||||||
|
version.target
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!resolved) {
|
||||||
|
throw new Error(
|
||||||
|
`Unable to find Kustomize version '${version.target}' for platform '${platform}' and architecture ${arch}.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = availableVersions.get(resolved) as string
|
||||||
|
|
||||||
|
return {...version, resolved, url}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function acquireKustomize(version: string): Promise<string> {
|
async function acquireVersion(version: Version): Promise<string> {
|
||||||
version = semver.clean(version) || ''
|
const toolFilename =
|
||||||
|
process.platform === 'win32' ? `${toolName}.exe` : toolName
|
||||||
let downloadUrl: string
|
|
||||||
let toolPath: string
|
let toolPath: string
|
||||||
let toolFilename = 'kustomize'
|
|
||||||
const toolName = 'kustomize'
|
|
||||||
|
|
||||||
if (osPlat === 'win32') {
|
|
||||||
toolFilename = `${toolFilename}.exe`
|
|
||||||
}
|
|
||||||
|
|
||||||
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')) {
|
|
||||||
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'))
|
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`)
|
|
||||||
downloadUrl = downloadUrl.replace('%{os}', 'windows')
|
|
||||||
if (semver.lt(version, '3.3.0')) downloadUrl = `${downloadUrl}.exe`
|
|
||||||
break
|
|
||||||
case 'linux':
|
|
||||||
case 'darwin':
|
|
||||||
downloadUrl = downloadUrl.replace('%{os}', osPlat)
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (osArch) {
|
|
||||||
case 'x64':
|
|
||||||
downloadUrl = downloadUrl.replace('%{arch}', 'amd64')
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected Arch '${osArch}'`)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
toolPath = await tc.downloadTool(downloadUrl)
|
toolPath = await cache.downloadTool(version.url)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.debug(err)
|
core.debug(err)
|
||||||
throw new Error(`Failed to download version ${version}: ${err}`)
|
throw new Error(`Failed to download version ${version.target}: ${err}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadUrl.endsWith('.tar.gz')) {
|
if (version.url.endsWith('.tar.gz')) {
|
||||||
toolPath = await tc.extractTar(toolPath)
|
toolPath = await cache.extractTar(toolPath)
|
||||||
toolPath = path.join(toolPath, toolFilename)
|
toolPath = path.join(toolPath, toolFilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (osPlat) {
|
switch (process.platform) {
|
||||||
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 cache.cacheFile(toolPath, toolFilename, toolName, version.target)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user