mirror of
https://github.com/imranismail/setup-kustomize.git
synced 2026-06-17 19:28:13 +00:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b67a0e7e1b | ||
|
|
60866b9f80 | ||
|
|
91ce0fb611 | ||
|
|
13cc3947ac | ||
|
|
548304dcdd | ||
|
|
366ebb426b | ||
|
|
0b4205889c | ||
|
|
509da12cc4 | ||
|
|
b7c602d150 | ||
|
|
d6406c9ed5 | ||
|
|
965f29eaf7 | ||
|
|
41e7f9975d | ||
|
|
45c217953c | ||
|
|
ae749a83d7 | ||
|
|
0c2f32dde2 | ||
|
|
59f3d52ca7 | ||
|
|
ff25099d8b | ||
|
|
359e84cbc9 |
42
CHANGELOG.MD
Normal file
42
CHANGELOG.MD
Normal file
@@ -0,0 +1,42 @@
|
||||
# Changelog
|
||||
|
||||
## v1.5.2
|
||||
|
||||
### Security
|
||||
|
||||
- Bump @actions/core to v1.2.6 to address deprecations raised in #30
|
||||
|
||||
## v1.5.1
|
||||
|
||||
### Changed
|
||||
|
||||
- Cache kustomize by requested version spec as key
|
||||
|
||||
## v1.5.0
|
||||
|
||||
### Changed
|
||||
|
||||
- Simplified asset look up
|
||||
|
||||
## v1.4.0
|
||||
|
||||
### Added
|
||||
|
||||
- Adds support for semver version ranges. Example: 3.x, 3.2.x
|
||||
- Add a step in the workflow to test the action with default value
|
||||
|
||||
## v1.2.0
|
||||
|
||||
N/A
|
||||
|
||||
## v1.1.0
|
||||
|
||||
### Fixed
|
||||
|
||||
- Support for new download path for kustomize
|
||||
|
||||
## v1.0.0
|
||||
|
||||
### Changed
|
||||
|
||||
- Update metadata
|
||||
@@ -1,4 +1,10 @@
|
||||
## TLDR
|
||||

