Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add annotation key prefix #216

Merged
merged 4 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/strategyHelpers/deploymentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export async function annotateAndLabelResources(
const workflowFilePath = await getWorkflowFilePath(githubToken)

const deploymentConfig = await getDeploymentConfig()
const annotationKeyLabel = getWorkflowAnnotationKeyLabel(workflowFilePath)
const annotationKeyLabel = getWorkflowAnnotationKeyLabel()

await annotateResources(
files,
Expand Down
20 changes: 1 addition & 19 deletions src/utilities/workflowAnnotationUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import {
cleanLabel,
prefixObjectKeys
} from '../utilities/workflowAnnotationUtils'
import {cleanLabel} from '../utilities/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', () => {
it('should clean label', () => {
const alreadyClean = 'alreadyClean'
Expand Down
25 changes: 4 additions & 21 deletions src/utilities/workflowAnnotationUtils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {DeploymentConfig} from '../types/deploymentConfig'

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
}, {})
}
const ANNOTATION_PREFIX = 'actions.github.com'

export function getWorkflowAnnotations(
lastSuccessRunSha: string,
Expand All @@ -31,21 +24,11 @@ export function getWorkflowAnnotations(
helmChartPaths: deploymentConfig.helmChartFilePaths,
provider: 'GitHub'
}
const prefixedAnnotationObject = prefixObjectKeys(
annotationObject,
ANNOTATION_PREFIX
)
return JSON.stringify(prefixedAnnotationObject)
return JSON.stringify(annotationObject)
}

export function getWorkflowAnnotationKeyLabel(
workflowFilePath: string
): string {
const hashKey = require('crypto')
.createHash('MD5')
.update(`${process.env.GITHUB_REPOSITORY}/${workflowFilePath}`)
.digest('hex')
return `githubWorkflow_${hashKey}`
export function getWorkflowAnnotationKeyLabel(): string {
return `${ANNOTATION_PREFIX}/k8s-deploy`
}

/**
Expand Down