diff --git a/README.md b/README.md index 8651ae88c..4218bf0ed 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,23 @@ The following arguments will be provided: - `io` A reference to the [@actions/io](https://github.com/actions/toolkit/tree/main/packages/io) package - `exec` A reference to the [@actions/exec](https://github.com/actions/toolkit/tree/main/packages/exec) package - `require` A proxy wrapper around the normal Node.js `require` to enable -- 'se' A library for resusbale functions - requiring relative paths (relative to the current working directory) and - requiring npm packages installed in the current working directory. If for - some reason you need the non-wrapped `require`, there is an escape hatch - available: `__original_require__` is the original value of `require` without - our wrapping applied. +- `se` A library for resusbale functions + - `createMetaJson` Create meta.json files for all deployable component + - returns a list of files created + - `startCheck` Helper method to create a check without annotations + - `completeCheck` Helper method to finish a check without annotations + - `listPoms`List all pom entities - returns an array of elements containing + - `pom` the pom file from repo root + - `path` path to folder for pom + - `pomRaw` path as matched with codeowners starts with / + - `name`the component name - if any + - `fullPath` path to pom from workdir if checked out in a subfolder + +requiring relative paths (relative to the current working directory) and +requiring npm packages installed in the current working directory. If for +some reason you need the non-wrapped `require`, there is an escape hatch +available: `__original_require__` is the original value of `require` without +our wrapping applied. Since the `script` is just a function body, these values will already be defined, so you don't have to import them (see examples below). diff --git a/dist/index.js b/dist/index.js index 158c84fca..c98fd9bf7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -40,7 +40,7 @@ module.exports = /******/ // the startup function /******/ function startup() { /******/ // Load entry module and return exports -/******/ return __webpack_require__(226); +/******/ return __webpack_require__(888); /******/ }; /******/ // initialize runtime /******/ runtime(__webpack_require__); @@ -6078,257 +6078,6 @@ function onceStrict (fn) { } -/***/ }), - -/***/ 226: -/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -var se_namespaceObject = {}; -__webpack_require__.r(se_namespaceObject); -__webpack_require__.d(se_namespaceObject, "createMetaJson", function() { return createMetaJson; }); - -// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js -var core = __webpack_require__(186); - -// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js -var exec = __webpack_require__(514); - -// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js -var lib_github = __webpack_require__(438); - -// EXTERNAL MODULE: ./node_modules/@actions/github/lib/utils.js -var utils = __webpack_require__(30); - -// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js -var glob = __webpack_require__(90); - -// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js -var io = __webpack_require__(436); - -// EXTERNAL MODULE: ./node_modules/@octokit/plugin-retry/dist-node/index.js -var dist_node = __webpack_require__(745); - -// CONCATENATED MODULE: ./src/async-function.ts -const AsyncFunction = Object.getPrototypeOf(async () => null).constructor; -function callAsyncFunction(args, source) { - const fn = new AsyncFunction(...Object.keys(args), source); - return fn(...Object.values(args)); -} - -// CONCATENATED MODULE: ./src/retry-options.ts - -function getRetryOptions(retries, exemptStatusCodes, defaultOptions) { - var _a; - if (retries <= 0) { - return [{ enabled: false }, defaultOptions.request]; - } - const retryOptions = { - enabled: true - }; - if (exemptStatusCodes.length > 0) { - retryOptions.doNotRetry = exemptStatusCodes; - } - // The GitHub type has some defaults for `options.request` - // see: https://github.com/actions/toolkit/blob/4fbc5c941a57249b19562015edbd72add14be93d/packages/github/src/utils.ts#L15 - // We pass these in here so they are not overidden. - const requestOptions = { - ...defaultOptions.request, - retries - }; - Object(core.debug)(`GitHub client configured with: (retries: ${requestOptions.retries}, retry-exempt-status-code: ${(_a = retryOptions === null || retryOptions === void 0 ? void 0 : retryOptions.doNotRetry) !== null && _a !== void 0 ? _a : 'octokit default: [400, 401, 403, 404, 422]'})`); - return [retryOptions, requestOptions]; -} -function parseNumberArray(listString) { - if (!listString) { - return []; - } - const split = listString.trim().split(','); - return split.map(x => parseInt(x)); -} - -// EXTERNAL MODULE: external "path" -var external_path_ = __webpack_require__(622); - -// CONCATENATED MODULE: ./src/wrap-require.ts - -const wrapRequire = new Proxy(require, { - apply: (target, thisArg, [moduleID]) => { - if (moduleID.startsWith('.')) { - moduleID = Object(external_path_.resolve)(moduleID); - return target.apply(thisArg, [moduleID]); - } - const modulePath = target.resolve.apply(thisArg, [ - moduleID, - { - // Webpack does not have an escape hatch for getting the actual - // module, other than `eval`. - paths: [process.cwd()] - } - ]); - return target.apply(thisArg, [modulePath]); - }, - get: (target, prop, receiver) => { - Reflect.get(target, prop, receiver); - } -}); - -// EXTERNAL MODULE: external "child_process" -var external_child_process_ = __webpack_require__(129); - -// EXTERNAL MODULE: external "fs" -var external_fs_ = __webpack_require__(747); - -// CONCATENATED MODULE: ./src/se.ts - - -function createMetaJson(root) { - const execSync = external_child_process_.execSync; - const xmllint = execSync('sudo apt install libxml2-utils', { - shell: '/bin/bash' - }); - console.log(xmllint.toString()); - const command = `#!/bin/bash - cd ` + - root + - ` - find . -name 'pom.xml' -type f > ` + - root + - `poms.txt - `; - const output = execSync(command, { shell: '/bin/bash' }); - console.log(output.toString()); - const ret = []; - 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')) { - const pom = pomRaw.replace('./', '/'); - const name = pom.split('/')[2]; - if (pom.startsWith('/components') && - pom.indexOf(name + '-deployment/') > -1) { - const owners = []; - const reviewers = []; - for (const ownerRaw of ownersFile.split('\n')) { - const path = ownerRaw.split(' ')[0]; - if (path.length > 3 && - ownerRaw.indexOf(' @') > -1 && - pom.startsWith(path)) { - owners.push(ownerRaw.split(' ')[1]); - reviewers.push(ownerRaw.split(' ')[1]); - } - } - const gid = `#!/bin/bash - cd ` + - root + - ` - xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" ` + - pom + - ` - `; - const aid = `#!/bin/bash - cd ` + - root + - ` - xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" ` + - pom + - ` - `; - const groupId = execSync(gid, { shell: '/bin/bash' }).toString(); - console.log(groupId); - const artifactId = execSync(aid, { shell: '/bin/bash' }).toString(); - console.log(artifactId); - const meta = {}; - meta['manifestSource'] = pom.replace('/pom.xml', '').substring(1); - meta['manifestTarget'] = - 'helm-chart/components/charts/' + - name + - '/' + - name + - '-deployment/templates/'; - meta['owners'] = owners; - meta['reviewers'] = reviewers; - meta['branchName'] = name + '-deployment'; - meta['mavenGroupId'] = groupId.trim(); - meta['mavenArtifactId'] = artifactId.trim(); - console.log(JSON.stringify(meta)); - ret.push(pomRaw.replace('/pom.xml', '/meta.json').substring(1)); - Object(external_fs_.writeFileSync)(root + pomRaw.replace('/pom.xml', '/meta.json').substring(1), JSON.stringify(meta)); - } - } - return ret; -} - -// CONCATENATED MODULE: ./src/main.ts - - - - - - - - - - - -process.on('unhandledRejection', handleError); -main().catch(handleError); -async function main() { - const token = Object(core.getInput)('github-token', { required: true }); - const debug = Object(core.getInput)('debug'); - const userAgent = Object(core.getInput)('user-agent'); - const previews = Object(core.getInput)('previews'); - const retries = parseInt(Object(core.getInput)('retries')); - const exemptStatusCodes = parseNumberArray(Object(core.getInput)('retry-exempt-status-codes')); - const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults); - const opts = {}; - if (debug === 'true') - opts.log = console; - if (userAgent != null) - opts.userAgent = userAgent; - if (previews != null) - opts.previews = previews.split(','); - if (retryOpts) - opts.retry = retryOpts; - if (requestOpts) - opts.request = requestOpts; - const github = Object(lib_github.getOctokit)(token, opts, dist_node.retry); - const script = Object(core.getInput)('script', { required: true }); - // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. - const result = await callAsyncFunction({ - require: wrapRequire, - __original_require__: require, - github, - context: lib_github.context, - core: core, - exec: exec, - glob: glob, - io: io, - se: se_namespaceObject - }, script); - let encoding = Object(core.getInput)('result-encoding'); - encoding = encoding ? encoding : 'json'; - let output; - switch (encoding) { - case 'json': - output = JSON.stringify(result); - break; - case 'string': - output = String(result); - break; - default: - throw new Error('"result-encoding" must be either "string" or "json"'); - } - Object(core.setOutput)('result', output); -} -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function handleError(err) { - console.error(err); - Object(core.setFailed)(`Unhandled error: ${err}`); -} - - /***/ }), /***/ 234: @@ -13777,6 +13526,311 @@ conversions["RegExp"] = function (V, opts) { module.exports = eval("require")("encoding"); +/***/ }), + +/***/ 888: +/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); + +// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js +var core = __webpack_require__(186); + +// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js +var exec = __webpack_require__(514); + +// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js +var lib_github = __webpack_require__(438); + +// EXTERNAL MODULE: ./node_modules/@actions/github/lib/utils.js +var utils = __webpack_require__(30); + +// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js +var glob = __webpack_require__(90); + +// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js +var io = __webpack_require__(436); + +// EXTERNAL MODULE: ./node_modules/@octokit/plugin-retry/dist-node/index.js +var dist_node = __webpack_require__(745); + +// CONCATENATED MODULE: ./src/async-function.ts +const AsyncFunction = Object.getPrototypeOf(async () => null).constructor; +function callAsyncFunction(args, source) { + const fn = new AsyncFunction(...Object.keys(args), source); + return fn(...Object.values(args)); +} + +// CONCATENATED MODULE: ./src/retry-options.ts + +function getRetryOptions(retries, exemptStatusCodes, defaultOptions) { + var _a; + if (retries <= 0) { + return [{ enabled: false }, defaultOptions.request]; + } + const retryOptions = { + enabled: true + }; + if (exemptStatusCodes.length > 0) { + retryOptions.doNotRetry = exemptStatusCodes; + } + // The GitHub type has some defaults for `options.request` + // see: https://github.com/actions/toolkit/blob/4fbc5c941a57249b19562015edbd72add14be93d/packages/github/src/utils.ts#L15 + // We pass these in here so they are not overidden. + const requestOptions = { + ...defaultOptions.request, + retries + }; + Object(core.debug)(`GitHub client configured with: (retries: ${requestOptions.retries}, retry-exempt-status-code: ${(_a = retryOptions === null || retryOptions === void 0 ? void 0 : retryOptions.doNotRetry) !== null && _a !== void 0 ? _a : 'octokit default: [400, 401, 403, 404, 422]'})`); + return [retryOptions, requestOptions]; +} +function parseNumberArray(listString) { + if (!listString) { + return []; + } + const split = listString.trim().split(','); + return split.map(x => parseInt(x)); +} + +// EXTERNAL MODULE: external "child_process" +var external_child_process_ = __webpack_require__(129); + +// EXTERNAL MODULE: external "fs" +var external_fs_ = __webpack_require__(747); + +// CONCATENATED MODULE: ./src/se.ts + + +class se_Helper { + constructor(currentBuild, github) { + this.currentBuild = currentBuild; + this.github = github; + } + listPoms(root) { + const execSync = external_child_process_.execSync; + const command = `#!/bin/bash + cd ` + + root + + ` + find . -name 'pom.xml' -type f > ` + + root + + `poms.txt + `; + const output = execSync(command, { shell: '/bin/bash' }); + console.log(output.toString()); + const ret = []; + const poms = Object(external_fs_.readFileSync)(root + 'poms.txt', 'utf8').toString(); + for (const pomRaw of poms.split('\n')) { + const pom = pomRaw.replace('./', '/'); + const pomEntity = {}; + 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; + } + createMetaJson(root) { + const execSync = external_child_process_.execSync; + console.log('Run number: ' + this.currentBuild.runNumber); + try { + const xmllint = execSync('sudo apt-get update; sudo apt install libxml2-utils', { + shell: '/bin/bash' + }); + console.log(xmllint.toString()); + } + catch (err) { + let message; + if (err instanceof Error) { + message = err.message; + } + else { + message = String(err); + } + console.log(message); + } + 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(pomEntity['name'] + '-deployment/') > -1) { + const owners = []; + const reviewers = []; + for (const ownerRaw of ownersFile.split('\n')) { + const path = ownerRaw.split(' ')[0]; + if (path.length > 3 && + ownerRaw.indexOf(' @') > -1 && + pomEntity['pom'].startsWith(path)) { + owners.push(ownerRaw.split(' ')[1]); + reviewers.push(ownerRaw.split(' ')[1]); + } + } + const gid = `#!/bin/bash + cd ` + + root + + ` + xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` + + pomEntity['pom'] + + ` + `; + const aid = `#!/bin/bash + cd ` + + root + + ` + xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` + + pomEntity['pom'] + + ` + `; + const groupId = execSync(gid, { shell: '/bin/bash' }).toString(); + console.log(groupId); + const artifactId = execSync(aid, { shell: '/bin/bash' }).toString(); + console.log(artifactId); + const meta = {}; + meta['manifestSource'] = pomEntity['path']; + meta['manifestTarget'] = + 'helm-chart/components/charts/' + + pomEntity['name'] + + '/' + + pomEntity['name'] + + '-deployment/templates/'; + meta['owners'] = owners; + meta['reviewers'] = reviewers; + meta['branchName'] = pomEntity['name'] + '-deployment'; + meta['mavenGroupId'] = groupId.trim(); + meta['mavenArtifactId'] = artifactId.trim(); + console.log(JSON.stringify(meta)); + ret.push(pomEntity['raw'].replace('/pom.xml', '/meta.json').substring(1)); + Object(external_fs_.writeFileSync)(root + + pomEntity['raw'].replace('/pom.xml', '/meta.json').substring(1), JSON.stringify(meta)); + } + } + return ret; + } + async startCheck(name, status) { + const result = await this.github.rest.checks.create({ + owner: this.currentBuild.repo.owner, + repo: this.currentBuild.repo.repo, + name: name, + head_sha: this.currentBuild.sha, + status: status + }); + return result; + } + async completeCheck(name, id, conclusionString) { + const result = await this.github.rest.checks.update({ + owner: this.currentBuild.repo.owner, + repo: this.currentBuild.repo.repo, + name: name, + check_run_id: id, + head_sha: this.currentBuild.sha, + status: 'completed', + conclusion: conclusionString + }); + return result; + } +} + +// EXTERNAL MODULE: external "path" +var external_path_ = __webpack_require__(622); + +// CONCATENATED MODULE: ./src/wrap-require.ts + +const wrapRequire = new Proxy(require, { + apply: (target, thisArg, [moduleID]) => { + if (moduleID.startsWith('.')) { + moduleID = Object(external_path_.resolve)(moduleID); + return target.apply(thisArg, [moduleID]); + } + const modulePath = target.resolve.apply(thisArg, [ + moduleID, + { + // Webpack does not have an escape hatch for getting the actual + // module, other than `eval`. + paths: [process.cwd()] + } + ]); + return target.apply(thisArg, [modulePath]); + }, + get: (target, prop, receiver) => { + Reflect.get(target, prop, receiver); + } +}); + +// CONCATENATED MODULE: ./src/main.ts + + + + + + + + + + + +process.on('unhandledRejection', handleError); +main().catch(handleError); +async function main() { + const token = Object(core.getInput)('github-token', { required: true }); + const debug = Object(core.getInput)('debug'); + const userAgent = Object(core.getInput)('user-agent'); + const previews = Object(core.getInput)('previews'); + const retries = parseInt(Object(core.getInput)('retries')); + const exemptStatusCodes = parseNumberArray(Object(core.getInput)('retry-exempt-status-codes')); + const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults); + const opts = {}; + if (debug === 'true') + opts.log = console; + if (userAgent != null) + opts.userAgent = userAgent; + if (previews != null) + opts.previews = previews.split(','); + if (retryOpts) + opts.retry = retryOpts; + if (requestOpts) + opts.request = requestOpts; + const github = Object(lib_github.getOctokit)(token, opts, dist_node.retry); + const script = Object(core.getInput)('script', { required: true }); + const se = new se_Helper(lib_github.context, github); + // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. + const result = await callAsyncFunction({ + require: wrapRequire, + __original_require__: require, + github, + context: lib_github.context, + core: core, + exec: exec, + glob: glob, + io: io, + se + }, script); + let encoding = Object(core.getInput)('result-encoding'); + encoding = encoding ? encoding : 'json'; + let output; + switch (encoding) { + case 'json': + output = JSON.stringify(result); + break; + case 'string': + output = String(result); + break; + default: + throw new Error('"result-encoding" must be either "string" or "json"'); + } + Object(core.setOutput)('result', output); +} +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function handleError(err) { + console.error(err); + Object(core.setFailed)(`Unhandled error: ${err}`); +} + + /***/ }), /***/ 891: diff --git a/src/async-function.ts b/src/async-function.ts index 46be50538..d84d43d66 100644 --- a/src/async-function.ts +++ b/src/async-function.ts @@ -4,7 +4,7 @@ import {Context} from '@actions/github/lib/context' import {GitHub} from '@actions/github/lib/utils' import * as glob from '@actions/glob' import * as io from '@actions/io' -import * as se from './se' +import * as helper from './se' const AsyncFunction = Object.getPrototypeOf(async () => null).constructor @@ -15,7 +15,7 @@ type AsyncFunctionArguments = { exec: typeof exec glob: typeof glob io: typeof io - se: typeof se + se: helper.Helper require: NodeRequire __original_require__: NodeRequire } diff --git a/src/main.ts b/src/main.ts index 00494bfb4..31573c59d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,8 +8,8 @@ import {retry} from '@octokit/plugin-retry' import {RequestRequestOptions} from '@octokit/types' import {callAsyncFunction} from './async-function' import {getRetryOptions, parseNumberArray, RetryOptions} from './retry-options' +import * as helper from './se' import {wrapRequire} from './wrap-require' -import * as se from './se' process.on('unhandledRejection', handleError) main().catch(handleError) @@ -46,6 +46,7 @@ async function main(): Promise { const github = getOctokit(token, opts, retry) const script = core.getInput('script', {required: true}) + const se = new helper.Helper(context, github) // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. const result = await callAsyncFunction( diff --git a/src/se.ts b/src/se.ts index 70dbaa2b8..4fb91dacb 100644 --- a/src/se.ts +++ b/src/se.ts @@ -1,92 +1,167 @@ +import {context} from '@actions/github' +import {GitHub} from '@actions/github/lib/utils' import * as child from 'child_process' import * as fs from 'fs' -export function createMetaJson(root: string): string[] { - const execSync = child.execSync +export class Helper { + currentBuild: typeof context + github: InstanceType - const xmllint = execSync('sudo apt install libxml2-utils', { - shell: '/bin/bash' - }) - console.log(xmllint.toString()) - const command = - `#!/bin/bash - cd ` + - root + - ` - find . -name 'pom.xml' -type f > ` + - root + - `poms.txt - ` - const output = execSync(command, {shell: '/bin/bash'}) - console.log(output.toString()) - const ret: string[] = [] - const poms = fs.readFileSync(root + 'poms.txt', 'utf8').toString() - const ownersFile = fs - .readFileSync(root + '.github/CODEOWNERS', 'utf8') - .toString() - for (const pomRaw of poms.split('\n')) { - const pom = pomRaw.replace('./', '/') - const name = pom.split('/')[2] - if ( - pom.startsWith('/components') && - pom.indexOf(name + '-deployment/') > -1 - ) { - const owners = [] - const reviewers = [] - for (const ownerRaw of ownersFile.split('\n')) { - const path = ownerRaw.split(' ')[0] + public constructor( + currentBuild: typeof context, + github: InstanceType + ) { + this.currentBuild = currentBuild + this.github = github + } + + public listPoms(root: string): {[key: string]: string}[] { + const execSync = child.execSync + const command = + `#!/bin/bash + cd ` + + root + + ` + find . -name 'pom.xml' -type f > ` + + root + + `poms.txt + ` + const output = execSync(command, {shell: '/bin/bash'}) + console.log(output.toString()) + const ret: {[key: string]: any}[] = [] + 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 + } - if ( - path.length > 3 && - ownerRaw.indexOf(' @') > -1 && - pom.startsWith(path) - ) { - owners.push(ownerRaw.split(' ')[1]) - reviewers.push(ownerRaw.split(' ')[1]) + public createMetaJson(root: string) { + const execSync = child.execSync + console.log('Run number: ' + this.currentBuild.runNumber) + try { + const xmllint = execSync( + 'sudo apt-get update; sudo apt install libxml2-utils', + { + shell: '/bin/bash' } - } - const gid = - `#!/bin/bash - cd ` + - root + - ` - xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" ` + - pom + - ` - ` - const aid = - `#!/bin/bash - cd ` + - root + - ` - xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" ` + - pom + - ` - ` - const groupId = execSync(gid, {shell: '/bin/bash'}).toString() - console.log(groupId) - const artifactId = execSync(aid, {shell: '/bin/bash'}).toString() - console.log(artifactId) - const meta: {[key: string]: any} = {} - meta['manifestSource'] = pom.replace('/pom.xml', '').substring(1) - meta['manifestTarget'] = - 'helm-chart/components/charts/' + - name + - '/' + - name + - '-deployment/templates/' - meta['owners'] = owners - meta['reviewers'] = reviewers - meta['branchName'] = name + '-deployment' - meta['mavenGroupId'] = groupId.trim() - meta['mavenArtifactId'] = artifactId.trim() - console.log(JSON.stringify(meta)) - ret.push(pomRaw.replace('/pom.xml', '/meta.json').substring(1)) - fs.writeFileSync( - root + pomRaw.replace('/pom.xml', '/meta.json').substring(1), - JSON.stringify(meta) ) + + console.log(xmllint.toString()) + } catch (err) { + let message + if (err instanceof Error) { + message = err.message + } else { + message = String(err) + } + console.log(message) } + const ret: string[] = [] + const poms = this.listPoms(root) + const ownersFile = fs + .readFileSync(root + '.github/CODEOWNERS', 'utf8') + .toString() + for (const pomEntity of poms) { + if ( + pomEntity['pom'].startsWith('/components') && + pomEntity['pom'].indexOf(pomEntity['name'] + '-deployment/') > -1 + ) { + const owners = [] + const reviewers = [] + for (const ownerRaw of ownersFile.split('\n')) { + const path = ownerRaw.split(' ')[0] + + if ( + path.length > 3 && + ownerRaw.indexOf(' @') > -1 && + pomEntity['pom'].startsWith(path) + ) { + owners.push(ownerRaw.split(' ')[1]) + reviewers.push(ownerRaw.split(' ')[1]) + } + } + const gid = + `#!/bin/bash + cd ` + + root + + ` + xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` + + pomEntity['pom'] + + ` + ` + const aid = + `#!/bin/bash + cd ` + + root + + ` + xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` + + pomEntity['pom'] + + ` + ` + const groupId = execSync(gid, {shell: '/bin/bash'}).toString() + console.log(groupId) + const artifactId = execSync(aid, {shell: '/bin/bash'}).toString() + console.log(artifactId) + const meta: {[key: string]: any} = {} + meta['manifestSource'] = pomEntity['path'] + meta['manifestTarget'] = + 'helm-chart/components/charts/' + + pomEntity['name'] + + '/' + + pomEntity['name'] + + '-deployment/templates/' + meta['owners'] = owners + meta['reviewers'] = reviewers + meta['branchName'] = pomEntity['name'] + '-deployment' + meta['mavenGroupId'] = groupId.trim() + meta['mavenArtifactId'] = artifactId.trim() + console.log(JSON.stringify(meta)) + ret.push( + pomEntity['raw'].replace('/pom.xml', '/meta.json').substring(1) + ) + fs.writeFileSync( + root + + pomEntity['raw'].replace('/pom.xml', '/meta.json').substring(1), + JSON.stringify(meta) + ) + } + } + return ret + } + + public async startCheck(name: string, status: string) { + const result = await this.github.rest.checks.create({ + owner: this.currentBuild.repo.owner, + repo: this.currentBuild.repo.repo, + name: name, + head_sha: this.currentBuild.sha, + status: status + }) + return result + } + + public async completeCheck( + name: string, + id: string, + conclusionString: string + ) { + const result = await this.github.rest.checks.update({ + owner: this.currentBuild.repo.owner, + repo: this.currentBuild.repo.repo, + name: name, + check_run_id: id, + head_sha: this.currentBuild.sha, + status: 'completed', + conclusion: conclusionString + }) + return result } - return ret }