mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-09 23:32:16 +08:00
add annotation key prefix
This commit is contained in:
parent
71e93a71d4
commit
d96b9b2965
@ -1,24 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
cleanLabel,
|
cleanLabel,
|
||||||
prefixObjectKeys
|
|
||||||
} from '../utilities/workflowAnnotationUtils'
|
} from '../utilities/workflowAnnotationUtils'
|
||||||
|
|
||||||
describe('WorkflowAnnotationUtils', () => {
|
describe('WorkflowAnnotationUtils', () => {
|
||||||
describe('prefixObjectKeys', () => {
|
|
||||||
it('should prefix an object with a given prefix', () => {
|
|
||||||
const obj = {
|
|
||||||
foo: 'bar',
|
|
||||||
baz: 'qux'
|
|
||||||
}
|
|
||||||
const prefix = 'prefix.'
|
|
||||||
const expected = {
|
|
||||||
'prefix.foo': 'bar',
|
|
||||||
'prefix.baz': 'qux'
|
|
||||||
}
|
|
||||||
expect(prefixObjectKeys(obj, prefix)).toEqual(expected)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('cleanLabel', () => {
|
describe('cleanLabel', () => {
|
||||||
it('should clean label', () => {
|
it('should clean label', () => {
|
||||||
const alreadyClean = 'alreadyClean'
|
const alreadyClean = 'alreadyClean'
|
||||||
|
|||||||
@ -2,13 +2,6 @@ import {DeploymentConfig} from '../types/deploymentConfig'
|
|||||||
|
|
||||||
const ANNOTATION_PREFIX = 'actions.github.com/'
|
const ANNOTATION_PREFIX = 'actions.github.com/'
|
||||||
|
|
||||||
export function prefixObjectKeys(obj: any, prefix: string): any {
|
|
||||||
return Object.keys(obj).reduce((newObj, key) => {
|
|
||||||
newObj[prefix + key] = obj[key]
|
|
||||||
return newObj
|
|
||||||
}, {})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getWorkflowAnnotations(
|
export function getWorkflowAnnotations(
|
||||||
lastSuccessRunSha: string,
|
lastSuccessRunSha: string,
|
||||||
workflowFilePath: string,
|
workflowFilePath: string,
|
||||||
@ -31,11 +24,7 @@ export function getWorkflowAnnotations(
|
|||||||
helmChartPaths: deploymentConfig.helmChartFilePaths,
|
helmChartPaths: deploymentConfig.helmChartFilePaths,
|
||||||
provider: 'GitHub'
|
provider: 'GitHub'
|
||||||
}
|
}
|
||||||
const prefixedAnnotationObject = prefixObjectKeys(
|
return JSON.stringify(annotationObject)
|
||||||
annotationObject,
|
|
||||||
ANNOTATION_PREFIX
|
|
||||||
)
|
|
||||||
return JSON.stringify(prefixedAnnotationObject)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getWorkflowAnnotationKeyLabel(
|
export function getWorkflowAnnotationKeyLabel(
|
||||||
@ -43,7 +32,7 @@ export function getWorkflowAnnotationKeyLabel(
|
|||||||
): string {
|
): string {
|
||||||
const hashKey = require('crypto')
|
const hashKey = require('crypto')
|
||||||
.createHash('MD5')
|
.createHash('MD5')
|
||||||
.update(`${process.env.GITHUB_REPOSITORY}/${workflowFilePath}`)
|
.update(`${ANNOTATION_PREFIX}/${workflowFilePath}`)
|
||||||
.digest('hex')
|
.digest('hex')
|
||||||
return `githubWorkflow_${hashKey}`
|
return `githubWorkflow_${hashKey}`
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user