6 Commits

Author SHA1 Message Date
Aarnav Tale
5aa0d1bacd chore: v1.2.0 2023-06-28 22:16:04 -04:00
Aarnav Tale
93d421ead9 feat: use github actions env for windows check for extra resiliency 2023-06-28 22:15:24 -04:00
Aarnav Tale
e49d06518c feat: support arch and darwin/linux properly 2023-06-28 22:14:43 -04:00
Aarnav Tale
69c8dc994c chore: add better failure message for version resolving failures on kubectl 2023-06-28 22:09:13 -04:00
Aarnav Tale
e70828b58c fix: typo in teardown error message 2023-06-28 22:07:52 -04:00
Aarnav Tale
d7c0fa7a71 chore: update packages 2023-06-28 22:06:56 -04:00
4 changed files with 1720 additions and 1228 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "kubectl-action", "name": "kubectl-action",
"version": "1.1.3", "version": "1.2.0",
"scripts": { "scripts": {
"dev": "ncc -smw --license licenses.txt build src/main.ts", "dev": "ncc -smw --license licenses.txt build src/main.ts",
"build": "ncc -sm --license licenses.txt build src/main.ts", "build": "ncc -sm --license licenses.txt build src/main.ts",
@@ -9,14 +9,14 @@
"dependencies": { "dependencies": {
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
"@actions/tool-cache": "^2.0.1", "@actions/tool-cache": "^2.0.1",
"undici": "^5.16.0" "undici": "^5.22.1"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^18.11.18", "@types/node": "^20.3.2",
"@vercel/ncc": "^0.36.0", "@vercel/ncc": "^0.36.1",
"eslint": "^8.32.0", "eslint": "^8.43.0",
"eslint-config-tale": "^1.0.15", "eslint-config-tale": "^1.0.16",
"np": "^7.6.3", "np": "^8.0.4",
"typescript": "^4.9.4" "typescript": "^5.1.6"
} }
} }

2907
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,11 @@
import { platform } from 'node:process' import { env, platform } from 'node:process'
import { debug, getState, setFailed } from '@actions/core' import { debug, getState, setFailed } from '@actions/core'
import { setupKubeconfig } from 'login' import { setupKubeconfig } from 'login'
import { installKubectl } from 'setup' import { installKubectl } from 'setup'
import { teardown } from 'teardown' import { teardown } from 'teardown'
if (platform === 'win32') { if (env.RUNNER_OS === 'Windows' || platform === 'win32') {
setFailed('kubectl-action does not support Windows') setFailed('kubectl-action does not support Windows')
} }
@@ -14,7 +14,7 @@ if (getState('kubectl-path')) {
teardown() teardown()
// eslint-disable-next-line unicorn/prefer-top-level-await // eslint-disable-next-line unicorn/prefer-top-level-await
.catch(error => { .catch(error => {
setFailed('Failed to install kubectl (this is a bug in kubectl-action): ') setFailed('Failed to teardown kubectl (this is a bug in kubectl-action): ')
debug(JSON.stringify(error)) debug(JSON.stringify(error))
}) })
} else { } else {

View File

@@ -36,7 +36,7 @@ export async function installKubectl() {
debug(`kubectl ${version} installed and cached at ${path}`) debug(`kubectl ${version} installed and cached at ${path}`)
} catch { } catch {
debug('Failed to download kubectl from dl.k8s.io') debug('Failed to download kubectl from dl.k8s.io')
setFailed('Failed to download kubectl from dl.k8s.io') setFailed('Failed to download kubectl from dl.k8s.io\nPlease check the version you specified is valid')
} }
} }
@@ -63,11 +63,24 @@ async function fetchKubectl(version: string) {
return join(cachedPath, 'kubectl') return join(cachedPath, 'kubectl')
} }
// TODO: Support other platforms const url = `https://dl.k8s.io/release/${version}/bin/${retrieveRunnerMetadata()}/kubectl`
const url = `https://dl.k8s.io/release/${version}/bin/linux/amd64/kubectl`
console.log(`Downloading kubectl (${url})`) console.log(`Downloading kubectl (${url})`)
const downloadPath = await downloadTool(url) const downloadPath = await downloadTool(url)
const toolPath = await cacheFile(downloadPath, 'kubectl', 'kubectl', version) const toolPath = await cacheFile(downloadPath, 'kubectl', 'kubectl', version)
return join(toolPath, 'kubectl') return join(toolPath, 'kubectl')
} }
// Gets the proper architecture and OS for the current platform
// This doesn't use node functions, but instead CI variables provided by GitHub
function retrieveRunnerMetadata() {
// Currently we don't support win32 platforms anyways
const runnerSystem = env.RUNNER_OS === 'Linux' ? 'linux' : 'darwin'
const runnerArch = env.RUNNER_ARCH?.toLowerCase()
if (runnerArch?.includes('arm')) {
return `${runnerSystem}/arm64`
}
return `${runnerSystem}/amd64`
}