Compare commits

..

10 Commits

Author SHA1 Message Date
Suneha Bose 787b48379f update pkg lock 2026-03-26 12:54:02 -07:00
Suneha Bose 16f33d5a55 update pkg lock 2026-03-26 12:42:14 -07:00
Suneha Bose 9d027c90e0 Merge branch 'main' of https://github.com/Azure/k8s-set-context into migrate-to-esm 2026-03-26 12:28:29 -07:00
dependabot[bot] eb220500b5 Bump picomatch (#228)
Bumps  and [picomatch](https://github.com/micromatch/picomatch). These dependencies needed to be updated together.

Updates `picomatch` from 2.3.1 to 2.3.2
- [Release notes](https://github.com/micromatch/picomatch/releases)
- [Changelog](https://github.com/micromatch/picomatch/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/picomatch/compare/2.3.1...2.3.2)

Updates `picomatch` from 4.0.2 to 4.0.4
- [Release notes](https://github.com/micromatch/picomatch/releases)
- [Changelog](https://github.com/micromatch/picomatch/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/picomatch/compare/2.3.1...2.3.2)

---
updated-dependencies:
- dependency-name: picomatch
  dependency-version: 2.3.2
  dependency-type: indirect
- dependency-name: picomatch
  dependency-version: 4.0.4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-26 12:33:37 +13:00
Suneha Bose 999ddc4def remove build.mjs and update build script 2026-03-25 14:00:31 -07:00
Suneha Bose fc3887264c Migrate to ESM, esbuild, vitest, and update actions/* to latest
- Update @actions/core to 3.x, @actions/exec to 3.x, @actions/io to 3.x
- Replace @vercel/ncc + babel with esbuild (build.mjs) targeting Node 20 ESM
- Replace jest/babel-jest/ts-jest with vitest and @vitest/coverage-v8
- Update tsconfig to NodeNext module resolution with strict mode
- Add explicit .js extensions to all relative imports (NodeNext requirement)
- Fix implicit any index signatures in parseCluster and parseMethod
- Migrate all test files from jest to vi.mock/vi.mocked APIs
- Fix ESM module spying limitations using vi.mock() at module level
- Fix env var test pollution in default.test.ts with afterEach cleanup
2026-03-25 10:54:37 -07:00
dependabot[bot] 55f8f705e4 Bump github/codeql-action in /.github/workflows in the actions group (#226)
Bumps the actions group in /.github/workflows with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 4.32.6 to 4.34.1
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/0d579ffd059c29b07949a3cce3983f0780820c98...38697555549f1db7851b81482ff19f1fa5c4fedc)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.34.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-24 17:33:59 +13:00
Marten Kreienbrock 2220ef0140 Update Node version from 20 to 24 (#222)
To mitigate warnings in Github regarding the EOL of node 20
2026-03-18 13:58:37 -07:00
dependabot[bot] 1b2b1d4a34 Bump undici from 6.23.0 to 6.24.0 (#223)
Bumps [undici](https://github.com/nodejs/undici) from 6.23.0 to 6.24.0.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](https://github.com/nodejs/undici/compare/v6.23.0...v6.24.0)

---
updated-dependencies:
- dependency-name: undici
  dependency-version: 6.24.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-14 22:43:48 +13:00
dependabot[bot] 7d5d1039d9 Bump the actions group in /.github/workflows with 2 updates (#221)
Bumps the actions group in /.github/workflows with 2 updates: [github/codeql-action](https://github.com/github/codeql-action) and [actions/setup-node](https://github.com/actions/setup-node).


Updates `github/codeql-action` from 4.32.4 to 4.32.6
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/89a39a4e59826350b863aa6b6252a07ad50cf83e...0d579ffd059c29b07949a3cce3983f0780820c98)

Updates `actions/setup-node` from 6.2.0 to 6.3.0
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/6044e13b5dc448c55e2357c09f80417699197238...53b83947a5a98c8d113130e565377fae1a50d02f)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.32.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: actions/setup-node
  dependency-version: 6.3.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-09 11:03:45 -07:00
26 changed files with 990 additions and 2050 deletions
+2 -2
View File
@@ -59,7 +59,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@89a39a4e59826350b863aa6b6252a07ad50cf83e # v3.29.5
uses: github/codeql-action/init@38697555549f1db7851b81482ff19f1fa5c4fedc # v3.29.5
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
@@ -86,6 +86,6 @@ jobs:
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@89a39a4e59826350b863aa6b6252a07ad50cf83e # v3.29.5
uses: github/codeql-action/analyze@38697555549f1db7851b81482ff19f1fa5c4fedc # v3.29.5
with:
category: '/language:${{matrix.language}}'
+1 -1
View File
@@ -13,7 +13,7 @@ jobs:
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: 'lts/*'
cache: 'npm'
-4
View File
@@ -107,7 +107,3 @@ provided by the bot. You will only need to do this once across all repos using o
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
### Local development
Use `npm run build` to bundle the action with esbuild (output is `lib/index.cjs`, referenced by `action.yml`) and `npm run test` to execute the Vitest suite, including an integration test that runs the built action.
+2 -2
View File
@@ -39,5 +39,5 @@ inputs:
branding:
color: 'blue'
runs:
using: 'node20'
main: 'lib/index.cjs'
using: 'node24'
main: 'lib/index.js'
+874 -1839
View File
File diff suppressed because it is too large Load Diff
+8 -8
View File
@@ -2,10 +2,11 @@
"name": "k8s-set-context-action",
"version": "4.0.2",
"private": true,
"main": "lib/index.cjs",
"main": "lib/index.js",
"type": "module",
"scripts": {
"build": "tsc --noEmit && node ./scripts/build.mjs",
"build": "tsc --noEmit && esbuild src/run.ts --bundle --platform=node --target=node20 --format=esm --outfile=lib/index.js --banner:js=\"import { createRequire } from 'module';const require = createRequire(import.meta.url);\"",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"test-coverage": "vitest run --coverage",
"format": "prettier --write .",
@@ -20,9 +21,9 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/core": "^2.0.2",
"@actions/exec": "^2.0.0",
"@actions/io": "^2.0.0",
"@actions/core": "^3.0.0",
"@actions/exec": "^3.0.0",
"@actions/io": "^3.0.2",
"@kubernetes/client-node": "^1.4.0",
"husky": "^9.1.7",
"js-yaml": "^4.1.1"
@@ -30,10 +31,9 @@
"devDependencies": {
"@types/js-yaml": "^4.0.9",
"@types/node": "^25.0.9",
"@vitest/coverage-v8": "^2.0.4",
"esbuild": "^0.24.0",
"esbuild": "^0.27.4",
"prettier": "^3.8.0",
"typescript": "^5.9.3",
"vitest": "^2.0.4"
"vitest": "^4.1.1"
}
}
-26
View File
@@ -1,26 +0,0 @@
#!/usr/bin/env node
import {build} from 'esbuild'
import {mkdir} from 'fs/promises'
import {dirname} from 'path'
const outFile = 'lib/index.cjs'
const main = async () => {
await mkdir(dirname(outFile), {recursive: true})
await build({
entryPoints: ['src/run.ts'],
bundle: true,
platform: 'node',
target: 'node20',
format: 'cjs',
sourcemap: true,
outfile: outFile,
legalComments: 'none'
})
}
main().catch((err) => {
console.error(err)
process.exit(1)
})
+18 -41
View File
@@ -1,56 +1,33 @@
import {getRequiredInputError} from '../tests/util'
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'
import {run} from './action'
import * as fs from 'fs'
import * as path from 'path'
import os from 'os'
import * as utils from './utils'
import * as core from '@actions/core'
import {vi, describe, it, expect} from 'vitest'
import {getRequiredInputError} from '../tests/util.js'
import {run} from './action.js'
vi.mock('fs')
vi.mock('./utils.js')
describe('Run', () => {
const initialEnv = {...process.env}
const tempDirs: string[] = []
beforeEach(() => {
vi.restoreAllMocks()
process.env = {...initialEnv}
vi.spyOn(core, 'warning').mockImplementation(() => {})
vi.spyOn(core, 'debug').mockImplementation(() => {})
})
afterEach(() => {
tempDirs.forEach((dir) => {
try {
fs.rmSync(dir, {recursive: true, force: true})
} catch {}
})
tempDirs.length = 0
})
it('throws error without cluster type', async () => {
await expect(run()).rejects.toThrow(getRequiredInputError('cluster-type'))
})
it('writes kubeconfig and sets context', async () => {
const {getKubeconfig, setContext} = await import('./utils.js')
const fs = await import('fs')
const kubeconfig = 'kubeconfig'
const fixedTimestamp = 42
process.env['INPUT_CLUSTER-TYPE'] = 'default'
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kubeconfig-test-'))
tempDirs.push(tmpDir)
process.env['RUNNER_TEMP'] = tmpDir
process.env['RUNNER_TEMP'] = '/sample/path'
vi.spyOn(Date, 'now').mockReturnValue(fixedTimestamp)
vi.spyOn(utils, 'getKubeconfig').mockResolvedValue(kubeconfig)
vi.spyOn(utils, 'setContext').mockImplementation(() => kubeconfig)
vi.mocked(getKubeconfig).mockResolvedValue(kubeconfig)
vi.mocked(setContext).mockReturnValue(kubeconfig)
vi.mocked(fs.writeFileSync).mockImplementation(() => {})
vi.mocked(fs.chmodSync).mockImplementation(() => {})
await expect(run()).resolves.toBeUndefined()
await run()
const outputPath = path.join(tmpDir, `kubeconfig_${fixedTimestamp}`)
expect(fs.existsSync(outputPath)).toBe(true)
expect(fs.readFileSync(outputPath, 'utf-8')).toBe(kubeconfig)
expect(process.env['KUBECONFIG']).toBe(outputPath)
expect(utils.getKubeconfig).toHaveBeenCalled()
expect(utils.setContext).toHaveBeenCalledWith(kubeconfig)
expect(getKubeconfig).toHaveBeenCalled()
expect(fs.writeFileSync).toHaveBeenCalled()
expect(fs.chmodSync).toHaveBeenCalled()
expect(setContext).toHaveBeenCalled()
})
})
+3 -3
View File
@@ -1,8 +1,8 @@
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'
import {Cluster, parseCluster} from './types/cluster.js'
import {setContext, getKubeconfig} from './utils.js'
/**
* Sets the Kubernetes context based on supplied action inputs
@@ -14,7 +14,7 @@ export async function run() {
required: true
})
)
const runnerTempDirectory: string = process.env['RUNNER_TEMP']
const runnerTempDirectory: string = process.env['RUNNER_TEMP'] ?? ''
const kubeconfigPath: string = path.join(
runnerTempDirectory,
`kubeconfig_${Date.now()}`
+10 -15
View File
@@ -1,18 +1,13 @@
import {beforeEach, describe, expect, it, test, vi} from 'vitest'
import * as core from '@actions/core'
import * as actions from '@actions/exec'
import {vi, describe, test, it, expect, beforeEach} from 'vitest'
import * as io from '@actions/io'
import {getRequiredInputError} from '../../tests/util'
import {getArcKubeconfig, KUBECONFIG_LOCATION} from './arc'
import * as az from './azCommands'
import {getRequiredInputError} from '../../tests/util.js'
import {getArcKubeconfig, KUBECONFIG_LOCATION} from './arc.js'
import * as az from './azCommands.js'
vi.mock('@actions/io')
vi.mock('./azCommands.js')
describe('Arc kubeconfig', () => {
beforeEach(() => {
vi.restoreAllMocks()
vi.spyOn(core, 'warning').mockImplementation(() => {})
vi.spyOn(core, 'debug').mockImplementation(() => {})
})
test('it throws error without resource group', async () => {
await expect(getArcKubeconfig()).rejects.toThrow(
getRequiredInputError('resource-group')
@@ -36,9 +31,9 @@ describe('Arc kubeconfig', () => {
process.env['INPUT_RESOURCE-GROUP'] = group
process.env['INPUT_CLUSTER-NAME'] = name
vi.spyOn(io, 'which').mockResolvedValue(path)
vi.spyOn(az, 'runAzCliCommand').mockResolvedValue()
vi.spyOn(az, 'runAzKubeconfigCommandBlocking').mockResolvedValue(
vi.mocked(io.which).mockResolvedValue(path)
vi.mocked(az.runAzCliCommand).mockResolvedValue(undefined)
vi.mocked(az.runAzKubeconfigCommandBlocking).mockResolvedValue(
kubeconfig
)
})
+2 -2
View File
@@ -1,8 +1,8 @@
import * as core from '@actions/core'
import * as io from '@actions/io'
import {Method, parseMethod} from '../types/method'
import {Method, parseMethod} from '../types/method.js'
import * as path from 'path'
import {runAzCliCommand, runAzKubeconfigCommandBlocking} from './azCommands'
import {runAzCliCommand, runAzKubeconfigCommandBlocking} from './azCommands.js'
const RUNNER_TEMP: string = process.env['RUNNER_TEMP'] || ''
export const KUBECONFIG_LOCATION: string = path.join(
+6 -6
View File
@@ -1,17 +1,17 @@
import {describe, expect, test, vi} from 'vitest'
import * as core from '@actions/core'
import {vi, describe, test, expect, beforeEach} from 'vitest'
import * as actions from '@actions/exec'
import {runAzCliCommand} from './azCommands'
import {runAzCliCommand} from './azCommands.js'
vi.mock('@actions/exec')
describe('Az commands', () => {
test('it runs an az cli command', async () => {
vi.spyOn(core, 'debug').mockImplementation(() => {})
const path = 'path'
const args = ['args']
vi.spyOn(actions, 'exec').mockResolvedValue(0)
vi.mocked(actions.exec).mockResolvedValue(0)
expect(await runAzCliCommand(path, args))
await runAzCliCommand(path, args)
expect(actions.exec).toHaveBeenCalledWith(path, args, {})
})
})
+1 -2
View File
@@ -1,6 +1,5 @@
import * as fs from 'fs'
import {ExecOptions} from '@actions/exec/lib/interfaces'
import {exec} from '@actions/exec'
import {ExecOptions, exec} from '@actions/exec'
import {spawn} from 'child_process'
const AZ_TIMEOUT_SECONDS: number = 120
+15 -37
View File
@@ -1,22 +1,9 @@
import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest'
import {vi, describe, test, expect, beforeEach, afterEach} from 'vitest'
import * as fs from 'fs'
import * as core from '@actions/core'
import {getRequiredInputError} from '../../tests/util'
import {createKubeconfig, getDefaultKubeconfig} from './default'
import {getRequiredInputError} from '../../tests/util.js'
import {createKubeconfig, getDefaultKubeconfig} from './default.js'
describe('Default kubeconfig', () => {
const originalEnv = {...process.env}
beforeEach(() => {
vi.restoreAllMocks()
vi.spyOn(core, 'warning').mockImplementation(() => {})
vi.spyOn(core, 'debug').mockImplementation(() => {})
})
afterEach(() => {
process.env = {...originalEnv}
})
test('it creates a kubeconfig with proper format', () => {
const certAuth = 'certAuth'
const token = 'token'
@@ -64,6 +51,11 @@ describe('Default kubeconfig', () => {
process.env['INPUT_METHOD'] = 'default'
})
afterEach(() => {
delete process.env['INPUT_KUBECONFIG']
delete process.env['INPUT_KUBECONFIG-ENCODING']
})
test('it throws error without kubeconfig', () => {
expect(() => getDefaultKubeconfig()).toThrow(
getRequiredInputError('kubeconfig')
@@ -79,39 +71,25 @@ describe('Default kubeconfig', () => {
test('returns kubeconfig as plaintext when encoding is plaintext', () => {
const kc = 'example kc'
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
if (name === 'method') return 'default'
if (name === 'kubeconfig-encoding') return 'plaintext'
if (name === 'kubeconfig') return kc
return ''
})
process.env['INPUT_KUBECONFIG'] = kc
process.env['INPUT_KUBECONFIG-ENCODING'] = 'plaintext'
expect(getDefaultKubeconfig()).toBe(kc)
})
test('it gets default config through base64 kubeconfig input', () => {
const kc = 'example kc'
const base64Kc = Buffer.from(kc, 'utf-8').toString('base64')
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
if (name === 'method') return 'default'
if (name === 'kubeconfig-encoding') return 'base64'
if (name === 'kubeconfig') return base64Kc
return ''
})
process.env['INPUT_KUBECONFIG'] = base64Kc
process.env['INPUT_KUBECONFIG-ENCODING'] = 'base64'
expect(getDefaultKubeconfig()).toBe(kc)
})
test('it throws error for unknown kubeconfig-encoding', () => {
const kc = 'example kc'
const unknownEncoding = 'foobar'
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
if (name === 'method') return 'default'
if (name === 'kubeconfig-encoding') return unknownEncoding
if (name === 'kubeconfig') return kc
return ''
})
process.env['INPUT_KUBECONFIG'] = kc
process.env['INPUT_KUBECONFIG-ENCODING'] = 'foobar'
expect(() => getDefaultKubeconfig()).toThrow(
"Invalid kubeconfig-encoding: 'foobar'. Must be 'plaintext' or 'base64'."
+2 -2
View File
@@ -1,8 +1,8 @@
import * as core from '@actions/core'
import * as jsyaml from 'js-yaml'
import {KubeConfig} from '@kubernetes/client-node'
import {K8sSecret, parseK8sSecret} from '../types/k8sSecret'
import {Method, parseMethod} from '../types/method'
import {K8sSecret, parseK8sSecret} from '../types/k8sSecret.js'
import {Method, parseMethod} from '../types/method.js'
/**
* Gets the kubeconfig based on provided method for a default Kubernetes cluster
+1 -1
View File
@@ -1,4 +1,4 @@
import {run} from './action'
import {run} from './action.js'
import * as core from '@actions/core'
// Run the application
+3 -3
View File
@@ -1,9 +1,9 @@
import {describe, expect, test} from 'vitest'
import {Cluster, parseCluster} from './cluster'
import {describe, test, expect} from 'vitest'
import {Cluster, parseCluster} from './cluster.js'
describe('Cluster type', () => {
test('it has required values', () => {
const vals = <any>Object.values(Cluster)
const vals = Object.values(Cluster) as string[]
expect(vals.includes('arc')).toBe(true)
expect(vals.includes('generic')).toBe(true)
})
+7 -6
View File
@@ -8,9 +8,10 @@ export enum Cluster {
* @param str The cluster type (case insensitive)
* @returns The Cluster enum or undefined if it can't be parsed
*/
export const parseCluster = (str: string): Cluster | undefined =>
Cluster[
Object.keys(Cluster).filter(
(k) => Cluster[k].toString().toLowerCase() === str.toLowerCase()
)[0] as keyof typeof Cluster
]
export const parseCluster = (str: string): Cluster | undefined => {
const key = Object.keys(Cluster).find(
(k) =>
Cluster[k as keyof typeof Cluster].toLowerCase() === str.toLowerCase()
) as keyof typeof Cluster | undefined
return key !== undefined ? Cluster[key] : undefined
}
+2 -2
View File
@@ -1,5 +1,5 @@
import {describe, expect, test} from 'vitest'
import {parseK8sSecret, K8sSecret} from './k8sSecret'
import {describe, test, expect} from 'vitest'
import {parseK8sSecret} from './k8sSecret.js'
describe('K8sSecret type', () => {
describe('Parsing from any', () => {
+3 -3
View File
@@ -1,9 +1,9 @@
import {describe, expect, test} from 'vitest'
import {Method, parseMethod} from './method'
import {describe, test, expect} from 'vitest'
import {Method, parseMethod} from './method.js'
describe('Method type', () => {
test('it has required values', () => {
const vals = <any>Object.values(Method)
const vals = Object.values(Method) as string[]
expect(vals.includes('kubeconfig')).toBe(true)
expect(vals.includes('service-account')).toBe(true)
expect(vals.includes('service-principal')).toBe(true)
+7 -6
View File
@@ -9,9 +9,10 @@ export enum Method {
* @param str The method (case insensitive)
* @returns The Method enum or undefined if it can't be parsed
*/
export const parseMethod = (str: string): Method | undefined =>
Method[
Object.keys(Method).filter(
(k) => Method[k].toString().toLowerCase() === str.toLowerCase()
)[0] as keyof typeof Method
]
export const parseMethod = (str: string): Method | undefined => {
const key = Object.keys(Method).find(
(k) =>
Method[k as keyof typeof Method].toLowerCase() === str.toLowerCase()
) as keyof typeof Method | undefined
return key !== undefined ? Method[key] : undefined
}
+8 -13
View File
@@ -1,22 +1,17 @@
import {beforeEach, describe, expect, test, vi} from 'vitest'
import {vi, describe, test, expect} from 'vitest'
import fs from 'fs'
import * as arc from './kubeconfigs/arc'
import * as def from './kubeconfigs/default'
import {Cluster} from './types/cluster'
import {getKubeconfig, setContext} from './utils'
import * as core from '@actions/core'
import * as arc from './kubeconfigs/arc.js'
import * as def from './kubeconfigs/default.js'
import {Cluster} from './types/cluster.js'
import {getKubeconfig, setContext} from './utils.js'
describe('Utils', () => {
beforeEach(() => {
vi.restoreAllMocks()
vi.spyOn(core, 'warning').mockImplementation(() => {})
vi.spyOn(core, 'debug').mockImplementation(() => {})
})
describe('get kubeconfig', () => {
test('it gets arc kubeconfig when type is arc', async () => {
const arcKubeconfig = 'arckubeconfig'
vi.spyOn(arc, 'getArcKubeconfig').mockResolvedValue(arcKubeconfig)
vi.spyOn(arc, 'getArcKubeconfig').mockImplementation(
async () => arcKubeconfig
)
expect(await getKubeconfig(Cluster.ARC)).toBe(arcKubeconfig)
})
+3 -3
View File
@@ -1,9 +1,9 @@
import * as core from '@actions/core'
import * as fs from 'fs'
import {KubeConfig} from '@kubernetes/client-node'
import {getDefaultKubeconfig} from './kubeconfigs/default'
import {getArcKubeconfig} from './kubeconfigs/arc'
import {Cluster} from './types/cluster'
import {getDefaultKubeconfig} from './kubeconfigs/default.js'
import {getArcKubeconfig} from './kubeconfigs/arc.js'
import {Cluster} from './types/cluster.js'
/**
* Gets the kubeconfig based on Kubernetes cluster type
+1 -1
View File
@@ -3,5 +3,5 @@
* @param inputName Name of input
* @returns Error with explanation message
*/
export const getRequiredInputError = (inputName: string): Error =>
export const getRequiredInputError = (inputName) =>
Error(`Input required and not supplied: ${inputName}`)
+9 -10
View File
@@ -1,15 +1,14 @@
{
"compilerOptions": {
"baseUrl": ".",
"module": "ESNext", // or "NodeNext" depending on your setup
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "ES2020",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "./src",
"outDir": "./lib",
"noImplicitAny": false,
"skipLibCheck": true,
"paths": {
"@actions/core": ["node_modules/@actions/core"],
"@kubernetes/client-node": ["node_modules/@kubernetes/client-node"]
}
"noEmit": true,
"types": ["node", "vitest/globals"]
},
"exclude": ["node_modules", "lib"]
"exclude": ["node_modules", "**/*.test.ts", "vitest.config.ts", "tests/"]
}
+2 -12
View File
@@ -2,19 +2,9 @@ import {defineConfig} from 'vitest/config'
export default defineConfig({
test: {
globals: true,
environment: 'node',
include: ['**/*.test.ts'],
restoreMocks: true,
clearMocks: true,
mockReset: true,
coverage: {
provider: 'v8',
thresholds: {
statements: 22,
branches: 0,
functions: 40,
lines: 22
}
}
clearMocks: true
}
})