From 0fdfdff59eb8393fc8e973fd88c7f0b08bb37497 Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Tue, 22 Nov 2022 12:53:42 +0100 Subject: [PATCH 01/14] Added dot --- dist/index.js | 4 ++-- src/se.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 158c84fca..00e49a212 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6223,7 +6223,7 @@ function createMetaJson(root) { cd ` + root + ` - xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" ` + + xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` + pom + ` `; @@ -6231,7 +6231,7 @@ function createMetaJson(root) { cd ` + root + ` - xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" ` + + xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` + pom + ` `; diff --git a/src/se.ts b/src/se.ts index 70dbaa2b8..8369bbdd2 100644 --- a/src/se.ts +++ b/src/se.ts @@ -50,7 +50,7 @@ export function createMetaJson(root: string): string[] { cd ` + root + ` - xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" ` + + xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` + pom + ` ` @@ -59,7 +59,7 @@ export function createMetaJson(root: string): string[] { cd ` + root + ` - xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" ` + + xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` + pom + ` ` From b1c10247693549995aaa38dd7af201840b13ed22 Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Tue, 22 Nov 2022 15:27:53 +0100 Subject: [PATCH 02/14] Added helper --- dist/index.js | 13 +++++++++++++ src/se.ts | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 00e49a212..7caa09878 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6087,7 +6087,10 @@ function onceStrict (fn) { __webpack_require__.r(__webpack_exports__); var se_namespaceObject = {}; __webpack_require__.r(se_namespaceObject); +__webpack_require__.d(se_namespaceObject, "Helper", function() { return Helper; }); __webpack_require__.d(se_namespaceObject, "createMetaJson", function() { return createMetaJson; }); +__webpack_require__.d(se_namespaceObject, "helper", function() { return helper; }); +__webpack_require__.d(se_namespaceObject, "setHelper", function() { return setHelper; }); // EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js var core = __webpack_require__(186); @@ -6183,8 +6186,18 @@ var external_fs_ = __webpack_require__(747); // CONCATENATED MODULE: ./src/se.ts +class Helper { + constructor(currentBuild) { + this.currentBuild = currentBuild; + } +} +let helper; +function setHelper(helperInstance) { + helper = helperInstance; +} function createMetaJson(root) { const execSync = external_child_process_.execSync; + console.log('Run number: ' + helper.currentBuild.runNumber); const xmllint = execSync('sudo apt install libxml2-utils', { shell: '/bin/bash' }); diff --git a/src/se.ts b/src/se.ts index 8369bbdd2..b6229f811 100644 --- a/src/se.ts +++ b/src/se.ts @@ -1,9 +1,24 @@ +import {context} from '@actions/github' import * as child from 'child_process' import * as fs from 'fs' +export class Helper { + public currentBuild: typeof context + + public constructor(currentBuild: typeof context) { + this.currentBuild = currentBuild + } +} + +export let helper: Helper + +export function setHelper(helperInstance: Helper) { + helper = helperInstance +} + export function createMetaJson(root: string): string[] { const execSync = child.execSync - + console.log('Run number: ' + helper.currentBuild.runNumber) const xmllint = execSync('sudo apt install libxml2-utils', { shell: '/bin/bash' }) From e4f7f1688c348ae0d273d30d0b71bf1cb7865aef Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Tue, 22 Nov 2022 16:44:13 +0100 Subject: [PATCH 03/14] Changed all to be helper --- dist/index.js | 521 +++++++++++++++++++++--------------------- src/async-function.ts | 4 +- src/main.ts | 3 +- src/se.ts | 174 +++++++------- 4 files changed, 344 insertions(+), 358 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7caa09878..5f46655f6 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,270 +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, "Helper", function() { return Helper; }); -__webpack_require__.d(se_namespaceObject, "createMetaJson", function() { return createMetaJson; }); -__webpack_require__.d(se_namespaceObject, "helper", function() { return helper; }); -__webpack_require__.d(se_namespaceObject, "setHelper", function() { return setHelper; }); - -// 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 - - -class Helper { - constructor(currentBuild) { - this.currentBuild = currentBuild; - } -} -let helper; -function setHelper(helperInstance) { - helper = helperInstance; -} -function createMetaJson(root) { - const execSync = external_child_process_.execSync; - console.log('Run number: ' + helper.currentBuild.runNumber); - 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: @@ -13790,6 +13526,261 @@ 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) { + this.currentBuild = currentBuild; + } + 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 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; + } +} + +// 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); + // 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..25a31ffd4 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) // 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 b6229f811..f9f3e166a 100644 --- a/src/se.ts +++ b/src/se.ts @@ -8,100 +8,94 @@ export class Helper { public constructor(currentBuild: typeof context) { this.currentBuild = currentBuild } -} - -export let helper: Helper - -export function setHelper(helperInstance: Helper) { - helper = helperInstance -} -export function createMetaJson(root: string): string[] { - const execSync = child.execSync - console.log('Run number: ' + helper.currentBuild.runNumber) - 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 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 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] - if ( - path.length > 3 && - ownerRaw.indexOf(' @') > -1 && - pom.startsWith(path) - ) { - owners.push(ownerRaw.split(' ')[1]) - reviewers.push(ownerRaw.split(' ')[1]) + 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: {[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) + ) } - 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) - ) } + return ret } - return ret } From 1bc237c625326f6d67b3d6b2c312650eb58bd1f2 Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Tue, 22 Nov 2022 17:07:46 +0100 Subject: [PATCH 04/14] Added start and end --- dist/index.js | 27 +++++++++++++++++++++++++-- src/main.ts | 2 +- src/se.ts | 38 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5f46655f6..7314d31c3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13603,8 +13603,9 @@ var external_fs_ = __webpack_require__(747); class se_Helper { - constructor(currentBuild) { + constructor(currentBuild, github) { this.currentBuild = currentBuild; + this.github = github; } createMetaJson(root) { const execSync = external_child_process_.execSync; @@ -13683,6 +13684,28 @@ class se_Helper { } 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, check_run_id, conclusion) { + const result = await this.github.rest.checks.create({ + owner: this.currentBuild.repo.owner, + repo: this.currentBuild.repo.repo, + name: name, + check_run_id: check_run_id, + head_sha: this.currentBuild.sha, + status: 'completed', + conclusion: conclusion + }); + return result; + } } // EXTERNAL MODULE: external "path" @@ -13746,7 +13769,7 @@ async function main() { 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); + 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, diff --git a/src/main.ts b/src/main.ts index 25a31ffd4..31573c59d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -46,7 +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) + 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 f9f3e166a..9f5ba777d 100644 --- a/src/se.ts +++ b/src/se.ts @@ -1,12 +1,18 @@ import {context} from '@actions/github' +import {GitHub} from '@actions/github/lib/utils' import * as child from 'child_process' import * as fs from 'fs' export class Helper { - public currentBuild: typeof context + currentBuild: typeof context + github: InstanceType - public constructor(currentBuild: typeof context) { + public constructor( + currentBuild: typeof context, + github: InstanceType + ) { this.currentBuild = currentBuild + this.github = github } public createMetaJson(root: string) { @@ -98,4 +104,32 @@ export class Helper { } 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, + check_run_id: string, + conclusion: string + ) { + const result = await this.github.rest.checks.create({ + owner: this.currentBuild.repo.owner, + repo: this.currentBuild.repo.repo, + name: name, + check_run_id: check_run_id, + head_sha: this.currentBuild.sha, + status: 'completed', + conclusion: conclusion + }) + return result + } } From 24fa723078dc8596313637d65da2b414ac31aaeb Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Wed, 23 Nov 2022 08:18:30 +0100 Subject: [PATCH 05/14] Changed names --- dist/index.js | 6 +++--- src/se.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7314d31c3..e4cc20276 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13694,15 +13694,15 @@ class se_Helper { }); return result; } - async completeCheck(name, check_run_id, conclusion) { + async completeCheck(name, id, conclusionString) { const result = await this.github.rest.checks.create({ owner: this.currentBuild.repo.owner, repo: this.currentBuild.repo.repo, name: name, - check_run_id: check_run_id, + check_run_id: id, head_sha: this.currentBuild.sha, status: 'completed', - conclusion: conclusion + conclusion: conclusionString }); return result; } diff --git a/src/se.ts b/src/se.ts index 9f5ba777d..b4e6e60c6 100644 --- a/src/se.ts +++ b/src/se.ts @@ -118,17 +118,17 @@ export class Helper { public async completeCheck( name: string, - check_run_id: string, - conclusion: string + id: string, + conclusionString: string ) { const result = await this.github.rest.checks.create({ owner: this.currentBuild.repo.owner, repo: this.currentBuild.repo.repo, name: name, - check_run_id: check_run_id, + check_run_id: id, head_sha: this.currentBuild.sha, status: 'completed', - conclusion: conclusion + conclusion: conclusionString }) return result } From 36c4d018eac45535ff97fb0dc7a8133d57c84f91 Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Wed, 23 Nov 2022 08:26:24 +0100 Subject: [PATCH 06/14] Changed to update --- dist/index.js | 2 +- src/se.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index e4cc20276..c5e4d7fae 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13695,7 +13695,7 @@ class se_Helper { return result; } async completeCheck(name, id, conclusionString) { - const result = await this.github.rest.checks.create({ + const result = await this.github.rest.checks.update({ owner: this.currentBuild.repo.owner, repo: this.currentBuild.repo.repo, name: name, diff --git a/src/se.ts b/src/se.ts index b4e6e60c6..96a2ef381 100644 --- a/src/se.ts +++ b/src/se.ts @@ -121,7 +121,7 @@ export class Helper { id: string, conclusionString: string ) { - const result = await this.github.rest.checks.create({ + const result = await this.github.rest.checks.update({ owner: this.currentBuild.repo.owner, repo: this.currentBuild.repo.repo, name: name, From 80e7869b2ddd3bcbdfb737e79f8d6309270a2682 Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Wed, 23 Nov 2022 08:58:54 +0100 Subject: [PATCH 07/14] Added unused --- dist/index.js | 1 + src/se.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/index.js b/dist/index.js index c5e4d7fae..20a4bcc88 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13614,6 +13614,7 @@ class se_Helper { shell: '/bin/bash' }); console.log(xmllint.toString()); + const x = '22'; const command = `#!/bin/bash cd ` + root + diff --git a/src/se.ts b/src/se.ts index 96a2ef381..41f1a2a47 100644 --- a/src/se.ts +++ b/src/se.ts @@ -22,6 +22,7 @@ export class Helper { shell: '/bin/bash' }) console.log(xmllint.toString()) + const x = '22' const command = `#!/bin/bash cd ` + From d226a0fe29f0a9d6d3dd555df5a874d05bf194da Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Wed, 23 Nov 2022 09:17:09 +0100 Subject: [PATCH 08/14] Reverted test change --- README.md | 16 ++++++++++------ dist/index.js | 1 - src/se.ts | 1 - 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8651ae88c..c14b92279 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,16 @@ 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 + - `startCheck` Helper method to create a check without annotations + - `completeCheck` Helper method to finish a check without annotations + +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 20a4bcc88..c5e4d7fae 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13614,7 +13614,6 @@ class se_Helper { shell: '/bin/bash' }); console.log(xmllint.toString()); - const x = '22'; const command = `#!/bin/bash cd ` + root + diff --git a/src/se.ts b/src/se.ts index 41f1a2a47..96a2ef381 100644 --- a/src/se.ts +++ b/src/se.ts @@ -22,7 +22,6 @@ export class Helper { shell: '/bin/bash' }) console.log(xmllint.toString()) - const x = '22' const command = `#!/bin/bash cd ` + From b17e8805d3082f948511e7f012445c046bc248a6 Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Wed, 23 Nov 2022 12:44:11 +0100 Subject: [PATCH 09/14] Extracted poms --- dist/index.js | 55 +++++++++++++++++++++++++++++----------------- src/se.ts | 60 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 74 insertions(+), 41 deletions(-) diff --git a/dist/index.js b/dist/index.js index c5e4d7fae..2007ba4b5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13607,13 +13607,8 @@ class se_Helper { this.currentBuild = currentBuild; this.github = github; } - createMetaJson(root) { + listPoms(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 command = `#!/bin/bash cd ` + root + @@ -13626,20 +13621,39 @@ class se_Helper { 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 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); + 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 reviewers = []; for (const ownerRaw of ownersFile.split('\n')) { const path = ownerRaw.split(' ')[0]; if (path.length > 3 && ownerRaw.indexOf(' @') > -1 && - pom.startsWith(path)) { + pomEntity['pom'].startsWith(path)) { owners.push(ownerRaw.split(' ')[1]); reviewers.push(ownerRaw.split(' ')[1]); } @@ -13649,7 +13663,7 @@ class se_Helper { root + ` xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` + - pom + + pomEntity['pom'] + ` `; const aid = `#!/bin/bash @@ -13657,7 +13671,7 @@ class se_Helper { root + ` xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` + - pom + + pomEntity['pom'] + ` `; const groupId = execSync(gid, { shell: '/bin/bash' }).toString(); @@ -13665,21 +13679,22 @@ class se_Helper { const artifactId = execSync(aid, { shell: '/bin/bash' }).toString(); console.log(artifactId); const meta = {}; - meta['manifestSource'] = pom.replace('/pom.xml', '').substring(1); + meta['manifestSource'] = pomEntity['path']; meta['manifestTarget'] = 'helm-chart/components/charts/' + - name + + pomEntity['name'] + '/' + - name + + pomEntity['name'] + '-deployment/templates/'; meta['owners'] = owners; meta['reviewers'] = reviewers; - meta['branchName'] = name + '-deployment'; + meta['branchName'] = pomEntity['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)); + ret.push(pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1)); + Object(external_fs_.writeFileSync)(root + + pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1), JSON.stringify(meta)); } } return ret; diff --git a/src/se.ts b/src/se.ts index 96a2ef381..43cec3071 100644 --- a/src/se.ts +++ b/src/se.ts @@ -15,13 +15,8 @@ export class Helper { this.github = github } - public createMetaJson(root: string) { + public listPoms(root: string): {[key: string]: 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 command = `#!/bin/bash cd ` + @@ -33,17 +28,37 @@ export class Helper { ` const output = execSync(command, {shell: '/bin/bash'}) console.log(output.toString()) - const ret: string[] = [] + 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 + } + + 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 .readFileSync(root + '.github/CODEOWNERS', 'utf8') .toString() - for (const pomRaw of poms.split('\n')) { - const pom = pomRaw.replace('./', '/') - const name = pom.split('/')[2] + for (const pomEntity of poms) { if ( - pom.startsWith('/components') && - pom.indexOf(name + '-deployment/') > -1 + pomEntity['pom'].startsWith('/components') && + pomEntity['pom'].indexOf(name + '-deployment/') > -1 ) { const owners = [] const reviewers = [] @@ -53,7 +68,7 @@ export class Helper { if ( path.length > 3 && ownerRaw.indexOf(' @') > -1 && - pom.startsWith(path) + pomEntity['pom'].startsWith(path) ) { owners.push(ownerRaw.split(' ')[1]) reviewers.push(ownerRaw.split(' ')[1]) @@ -65,7 +80,7 @@ export class Helper { root + ` xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` + - pom + + pomEntity['pom'] + ` ` const aid = @@ -74,7 +89,7 @@ export class Helper { root + ` xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` + - pom + + pomEntity['pom'] + ` ` const groupId = execSync(gid, {shell: '/bin/bash'}).toString() @@ -82,22 +97,25 @@ export class Helper { 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['manifestSource'] = pomEntity['path'] meta['manifestTarget'] = 'helm-chart/components/charts/' + - name + + pomEntity['name'] + '/' + - name + + pomEntity['name'] + '-deployment/templates/' meta['owners'] = owners meta['reviewers'] = reviewers - meta['branchName'] = name + '-deployment' + meta['branchName'] = pomEntity['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)) + ret.push( + pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1) + ) fs.writeFileSync( - root + pomRaw.replace('/pom.xml', '/meta.json').substring(1), + root + + pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1), JSON.stringify(meta) ) } From cc9cbe651c414997275ab44373462f4587edcdd6 Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Wed, 23 Nov 2022 12:49:08 +0100 Subject: [PATCH 10/14] fixed missing name --- dist/index.js | 2 +- src/se.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2007ba4b5..958776937 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13646,7 +13646,7 @@ class se_Helper { .toString(); for (const pomEntity of poms) { if (pomEntity['pom'].startsWith('/components') && - pomEntity['pom'].indexOf(name + '-deployment/') > -1) { + pomEntity['pom'].indexOf(pomEntity['name'] + '-deployment/') > -1) { const owners = []; const reviewers = []; for (const ownerRaw of ownersFile.split('\n')) { diff --git a/src/se.ts b/src/se.ts index 43cec3071..2c20d86ba 100644 --- a/src/se.ts +++ b/src/se.ts @@ -58,7 +58,7 @@ export class Helper { for (const pomEntity of poms) { if ( pomEntity['pom'].startsWith('/components') && - pomEntity['pom'].indexOf(name + '-deployment/') > -1 + pomEntity['pom'].indexOf(pomEntity['name'] + '-deployment/') > -1 ) { const owners = [] const reviewers = [] From c8f9315e0c7ff7a9cb6cd34780a17f1b9e020ce7 Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Wed, 23 Nov 2022 12:56:03 +0100 Subject: [PATCH 11/14] Fixed pomRaw reference --- dist/index.js | 4 ++-- src/se.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 958776937..f44618829 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13692,9 +13692,9 @@ class se_Helper { meta['mavenGroupId'] = groupId.trim(); meta['mavenArtifactId'] = artifactId.trim(); console.log(JSON.stringify(meta)); - ret.push(pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1)); + ret.push(pomEntity['raw'].replace('/pom.xml', '/meta.json').substring(1)); Object(external_fs_.writeFileSync)(root + - pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1), JSON.stringify(meta)); + pomEntity['raw'].replace('/pom.xml', '/meta.json').substring(1), JSON.stringify(meta)); } } return ret; diff --git a/src/se.ts b/src/se.ts index 2c20d86ba..16d077988 100644 --- a/src/se.ts +++ b/src/se.ts @@ -111,11 +111,11 @@ export class Helper { meta['mavenArtifactId'] = artifactId.trim() console.log(JSON.stringify(meta)) ret.push( - pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1) + pomEntity['raw'].replace('/pom.xml', '/meta.json').substring(1) ) fs.writeFileSync( root + - pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1), + pomEntity['raw'].replace('/pom.xml', '/meta.json').substring(1), JSON.stringify(meta) ) } From 2a9db83c42131fcd1965a81d2e4034f8ecddf5a4 Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Wed, 23 Nov 2022 13:50:13 +0100 Subject: [PATCH 12/14] Updated readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index c14b92279..4218bf0ed 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,15 @@ The following arguments will be provided: - `require` A proxy wrapper around the normal Node.js `require` to enable - `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 From 085e38d2d350a43668784304194619eddf4d5d7c Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Fri, 9 Dec 2022 11:59:59 +0100 Subject: [PATCH 13/14] Added error handling --- dist/index.js | 20 ++++++++++++++++---- src/se.ts | 19 +++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index f44618829..bdcd7e1e0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13636,10 +13636,22 @@ class se_Helper { 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()); + try { + const xmllint = execSync('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') diff --git a/src/se.ts b/src/se.ts index 16d077988..cd54d8a87 100644 --- a/src/se.ts +++ b/src/se.ts @@ -46,10 +46,21 @@ export class Helper { 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()) + try { + const xmllint = execSync('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: string[] = [] const poms = this.listPoms(root) const ownersFile = fs From b10f6d2a4437b61d97cd0c8855aa746b7971b160 Mon Sep 17 00:00:00 2001 From: Jonas Bovin Date: Fri, 9 Dec 2022 12:28:47 +0100 Subject: [PATCH 14/14] Run apt-get first --- dist/index.js | 2 +- src/se.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index bdcd7e1e0..c98fd9bf7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13637,7 +13637,7 @@ class se_Helper { const execSync = external_child_process_.execSync; console.log('Run number: ' + this.currentBuild.runNumber); try { - const xmllint = execSync('sudo apt install libxml2-utils', { + const xmllint = execSync('sudo apt-get update; sudo apt install libxml2-utils', { shell: '/bin/bash' }); console.log(xmllint.toString()); diff --git a/src/se.ts b/src/se.ts index cd54d8a87..4fb91dacb 100644 --- a/src/se.ts +++ b/src/se.ts @@ -47,9 +47,12 @@ export class Helper { const execSync = child.execSync console.log('Run number: ' + this.currentBuild.runNumber) try { - const xmllint = execSync('sudo apt install libxml2-utils', { - shell: '/bin/bash' - }) + const xmllint = execSync( + 'sudo apt-get update; sudo apt install libxml2-utils', + { + shell: '/bin/bash' + } + ) console.log(xmllint.toString()) } catch (err) {