mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-30 09:19:27 +08:00
01cfe404ef
* 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
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import {DeploymentConfig} from '../types/deploymentConfig.js'
|
|
|
|
const ANNOTATION_PREFIX = 'actions.github.com'
|
|
|
|
export const VALID_LABEL_REGEX = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/
|
|
|
|
export function getWorkflowAnnotations(
|
|
lastSuccessRunSha: string,
|
|
workflowFilePath: string,
|
|
deploymentConfig: DeploymentConfig
|
|
): string {
|
|
const annotationObject = {
|
|
run: process.env.GITHUB_RUN_ID,
|
|
repository: process.env.GITHUB_REPOSITORY,
|
|
workflow: process.env.GITHUB_WORKFLOW,
|
|
workflowFileName: workflowFilePath.replace('.github/workflows/', ''),
|
|
jobName: process.env.GITHUB_JOB,
|
|
createdBy: process.env.GITHUB_ACTOR,
|
|
runUri: `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`,
|
|
commit: process.env.GITHUB_SHA,
|
|
lastSuccessRunCommit: lastSuccessRunSha,
|
|
branch: process.env.GITHUB_REF,
|
|
deployTimestamp: Date.now(),
|
|
dockerfilePaths: deploymentConfig.dockerfilePaths,
|
|
manifestsPaths: deploymentConfig.manifestFilePaths,
|
|
helmChartPaths: deploymentConfig.helmChartFilePaths,
|
|
provider: 'GitHub'
|
|
}
|
|
return JSON.stringify(annotationObject)
|
|
}
|
|
|
|
export function getWorkflowAnnotationKeyLabel(): string {
|
|
return `${ANNOTATION_PREFIX}/k8s-deploy`
|
|
}
|
|
|
|
/**
|
|
* Cleans label to match valid kubernetes label specification by removing invalid characters
|
|
* @param label
|
|
* @returns cleaned label
|
|
*/
|
|
export function cleanLabel(label: string): string {
|
|
let removedInvalidChars = removeInvalidLabelCharacters(label)
|
|
|
|
const regexResult = VALID_LABEL_REGEX.exec(removedInvalidChars) || [
|
|
'github-workflow-file'
|
|
]
|
|
return regexResult[0]
|
|
}
|
|
|
|
export function removeInvalidLabelCharacters(label: string): string {
|
|
return label
|
|
.replace(/\s/gi, '_')
|
|
.replace(/[\/\\\|]/gi, '-')
|
|
.replace(/[^-A-Za-z0-9_.]/gi, '')
|
|
}
|