diff --git a/src/main.ts b/src/main.ts index 27f00c4..442fc49 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,12 +1,19 @@ /* eslint-disable unicorn/prefer-top-level-await */ import { debug, getState, setFailed } from '@actions/core' +import { setupKubeconfig } from 'login' import { installKubectl } from 'setup' const post = Boolean(getState('isPost')) if (!post) { debug('Running kubectl-action setup') - installKubectl() + new Promise(async () => { + await installKubectl() + debug('kubectl-action setup complete') + + await setupKubeconfig() + debug('kubectl-action kubeconfig setup complete') + }) .catch(error => { setFailed('Failed to install kubectl (this is a bug in kubectl-action): ') debug(JSON.stringify(error)) diff --git a/src/setup.ts b/src/setup.ts index 3eaeb74..89e6629 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -22,6 +22,7 @@ export async function installKubectl() { }) const version = input === 'latest' ? await fetchLatestVersion() : input + debug(`kubectl-version: ${version ?? 'undefined'}`) if (!version?.startsWith('v')) { setFailed('Unable to determine the `kubectl` version to install') @@ -29,7 +30,6 @@ export async function installKubectl() { } console.log(`Installing kubectl version ${version}`) - const kubectl = await downloadKubectl(version) if (!kubectl) { @@ -72,9 +72,11 @@ async function downloadKubectl(version: string) { const hashUrl = `${url}.sha256` console.log(`Downloading kubectl (${url})`) + debug(`Downloading kubectl checksum (${hashUrl})`) const hashResponse = await fetch(hashUrl) if (!hashResponse.ok) { + debug(`Failed to download kubectl checksum with status ${hashResponse.status}`) warning(`Skipping checksum verification for kubectl ${version}`) } @@ -82,6 +84,7 @@ async function downloadKubectl(version: string) { const response = await fetch(url) if (!response.ok || !response.body) { + debug(`Failed to download kubectl with status ${response.status}`) setFailed(`Failed to download kubectl with status ${response.status}`) return } @@ -89,6 +92,7 @@ async function downloadKubectl(version: string) { const hashStream = createHash('sha256') const body = Readable.fromWeb(response.body) const size = Number(response.headers.get('content-length')) + debug(`Downloaded kubectl (${size} bytes)`) return new Promise((resolve, reject) => { let downloaded = 0 @@ -114,6 +118,7 @@ async function downloadKubectl(version: string) { const hashSum = hashStream.digest('hex') if (hashResponse.ok && hashSum !== hash) { + debug(`Checksum verification failed for kubectl ${version}`) setFailed(`Checksum verification failed for kubectl ${version}`) resolve() }