feat: implement the action in typescript

This commit is contained in:
Aarnav Tale
2023-01-25 00:30:36 -05:00
parent 880d48e290
commit c368992ffb
6 changed files with 182 additions and 17 deletions

28
src/login.ts Normal file
View File

@@ -0,0 +1,28 @@
import { mkdir, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
import { env } from 'node:process'
import { debug, getInput, saveState, setFailed } from '@actions/core'
export async function setupKubeconfig() {
debug('Running kubectl-action setupKubeconfig()')
if (env.HOME === undefined) {
setFailed('$HOME is not defined')
return
}
const config = getInput('base64-kube-config', {
required: true,
trimWhitespace: true
})
const decoded = Buffer.from(config, 'base64')
.toString('utf8')
const path = join(env.HOME, '.kube')
saveState('kubeconfig-path', path)
await mkdir(path, { recursive: true })
await writeFile(join(path, 'config'), decoded, 'utf8')
}