add tool custom url
Some checks failed
Run unit tests. / build (push) Has been cancelled
Run prettify / Prettier Check (push) Has been cancelled
Integration test for setup-kubectl / Validate release and master branch (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled

This commit is contained in:
suisrc 2025-05-15 10:40:34 +08:00
parent a76651a0e0
commit 6563d5d80a
3 changed files with 12 additions and 4 deletions

View File

@ -5,6 +5,10 @@ inputs:
description: 'Version of kubectl' description: 'Version of kubectl'
required: true required: true
default: 'latest' default: 'latest'
url:
description: 'Url of kubectl'
required: false
default: ''
outputs: outputs:
kubectl-path: kubectl-path:
description: 'Path to the cached kubectl binary' description: 'Path to the cached kubectl binary'

View File

@ -9,7 +9,10 @@ export function getKubectlArch(): string {
return arch return arch
} }
export function getkubectlDownloadURL(version: string, arch: string): string { export function getkubectlDownloadURL(version: string, arch: string, url: string = ''): string {
if (url != '') {
return url.replace('${version}', version).replace('${arch}', arch)
}
switch (os.type()) { switch (os.type()) {
case 'Linux': case 'Linux':
return `https://dl.k8s.io/release/${version}/bin/linux/${arch}/kubectl` return `https://dl.k8s.io/release/${version}/bin/linux/${arch}/kubectl`

View File

@ -18,10 +18,11 @@ const stableVersionUrl =
export async function run() { export async function run() {
let version = core.getInput('version', {required: true}) let version = core.getInput('version', {required: true})
let toolurl = core.getInput('url', {required: false})
if (version.toLocaleLowerCase() === 'latest') { if (version.toLocaleLowerCase() === 'latest') {
version = await getStableKubectlVersion() version = await getStableKubectlVersion()
} }
const cachedPath = await downloadKubectl(version) const cachedPath = await downloadKubectl(version, toolurl)
core.addPath(path.dirname(cachedPath)) core.addPath(path.dirname(cachedPath))
@ -48,14 +49,14 @@ export async function getStableKubectlVersion(): Promise<string> {
) )
} }
export async function downloadKubectl(version: string): Promise<string> { export async function downloadKubectl(version: string, toolurl: string = ''): Promise<string> {
let cachedToolpath = toolCache.find(kubectlToolName, version) let cachedToolpath = toolCache.find(kubectlToolName, version)
let kubectlDownloadPath = '' let kubectlDownloadPath = ''
const arch = getKubectlArch() const arch = getKubectlArch()
if (!cachedToolpath) { if (!cachedToolpath) {
try { try {
kubectlDownloadPath = await toolCache.downloadTool( kubectlDownloadPath = await toolCache.downloadTool(
getkubectlDownloadURL(version, arch) getkubectlDownloadURL(version, arch, toolurl)
) )
} catch (exception) { } catch (exception) {
if ( if (