* Bump the actions group across 1 directory with 3 updates Bumps the actions group with 3 updates in the / directory: [@actions/tool-cache](https://github.com/actions/toolkit/tree/HEAD/packages/tool-cache), [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) and [typescript](https://github.com/microsoft/TypeScript). Updates `@actions/tool-cache` from 2.0.1 to 2.0.2 - [Changelog](https://github.com/actions/toolkit/blob/main/packages/tool-cache/RELEASES.md) - [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/tool-cache) Updates `@types/node` from 22.10.2 to 22.10.10 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Updates `typescript` from 5.7.2 to 5.7.3 - [Release notes](https://github.com/microsoft/TypeScript/releases) - [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml) - [Commits](https://github.com/microsoft/TypeScript/compare/v5.7.2...v5.7.3) --- updated-dependencies: - dependency-name: "@actions/tool-cache" dependency-type: direct:production update-type: version-update:semver-patch dependency-group: actions - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: actions - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-patch dependency-group: actions ... Signed-off-by: dependabot[bot] <support@github.com> * new method * initial * moved execution to index to free up tests --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
92 lines
2.5 KiB
TypeScript
92 lines
2.5 KiB
TypeScript
import * as path from 'path'
|
|
import * as util from 'util'
|
|
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 async function run() {
|
|
let version = core.getInput('version', {required: true})
|
|
if (version.toLocaleLowerCase() === 'latest') {
|
|
version = await getStableKubectlVersion()
|
|
}
|
|
const cachedPath = await downloadKubectl(version)
|
|
|
|
core.addPath(path.dirname(cachedPath))
|
|
|
|
core.debug(
|
|
`Kubectl tool version: '${version}' has been cached at ${cachedPath}`
|
|
)
|
|
core.setOutput('kubectl-path', cachedPath)
|
|
}
|
|
|
|
export async function getStableKubectlVersion(): Promise<string> {
|
|
return toolCache.downloadTool(stableVersionUrl).then(
|
|
(downloadPath) => {
|
|
let version = fs.readFileSync(downloadPath, 'utf8').toString().trim()
|
|
if (!version) {
|
|
version = stableKubectlVersion
|
|
}
|
|
return version
|
|
},
|
|
(error) => {
|
|
core.debug(error)
|
|
core.warning('GetStableVersionFailed')
|
|
return stableKubectlVersion
|
|
}
|
|
)
|
|
}
|
|
|
|
export async function downloadKubectl(version: string): Promise<string> {
|
|
let cachedToolpath = toolCache.find(kubectlToolName, version)
|
|
let kubectlDownloadPath = ''
|
|
const arch = getKubectlArch()
|
|
if (!cachedToolpath) {
|
|
try {
|
|
kubectlDownloadPath = await toolCache.downloadTool(
|
|
getkubectlDownloadURL(version, arch)
|
|
)
|
|
} catch (exception) {
|
|
if (
|
|
exception instanceof toolCache.HTTPError &&
|
|
exception.httpStatusCode === 404
|
|
) {
|
|
throw new Error(
|
|
util.format(
|
|
"Kubectl '%s' for '%s' arch not found.",
|
|
version,
|
|
arch
|
|
)
|
|
)
|
|
} else {
|
|
throw new Error('DownloadKubectlFailed')
|
|
}
|
|
}
|
|
|
|
cachedToolpath = await toolCache.cacheFile(
|
|
kubectlDownloadPath,
|
|
kubectlToolName + getExecutableExtension(),
|
|
kubectlToolName,
|
|
version
|
|
)
|
|
}
|
|
|
|
const kubectlPath = path.join(
|
|
cachedToolpath,
|
|
kubectlToolName + getExecutableExtension()
|
|
)
|
|
fs.chmodSync(kubectlPath, '775')
|
|
return kubectlPath
|
|
}
|