feat: implement the action in typescript
This commit is contained in:
28
src/login.ts
Normal file
28
src/login.ts
Normal 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')
|
||||
}
|
||||
Reference in New Issue
Block a user