David Gamero 01cfe404ef
Migrate to esbuild/Vitest and upgrade @actions/* to ESM-only versions (#492)
* Migrate build toolchain from ncc/Jest to esbuild/Vitest

Replace the legacy ncc/Jest/Babel build stack with a modern ESM toolchain:

Build:
- Replace @vercel/ncc with esbuild (--platform=node --target=node20 --format=esm)
- Add createRequire banner for CJS interop in ESM bundle
- Add "type": "module" to package.json
- Add tsc --noEmit typecheck script (esbuild strips types without checking)
- Add typecheck to husky pre-commit hook

Dependencies:
- Bump @actions/core@3, exec@3, io@3, tool-cache@4 (ESM-only)
- Replace jest/ts-jest/@babel/* with vitest@4

Tests:
- Convert 29 test files: jest.fn()→vi.fn(), jest.mock()→vi.mock(), jest.spyOn()→vi.spyOn()
- Fix vitest 4 compat: mockImplementation requires args, mock call tracking, await .rejects

CI:
- Update build step from ncc build → npm run build
- Update composite action to use npm run build

* Switch tsconfig to NodeNext module resolution

Change module/moduleResolution from ES2022/bundler to NodeNext/NodeNext
and target from ES2022 to ES2020.

- Add .js extensions to all relative imports across 59 source/test files
  (required by NodeNext module resolution)
- Add vitest/globals to tsconfig types array for global test API declarations
2026-02-24 11:57:56 -08:00

170 lines
4.8 KiB
TypeScript

import * as core from '@actions/core'
import {Kubectl} from '../../types/kubectl.js'
import {
BlueGreenDeployment,
BlueGreenManifests
} from '../../types/blueGreenTypes.js'
import {RouteStrategy} from '../../types/routeStrategy.js'
import {
deployWithLabel,
getManifestObjects,
GREEN_LABEL_VALUE,
deployObjects
} from './blueGreenHelper.js'
import {setupSMI} from './smiBlueGreenHelper.js'
import {routeBlueGreenForDeploy} from './route.js'
import {DeployResult} from '../../types/deployResult.js'
export async function deployBlueGreen(
kubectl: Kubectl,
files: string[],
routeStrategy: RouteStrategy,
timeout?: string
): Promise<BlueGreenDeployment> {
const blueGreenDeployment = await (async () => {
switch (routeStrategy) {
case RouteStrategy.INGRESS:
return await deployBlueGreenIngress(kubectl, files, timeout)
case RouteStrategy.SMI:
return await deployBlueGreenSMI(kubectl, files, timeout)
default:
return await deployBlueGreenService(kubectl, files, timeout)
}
})()
core.startGroup('Routing blue green')
const routeDeployment = await routeBlueGreenForDeploy(
kubectl,
files,
routeStrategy,
timeout
)
core.endGroup()
blueGreenDeployment.objects.push(...routeDeployment.objects)
blueGreenDeployment.deployResult.manifestFiles.push(
...routeDeployment.deployResult.manifestFiles
)
return blueGreenDeployment
}
export async function deployBlueGreenSMI(
kubectl: Kubectl,
filePaths: string[],
timeout?: string
): Promise<BlueGreenDeployment> {
// get all kubernetes objects defined in manifest files
const manifestObjects: BlueGreenManifests = getManifestObjects(filePaths)
// create services and other objects
const newObjectsList = [].concat(
manifestObjects.otherObjects,
manifestObjects.serviceEntityList,
manifestObjects.ingressEntityList,
manifestObjects.unroutedServiceEntityList
)
const otherObjDeployment: DeployResult = await deployObjects(
kubectl,
newObjectsList,
timeout
)
// make extraservices and trafficsplit
const smiAndSvcDeployment = await setupSMI(
kubectl,
manifestObjects.serviceEntityList,
timeout
)
// create new deloyments
const blueGreenDeployment: BlueGreenDeployment = await deployWithLabel(
kubectl,
manifestObjects.deploymentEntityList,
GREEN_LABEL_VALUE,
timeout
)
blueGreenDeployment.objects.push(...newObjectsList)
blueGreenDeployment.objects.push(...smiAndSvcDeployment.objects)
blueGreenDeployment.deployResult.manifestFiles.push(
...otherObjDeployment.manifestFiles
)
blueGreenDeployment.deployResult.manifestFiles.push(
...smiAndSvcDeployment.deployResult.manifestFiles
)
return blueGreenDeployment
}
export async function deployBlueGreenIngress(
kubectl: Kubectl,
filePaths: string[],
timeout?: string
): Promise<BlueGreenDeployment> {
// get all kubernetes objects defined in manifest files
const manifestObjects: BlueGreenManifests = getManifestObjects(filePaths)
// create deployments with green label value
const servicesAndDeployments = [].concat(
manifestObjects.deploymentEntityList,
manifestObjects.serviceEntityList
)
const workloadDeployment: BlueGreenDeployment = await deployWithLabel(
kubectl,
servicesAndDeployments,
GREEN_LABEL_VALUE,
timeout
)
const otherObjects = [].concat(
manifestObjects.otherObjects,
manifestObjects.unroutedServiceEntityList
)
await deployObjects(kubectl, otherObjects, timeout)
core.debug(
`new objects after processing services and other objects: \n
${JSON.stringify(servicesAndDeployments)}`
)
return {
deployResult: workloadDeployment.deployResult,
objects: [].concat(workloadDeployment.objects, otherObjects)
}
}
export async function deployBlueGreenService(
kubectl: Kubectl,
filePaths: string[],
timeout?: string
): Promise<BlueGreenDeployment> {
const manifestObjects: BlueGreenManifests = getManifestObjects(filePaths)
// create deployments with green label value
const blueGreenDeployment: BlueGreenDeployment = await deployWithLabel(
kubectl,
manifestObjects.deploymentEntityList,
GREEN_LABEL_VALUE,
timeout
)
// create other non deployment and non service entities
const newObjectsList = [].concat(
manifestObjects.otherObjects,
manifestObjects.ingressEntityList,
manifestObjects.unroutedServiceEntityList
)
await deployObjects(kubectl, newObjectsList, timeout)
// returning deployment details to check for rollout stability
return {
deployResult: blueGreenDeployment.deployResult,
objects: [].concat(blueGreenDeployment.objects, newObjectsList)
}
}