|
||||
|
||||
## Description
|
||||
|
||||
Install any kustomize version as a step in your workflow
|
||||
|
||||
## Usage
|
||||
|
||||
```yaml
|
||||
on:
|
||||
|
||||
@@ -17,18 +17,24 @@ describe('installer tests', () => {
|
||||
beforeAll(async () => {
|
||||
await io.rmRF(toolDir)
|
||||
await io.rmRF(tempDir)
|
||||
}, 100000)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await io.rmRF(toolDir)
|
||||
await io.rmRF(tempDir)
|
||||
}, 100000)
|
||||
it('Acquires the max satisfying version range', async () => {
|
||||
await installer.getKustomize('~> 3.0')
|
||||
const kustomizeDir = path.join(toolDir, 'kustomize', '~> 3.0', os.arch())
|
||||
expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true)
|
||||
|
||||
it('Acquires the latest kustomize version 3.x successfully', () => {
|
||||
expect(async () => await installer.getKustomize('3.x')).not.toThrow()
|
||||
}, 100000)
|
||||
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()
|
||||
}
|
||||
})
|
||||
|
||||
it('Acquires kustomize version 3.2.0 successfully', async () => {
|
||||
it('Acquires kustomize version 3.2.0', async () => {
|
||||
await installer.getKustomize('3.2.0')
|
||||
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.0', os.arch())
|
||||
|
||||
@@ -42,9 +48,9 @@ describe('installer tests', () => {
|
||||
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
||||
).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')
|
||||
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.1', os.arch())
|
||||
|
||||
@@ -58,9 +64,9 @@ describe('installer tests', () => {
|
||||
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
||||
).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')
|
||||
const kustomizeDir = path.join(toolDir, 'kustomize', '3.3.0', os.arch())
|
||||
|
||||
@@ -74,7 +80,7 @@ describe('installer tests', () => {
|
||||
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
|
||||
|
||||
1778
dist/index.js
vendored
1778
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
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
|
||||
/******/ 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
|
||||
/******/ module.l = true;
|
||||
|
||||
@@ -4,8 +4,9 @@ module.exports = {
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
testTimeout: 60000,
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true
|
||||
}
|
||||
}
|
||||
|
||||
1222
package-lock.json
generated
1222
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
21
package.json
21
package.json
@@ -25,26 +25,27 @@
|
||||
"author": "Imran Ismail",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.4",
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/io": "^1.0.2",
|
||||
"@actions/tool-cache": "^1.3.3",
|
||||
"@octokit/plugin-retry": "^3.0.6",
|
||||
"@octokit/rest": "^18.0.6",
|
||||
"semver": "^7.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.5",
|
||||
"@types/node": "^14.0.23",
|
||||
"@types/jest": "^26.0.14",
|
||||
"@types/node": "^14.11.8",
|
||||
"@types/semver": "^7.3.4",
|
||||
"@typescript-eslint/parser": "^2.8.0",
|
||||
"@zeit/ncc": "^0.20.5",
|
||||
"eslint": "^7.5.0",
|
||||
"@typescript-eslint/parser": "^4.4.1",
|
||||
"@zeit/ncc": "^0.22.3",
|
||||
"eslint": "^7.10.0",
|
||||
"eslint-plugin-github": "^4.0.1",
|
||||
"eslint-plugin-jest": "^23.18.0",
|
||||
"eslint-plugin-jest": "^24.1.0",
|
||||
"jest": "^24.9.0",
|
||||
"jest-circus": "^26.1.0",
|
||||
"jest-circus": "^26.5.3",
|
||||
"js-yaml": "^3.13.1",
|
||||
"prettier": "^2.0.5",
|
||||
"prettier": "^2.1.2",
|
||||
"ts-jest": "^24.2.0",
|
||||
"typescript": "^3.9.4"
|
||||
"typescript": "^4.0.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Load tempDirectory before it gets wiped by tool-cache
|
||||
import {Octokit} from '@octokit/rest'
|
||||
import {retry} from '@octokit/plugin-retry'
|
||||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/tool-cache'
|
||||
import * as path from 'path'
|
||||
@@ -7,7 +8,8 @@ import * as semver from 'semver'
|
||||
import * as fs from 'fs'
|
||||
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''
|
||||
|
||||
const octokit = new Octokit()
|
||||
const RetriableOctokit = Octokit.plugin(retry)
|
||||
const octokit = new RetriableOctokit()
|
||||
const versionRegex = /\d+\.?\d*\.?\d*/
|
||||
const toolName = 'kustomize'
|
||||
const platform = process.platform
|
||||
@@ -28,26 +30,31 @@ if (!tempDirectory) {
|
||||
tempDirectory = path.join(baseLocation, 'actions', 'temp')
|
||||
}
|
||||
|
||||
export async function getKustomize(versionSpec: string): Promise<void> {
|
||||
let toolPath = cache.find('kustomize', versionSpec)
|
||||
export async function getKustomize(targetVersion: string): Promise<void> {
|
||||
if (!semver.validRange(targetVersion))
|
||||
throw new Error(`invalid semver requested: ${targetVersion}`)
|
||||
|
||||
if (!toolPath) {
|
||||
const version = await getMaxSatisfyingVersion(versionSpec)
|
||||
toolPath = await acquireVersion(version)
|
||||
let kustomizePath = cache.find('kustomize', targetVersion)
|
||||
|
||||
if (!kustomizePath) {
|
||||
const version = await getMaxSatisfyingVersion(targetVersion)
|
||||
kustomizePath = await acquireVersion(version)
|
||||
}
|
||||
|
||||
return core.addPath(toolPath)
|
||||
return core.addPath(kustomizePath)
|
||||
}
|
||||
|
||||
interface Version {
|
||||
name: string
|
||||
resolved: string
|
||||
target: string
|
||||
url: string
|
||||
}
|
||||
|
||||
async function getMaxSatisfyingVersion(versionSpec: string): Promise<Version> {
|
||||
const versionRange = semver.validRange(versionSpec)
|
||||
const downloadUrls: Map<string, string> = new Map()
|
||||
const versions: string[] = []
|
||||
async function getMaxSatisfyingVersion(
|
||||
targetVersion: string
|
||||
): Promise<Version> {
|
||||
const version = {target: targetVersion}
|
||||
const availableVersions: Map<string, string> = new Map()
|
||||
|
||||
for await (const response of octokit.paginate.iterator(
|
||||
octokit.repos.listReleases,
|
||||
@@ -65,27 +72,32 @@ async function getMaxSatisfyingVersion(versionSpec: string): Promise<Version> {
|
||||
)
|
||||
|
||||
if (matchingAsset) {
|
||||
const version = (versionRegex.exec(release.name) || []).shift()
|
||||
const kustomizeVersion = (versionRegex.exec(release.name) || []).shift()
|
||||
|
||||
if (version != null) {
|
||||
downloadUrls.set(version, matchingAsset.browser_download_url)
|
||||
versions.push(version)
|
||||
if (kustomizeVersion != null) {
|
||||
availableVersions.set(
|
||||
kustomizeVersion,
|
||||
matchingAsset.browser_download_url
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const versionToDownload = semver.maxSatisfying(versions, versionRange)
|
||||
const resolved = semver.maxSatisfying(
|
||||
[...availableVersions.keys()],
|
||||
version.target
|
||||
)
|
||||
|
||||
if (!versionToDownload) {
|
||||
if (!resolved) {
|
||||
throw new Error(
|
||||
`Unable to find Kustomize version '${versionSpec}' for platform '${platform}' and architecture ${arch}.`
|
||||
`Unable to find Kustomize version '${version.target}' for platform '${platform}' and architecture ${arch}.`
|
||||
)
|
||||
}
|
||||
|
||||
const downloadUrl = downloadUrls.get(versionToDownload) as string
|
||||
const url = availableVersions.get(resolved) as string
|
||||
|
||||
return {name: versionToDownload, url: downloadUrl}
|
||||
return {...version, resolved, url}
|
||||
}
|
||||
|
||||
async function acquireVersion(version: Version): Promise<string> {
|
||||
@@ -97,7 +109,7 @@ async function acquireVersion(version: Version): Promise<string> {
|
||||
toolPath = await cache.downloadTool(version.url)
|
||||
} catch (err) {
|
||||
core.debug(err)
|
||||
throw new Error(`Failed to download version ${version.name}: ${err}`)
|
||||
throw new Error(`Failed to download version ${version.target}: ${err}`)
|
||||
}
|
||||
|
||||
if (version.url.endsWith('.tar.gz')) {
|
||||
@@ -112,5 +124,5 @@ async function acquireVersion(version: Version): Promise<string> {
|
||||
break
|
||||
}
|
||||
|
||||
return await cache.cacheFile(toolPath, toolFilename, toolName, version.name)
|
||||
return await cache.cacheFile(toolPath, toolFilename, toolName, version.target)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user