Extracted poms

This commit is contained in:
Jonas Bovin 2022-11-23 12:44:11 +01:00
parent d226a0fe29
commit b17e8805d3
2 changed files with 74 additions and 41 deletions

55
dist/index.js vendored
View file

@ -13607,13 +13607,8 @@ class se_Helper {
this.currentBuild = currentBuild; this.currentBuild = currentBuild;
this.github = github; this.github = github;
} }
createMetaJson(root) { listPoms(root) {
const execSync = external_child_process_.execSync; const execSync = external_child_process_.execSync;
console.log('Run number: ' + this.currentBuild.runNumber);
const xmllint = execSync('sudo apt install libxml2-utils', {
shell: '/bin/bash'
});
console.log(xmllint.toString());
const command = `#!/bin/bash const command = `#!/bin/bash
cd ` + cd ` +
root + root +
@ -13626,20 +13621,39 @@ class se_Helper {
console.log(output.toString()); console.log(output.toString());
const ret = []; const ret = [];
const poms = Object(external_fs_.readFileSync)(root + 'poms.txt', 'utf8').toString(); const poms = Object(external_fs_.readFileSync)(root + 'poms.txt', 'utf8').toString();
const ownersFile = Object(external_fs_.readFileSync)(root + '.github/CODEOWNERS', 'utf8')
.toString();
for (const pomRaw of poms.split('\n')) { for (const pomRaw of poms.split('\n')) {
const pom = pomRaw.replace('./', '/'); const pom = pomRaw.replace('./', '/');
const name = pom.split('/')[2]; const pomEntity = {};
if (pom.startsWith('/components') && pomEntity['path'] = pom.replace('/pom.xml', '').substring(1);
pom.indexOf(name + '-deployment/') > -1) { pomEntity['raw'] = pomRaw;
pomEntity['pom'] = pom;
pomEntity['name'] = pom.split('/')[2];
pomEntity['fullPath'] = root + pomRaw.substring(1);
ret.push(pomEntity);
}
return ret;
}
createMetaJson(root) {
const execSync = external_child_process_.execSync;
console.log('Run number: ' + this.currentBuild.runNumber);
const xmllint = execSync('sudo apt install libxml2-utils', {
shell: '/bin/bash'
});
console.log(xmllint.toString());
const ret = [];
const poms = this.listPoms(root);
const ownersFile = Object(external_fs_.readFileSync)(root + '.github/CODEOWNERS', 'utf8')
.toString();
for (const pomEntity of poms) {
if (pomEntity['pom'].startsWith('/components') &&
pomEntity['pom'].indexOf(name + '-deployment/') > -1) {
const owners = []; const owners = [];
const reviewers = []; const reviewers = [];
for (const ownerRaw of ownersFile.split('\n')) { for (const ownerRaw of ownersFile.split('\n')) {
const path = ownerRaw.split(' ')[0]; const path = ownerRaw.split(' ')[0];
if (path.length > 3 && if (path.length > 3 &&
ownerRaw.indexOf(' @') > -1 && ownerRaw.indexOf(' @') > -1 &&
pom.startsWith(path)) { pomEntity['pom'].startsWith(path)) {
owners.push(ownerRaw.split(' ')[1]); owners.push(ownerRaw.split(' ')[1]);
reviewers.push(ownerRaw.split(' ')[1]); reviewers.push(ownerRaw.split(' ')[1]);
} }
@ -13649,7 +13663,7 @@ class se_Helper {
root + root +
` `
xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` + xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` +
pom + pomEntity['pom'] +
` `
`; `;
const aid = `#!/bin/bash const aid = `#!/bin/bash
@ -13657,7 +13671,7 @@ class se_Helper {
root + root +
` `
xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` + xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` +
pom + pomEntity['pom'] +
` `
`; `;
const groupId = execSync(gid, { shell: '/bin/bash' }).toString(); const groupId = execSync(gid, { shell: '/bin/bash' }).toString();
@ -13665,21 +13679,22 @@ class se_Helper {
const artifactId = execSync(aid, { shell: '/bin/bash' }).toString(); const artifactId = execSync(aid, { shell: '/bin/bash' }).toString();
console.log(artifactId); console.log(artifactId);
const meta = {}; const meta = {};
meta['manifestSource'] = pom.replace('/pom.xml', '').substring(1); meta['manifestSource'] = pomEntity['path'];
meta['manifestTarget'] = meta['manifestTarget'] =
'helm-chart/components/charts/' + 'helm-chart/components/charts/' +
name + pomEntity['name'] +
'/' + '/' +
name + pomEntity['name'] +
'-deployment/templates/'; '-deployment/templates/';
meta['owners'] = owners; meta['owners'] = owners;
meta['reviewers'] = reviewers; meta['reviewers'] = reviewers;
meta['branchName'] = name + '-deployment'; meta['branchName'] = pomEntity['name'] + '-deployment';
meta['mavenGroupId'] = groupId.trim(); meta['mavenGroupId'] = groupId.trim();
meta['mavenArtifactId'] = artifactId.trim(); meta['mavenArtifactId'] = artifactId.trim();
console.log(JSON.stringify(meta)); console.log(JSON.stringify(meta));
ret.push(pomRaw.replace('/pom.xml', '/meta.json').substring(1)); ret.push(pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1));
Object(external_fs_.writeFileSync)(root + pomRaw.replace('/pom.xml', '/meta.json').substring(1), JSON.stringify(meta)); Object(external_fs_.writeFileSync)(root +
pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1), JSON.stringify(meta));
} }
} }
return ret; return ret;

View file

@ -15,13 +15,8 @@ export class Helper {
this.github = github this.github = github
} }
public createMetaJson(root: string) { public listPoms(root: string): {[key: string]: string}[] {
const execSync = child.execSync const execSync = child.execSync
console.log('Run number: ' + this.currentBuild.runNumber)
const xmllint = execSync('sudo apt install libxml2-utils', {
shell: '/bin/bash'
})
console.log(xmllint.toString())
const command = const command =
`#!/bin/bash `#!/bin/bash
cd ` + cd ` +
@ -33,17 +28,37 @@ export class Helper {
` `
const output = execSync(command, {shell: '/bin/bash'}) const output = execSync(command, {shell: '/bin/bash'})
console.log(output.toString()) console.log(output.toString())
const ret: string[] = [] const ret: {[key: string]: any}[] = []
const poms = fs.readFileSync(root + 'poms.txt', 'utf8').toString() const poms = fs.readFileSync(root + 'poms.txt', 'utf8').toString()
for (const pomRaw of poms.split('\n')) {
const pom = pomRaw.replace('./', '/')
const pomEntity: {[key: string]: any} = {}
pomEntity['path'] = pom.replace('/pom.xml', '').substring(1)
pomEntity['raw'] = pomRaw
pomEntity['pom'] = pom
pomEntity['name'] = pom.split('/')[2]
pomEntity['fullPath'] = root + pomRaw.substring(1)
ret.push(pomEntity)
}
return ret
}
public createMetaJson(root: string) {
const execSync = child.execSync
console.log('Run number: ' + this.currentBuild.runNumber)
const xmllint = execSync('sudo apt install libxml2-utils', {
shell: '/bin/bash'
})
console.log(xmllint.toString())
const ret: string[] = []
const poms = this.listPoms(root)
const ownersFile = fs const ownersFile = fs
.readFileSync(root + '.github/CODEOWNERS', 'utf8') .readFileSync(root + '.github/CODEOWNERS', 'utf8')
.toString() .toString()
for (const pomRaw of poms.split('\n')) { for (const pomEntity of poms) {
const pom = pomRaw.replace('./', '/')
const name = pom.split('/')[2]
if ( if (
pom.startsWith('/components') && pomEntity['pom'].startsWith('/components') &&
pom.indexOf(name + '-deployment/') > -1 pomEntity['pom'].indexOf(name + '-deployment/') > -1
) { ) {
const owners = [] const owners = []
const reviewers = [] const reviewers = []
@ -53,7 +68,7 @@ export class Helper {
if ( if (
path.length > 3 && path.length > 3 &&
ownerRaw.indexOf(' @') > -1 && ownerRaw.indexOf(' @') > -1 &&
pom.startsWith(path) pomEntity['pom'].startsWith(path)
) { ) {
owners.push(ownerRaw.split(' ')[1]) owners.push(ownerRaw.split(' ')[1])
reviewers.push(ownerRaw.split(' ')[1]) reviewers.push(ownerRaw.split(' ')[1])
@ -65,7 +80,7 @@ export class Helper {
root + root +
` `
xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` + xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` +
pom + pomEntity['pom'] +
` `
` `
const aid = const aid =
@ -74,7 +89,7 @@ export class Helper {
root + root +
` `
xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` + xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` +
pom + pomEntity['pom'] +
` `
` `
const groupId = execSync(gid, {shell: '/bin/bash'}).toString() const groupId = execSync(gid, {shell: '/bin/bash'}).toString()
@ -82,22 +97,25 @@ export class Helper {
const artifactId = execSync(aid, {shell: '/bin/bash'}).toString() const artifactId = execSync(aid, {shell: '/bin/bash'}).toString()
console.log(artifactId) console.log(artifactId)
const meta: {[key: string]: any} = {} const meta: {[key: string]: any} = {}
meta['manifestSource'] = pom.replace('/pom.xml', '').substring(1) meta['manifestSource'] = pomEntity['path']
meta['manifestTarget'] = meta['manifestTarget'] =
'helm-chart/components/charts/' + 'helm-chart/components/charts/' +
name + pomEntity['name'] +
'/' + '/' +
name + pomEntity['name'] +
'-deployment/templates/' '-deployment/templates/'
meta['owners'] = owners meta['owners'] = owners
meta['reviewers'] = reviewers meta['reviewers'] = reviewers
meta['branchName'] = name + '-deployment' meta['branchName'] = pomEntity['name'] + '-deployment'
meta['mavenGroupId'] = groupId.trim() meta['mavenGroupId'] = groupId.trim()
meta['mavenArtifactId'] = artifactId.trim() meta['mavenArtifactId'] = artifactId.trim()
console.log(JSON.stringify(meta)) console.log(JSON.stringify(meta))
ret.push(pomRaw.replace('/pom.xml', '/meta.json').substring(1)) ret.push(
pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1)
)
fs.writeFileSync( fs.writeFileSync(
root + pomRaw.replace('/pom.xml', '/meta.json').substring(1), root +
pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1),
JSON.stringify(meta) JSON.stringify(meta)
) )
} }