separate action and execution (#77)
This commit is contained in:
parent
ab43e1cba5
commit
3624a1fc64
@ -1,5 +1,5 @@
|
||||
import {getRequiredInputError} from '../tests/util'
|
||||
import {run} from './run'
|
||||
import {run} from './action'
|
||||
import fs from 'fs'
|
||||
import * as utils from './utils'
|
||||
|
33
src/action.ts
Normal file
33
src/action.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import {Cluster, parseCluster} from './types/cluster'
|
||||
import {setContext, getKubeconfig} from './utils'
|
||||
|
||||
/**
|
||||
* Sets the Kubernetes context based on supplied action inputs
|
||||
*/
|
||||
export async function run() {
|
||||
// get inputs
|
||||
const clusterType: Cluster | undefined = parseCluster(
|
||||
core.getInput('cluster-type', {
|
||||
required: true
|
||||
})
|
||||
)
|
||||
const runnerTempDirectory: string = process.env['RUNNER_TEMP']
|
||||
const kubeconfigPath: string = path.join(
|
||||
runnerTempDirectory,
|
||||
`kubeconfig_${Date.now()}`
|
||||
)
|
||||
|
||||
// get kubeconfig and update context
|
||||
const kubeconfig: string = await getKubeconfig(clusterType)
|
||||
const kubeconfigWithContext: string = setContext(kubeconfig)
|
||||
|
||||
// output kubeconfig
|
||||
core.debug(`Writing kubeconfig contents to ${kubeconfigPath}`)
|
||||
fs.writeFileSync(kubeconfigPath, kubeconfigWithContext)
|
||||
fs.chmodSync(kubeconfigPath, '600')
|
||||
core.debug('Setting KUBECONFIG environment variable')
|
||||
core.exportVariable('KUBECONFIG', kubeconfigPath)
|
||||
}
|
33
src/run.ts
33
src/run.ts
@ -1,36 +1,5 @@
|
||||
import {run} from './action'
|
||||
import * as core from '@actions/core'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import {Cluster, parseCluster} from './types/cluster'
|
||||
import {setContext, getKubeconfig} from './utils'
|
||||
|
||||
/**
|
||||
* Sets the Kubernetes context based on supplied action inputs
|
||||
*/
|
||||
export async function run() {
|
||||
// get inputs
|
||||
const clusterType: Cluster | undefined = parseCluster(
|
||||
core.getInput('cluster-type', {
|
||||
required: true
|
||||
})
|
||||
)
|
||||
const runnerTempDirectory: string = process.env['RUNNER_TEMP']
|
||||
const kubeconfigPath: string = path.join(
|
||||
runnerTempDirectory,
|
||||
`kubeconfig_${Date.now()}`
|
||||
)
|
||||
|
||||
// get kubeconfig and update context
|
||||
const kubeconfig: string = await getKubeconfig(clusterType)
|
||||
const kubeconfigWithContext: string = setContext(kubeconfig)
|
||||
|
||||
// output kubeconfig
|
||||
core.debug(`Writing kubeconfig contents to ${kubeconfigPath}`)
|
||||
fs.writeFileSync(kubeconfigPath, kubeconfigWithContext)
|
||||
fs.chmodSync(kubeconfigPath, '600')
|
||||
core.debug('Setting KUBECONFIG environment variable')
|
||||
core.exportVariable('KUBECONFIG', kubeconfigPath)
|
||||
}
|
||||
|
||||
// Run the application
|
||||
run().catch(core.setFailed)
|
||||
|
Loading…
x
Reference in New Issue
Block a user