diff --git a/src/run.test.ts b/src/action.test.ts similarity index 97% rename from src/run.test.ts rename to src/action.test.ts index 91d62e84..456fc477 100644 --- a/src/run.test.ts +++ b/src/action.test.ts @@ -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' diff --git a/src/action.ts b/src/action.ts new file mode 100644 index 00000000..91342696 --- /dev/null +++ b/src/action.ts @@ -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) +} diff --git a/src/run.ts b/src/run.ts index 9bb23014..893a07ad 100644 --- a/src/run.ts +++ b/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)