mirror of
https://github.com/actions/github-script.git
synced 2026-04-08 07:00:05 +00:00
Changed all to be helper
This commit is contained in:
parent
b1c1024769
commit
e4f7f1688c
4 changed files with 344 additions and 358 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<void> {
|
|||
|
||||
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(
|
||||
|
|
|
|||
174
src/se.ts
174
src/se.ts
|
|
@ -8,100 +8,94 @@ export class Helper {
|
|||
public constructor(currentBuild: typeof context) {
|
||||
this.currentBuild = currentBuild
|
||||
}
|
||||
}
|
||||
|
||||
export let helper: 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())
|
||||
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]
|
||||
|
||||
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]
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue