mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-16 19:42:19 +08:00
* 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
89 lines
2.7 KiB
TypeScript
89 lines
2.7 KiB
TypeScript
import * as core from '@actions/core'
|
|
import * as canaryDeploymentHelper from '../strategyHelpers/canary/canaryHelper.js'
|
|
import * as SMICanaryDeploymentHelper from '../strategyHelpers/canary/smiCanaryHelper.js'
|
|
import {Kubectl} from '../types/kubectl.js'
|
|
import {BlueGreenManifests} from '../types/blueGreenTypes.js'
|
|
import {
|
|
rejectBlueGreenIngress,
|
|
rejectBlueGreenService,
|
|
rejectBlueGreenSMI
|
|
} from '../strategyHelpers/blueGreen/reject.js'
|
|
import {getManifestObjects} from '../strategyHelpers/blueGreen/blueGreenHelper.js'
|
|
import {DeploymentStrategy} from '../types/deploymentStrategy.js'
|
|
import {
|
|
parseTrafficSplitMethod,
|
|
TrafficSplitMethod
|
|
} from '../types/trafficSplitMethod.js'
|
|
import {parseRouteStrategy, RouteStrategy} from '../types/routeStrategy.js'
|
|
|
|
export async function reject(
|
|
kubectl: Kubectl,
|
|
manifests: string[],
|
|
deploymentStrategy: DeploymentStrategy,
|
|
timeout?: string
|
|
) {
|
|
switch (deploymentStrategy) {
|
|
case DeploymentStrategy.CANARY:
|
|
await rejectCanary(kubectl, manifests, timeout)
|
|
break
|
|
case DeploymentStrategy.BLUE_GREEN:
|
|
await rejectBlueGreen(kubectl, manifests, timeout)
|
|
break
|
|
default:
|
|
throw 'Invalid delete deployment strategy'
|
|
}
|
|
}
|
|
|
|
async function rejectCanary(
|
|
kubectl: Kubectl,
|
|
manifests: string[],
|
|
timeout?: string
|
|
) {
|
|
let includeServices = false
|
|
|
|
const trafficSplitMethod = parseTrafficSplitMethod(
|
|
core.getInput('traffic-split-method', {required: true})
|
|
)
|
|
if (trafficSplitMethod == TrafficSplitMethod.SMI) {
|
|
core.startGroup('Rejecting deployment with SMI canary strategy')
|
|
includeServices = true
|
|
await SMICanaryDeploymentHelper.redirectTrafficToStableDeployment(
|
|
kubectl,
|
|
manifests,
|
|
timeout
|
|
)
|
|
core.endGroup()
|
|
}
|
|
|
|
core.startGroup('Deleting baseline and canary workloads')
|
|
await canaryDeploymentHelper.deleteCanaryDeployment(
|
|
kubectl,
|
|
manifests,
|
|
includeServices,
|
|
timeout
|
|
)
|
|
core.endGroup()
|
|
}
|
|
|
|
async function rejectBlueGreen(
|
|
kubectl: Kubectl,
|
|
manifests: string[],
|
|
timeout?: string
|
|
) {
|
|
const routeStrategy = parseRouteStrategy(
|
|
core.getInput('route-method', {required: true})
|
|
)
|
|
core.startGroup('Rejecting deployment with blue green strategy')
|
|
core.info(`using routeMethod ${routeStrategy}`)
|
|
const manifestObjects: BlueGreenManifests = getManifestObjects(manifests)
|
|
|
|
if (routeStrategy == RouteStrategy.INGRESS) {
|
|
await rejectBlueGreenIngress(kubectl, manifestObjects, timeout)
|
|
} else if (routeStrategy == RouteStrategy.SMI) {
|
|
await rejectBlueGreenSMI(kubectl, manifestObjects, timeout)
|
|
} else {
|
|
await rejectBlueGreenService(kubectl, manifestObjects, timeout)
|
|
}
|
|
core.endGroup()
|
|
}
|