JSON structure fixes

This commit is contained in:
Jyotsna 2020-11-23 15:37:13 +05:30
parent 27085d52d5
commit 9458d67ac6
4 changed files with 35 additions and 36 deletions

View File

@ -26,23 +26,22 @@ exports.deploymentTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'stat
exports.workloadTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset', 'job', 'cronjob'];
exports.workloadTypesWithRolloutStatus = ['deployment', 'daemonset', 'statefulset'];
function getWorkflowAnnotationsJson(lastSuccessRunSha, workflowFilePath, filePathConfigs) {
return `{`
+ `'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': '${JSON.stringify(filePathConfigs.dockerfilePaths, null, 2)}',`
+ `'manifestsPaths': '${JSON.stringify(filePathConfigs.manifestFilePaths, null, 2)}',`
+ `'helmChartPaths': '${JSON.stringify(filePathConfigs.helmChartFilePaths, null, 2)}',`
+ `'provider': 'GitHub'`
+ `}`;
let annotationObject;
annotationObject["run"] = process.env.GITHUB_RUN_ID;
annotationObject["repository"] = process.env.GITHUB_REPOSITORY;
annotationObject["workflow"] = process.env.GITHUB_WORKFLOW;
annotationObject["workflowFileName"] = workflowFilePath.replace(".github/workflows/", "");
annotationObject["jobName"] = process.env.GITHUB_JOB;
annotationObject["createdBy"] = process.env.GITHUB_ACTOR;
annotationObject["runUri"] = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
annotationObject["commit"] = process.env.GITHUB_SHA;
annotationObject["branch"] = process.env.GITHUB_REF;
annotationObject["deployTimestamp"] = Date.now();
annotationObject["dockerfilePaths"] = filePathConfigs.dockerfilePaths;
annotationObject["manifestsPaths"] = filePathConfigs.manifestFilePaths;
annotationObject["helmChartPaths"] = filePathConfigs.helmChartFilePaths;
annotationObject["provider"] = "GitHub";
return JSON.stringify(annotationObject);
}
exports.getWorkflowAnnotationsJson = getWorkflowAnnotationsJson;
function getWorkflowAnnotationKeyLabel(workflowFilePath) {

View File

@ -151,7 +151,7 @@ function getFilePathsConfigs() {
let helmChartPaths = [];
if (process.env.HELM_CHART_PATHS) {
helmChartPaths = process.env.HELM_CHART_PATHS.split('\n');
helmChartPaths.filter(val => val != "");
helmChartPaths.splice(-1);
}
filePathsConfig[HELM_CHART_KEY] = helmChartPaths;
//Fetch labels from each image

View File

@ -26,23 +26,23 @@ export const workloadTypes: string[] = ['deployment', 'replicaset', 'daemonset',
export const workloadTypesWithRolloutStatus: string[] = ['deployment', 'daemonset', 'statefulset'];
export function getWorkflowAnnotationsJson(lastSuccessRunSha: string, workflowFilePath: string, filePathConfigs: any): string {
return `{`
+ `'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': '${JSON.stringify(filePathConfigs.dockerfilePaths,null,2)}',`
+ `'manifestsPaths': '${JSON.stringify(filePathConfigs.manifestFilePaths,null,2)}',`
+ `'helmChartPaths': '${JSON.stringify(filePathConfigs.helmChartFilePaths,null,2)}',`
+ `'provider': 'GitHub'`
+ `}`;
let annotationObject: any;
annotationObject["run"] = process.env.GITHUB_RUN_ID;
annotationObject["repository"] = process.env.GITHUB_REPOSITORY;
annotationObject["workflow"] = process.env.GITHUB_WORKFLOW;
annotationObject["workflowFileName"] = workflowFilePath.replace(".github/workflows/", "");
annotationObject["jobName"] = process.env.GITHUB_JOB;
annotationObject["createdBy"] = process.env.GITHUB_ACTOR;
annotationObject["runUri"] = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
annotationObject["commit"] = process.env.GITHUB_SHA;
annotationObject["branch"] = process.env.GITHUB_REF;
annotationObject["deployTimestamp"] = Date.now();
annotationObject["dockerfilePaths"] = filePathConfigs.dockerfilePaths;
annotationObject["manifestsPaths"] = filePathConfigs.manifestFilePaths
annotationObject["helmChartPaths"] = filePathConfigs.helmChartFilePaths;
annotationObject["provider"] = "GitHub";
return JSON.stringify(annotationObject);
}
export function getWorkflowAnnotationKeyLabel(workflowFilePath: string): string {

View File

@ -144,7 +144,7 @@ export async function getFilePathsConfigs(): Promise<any> {
let helmChartPaths = [];
if(process.env.HELM_CHART_PATHS){
helmChartPaths = process.env.HELM_CHART_PATHS.split('\n');
helmChartPaths.filter( val => val != "" );
helmChartPaths.splice(-1);
}
filePathsConfig[HELM_CHART_KEY] = helmChartPaths;