|
|
@ -6,13 +6,12 @@ import { mkdirsSync, remove } from "fs-extra"; |
|
|
|
import * as JSONParse from "json-parse-safe"; |
|
|
|
import * as JSONParse from "json-parse-safe"; |
|
|
|
import { join } from "path"; |
|
|
|
import { join } from "path"; |
|
|
|
|
|
|
|
|
|
|
|
import settings from "../settings"; |
|
|
|
|
|
|
|
import { gitLoader } from "./git/loader"; |
|
|
|
import { gitLoader } from "./git/loader"; |
|
|
|
import { createGithub } from "./github-wrapper"; |
|
|
|
import { createGithub } from "./github-wrapper"; |
|
|
|
import { send as sendMail } from "./mail-sender"; |
|
|
|
import { send as sendMail } from "./mail-sender"; |
|
|
|
import { writeReport } from "./report-processor"; |
|
|
|
import { writeReport } from "./report-processor"; |
|
|
|
import { processTask } from "./task-processor"; |
|
|
|
import { processTask } from "./task-processor"; |
|
|
|
import { ReportResult } from "./types"; |
|
|
|
import { ReportResult, Settings } from "./types"; |
|
|
|
|
|
|
|
|
|
|
|
const codePostfix = ""; |
|
|
|
const codePostfix = ""; |
|
|
|
const mailLazinessLevel = 1000; |
|
|
|
const mailLazinessLevel = 1000; |
|
|
@ -36,7 +35,7 @@ const createBuildDoneMessage = (isSuccess, name) => { |
|
|
|
return `Build failed for ${name}`; |
|
|
|
return `Build failed for ${name}`; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const notifyStatus = (options, notifyStatusCallback) => { |
|
|
|
const notifyStatus = (settings: Settings, options, notifyStatusCallback) => { |
|
|
|
const status = { |
|
|
|
const status = { |
|
|
|
description: String(options.description || "").substr(0, maxDescriptionLength), |
|
|
|
description: String(options.description || "").substr(0, maxDescriptionLength), |
|
|
|
owner: options.owner, |
|
|
|
owner: options.owner, |
|
|
@ -46,7 +45,7 @@ const notifyStatus = (options, notifyStatusCallback) => { |
|
|
|
target_url: `${settings.siteRoot}status/${options.owner}/${options.reponame}/${options.hash}`, |
|
|
|
target_url: `${settings.siteRoot}status/${options.owner}/${options.reponame}/${options.hash}`, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
createGithub(options.owner).repos.createStatus(status, (createStatusErr) => { |
|
|
|
createGithub(settings, options.owner).repos.createStatus(status, (createStatusErr) => { |
|
|
|
if (createStatusErr) { |
|
|
|
if (createStatusErr) { |
|
|
|
console.log(`Error while creating status: ${createStatusErr}`); |
|
|
|
console.log(`Error while creating status: ${createStatusErr}`); |
|
|
|
console.log(status); |
|
|
|
console.log(status); |
|
|
@ -66,17 +65,17 @@ const wrapGitLoader = (skipGitLoader) => { |
|
|
|
return (gitLoaderOptions, gitLoaderCallback) => process.nextTick(gitLoaderCallback); |
|
|
|
return (gitLoaderOptions, gitLoaderCallback) => process.nextTick(gitLoaderCallback); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export const build = (options, buildCallback) => { |
|
|
|
export const build = (settings: Settings, options, buildCallback) => { |
|
|
|
const url = options.url; |
|
|
|
const url = options.url; |
|
|
|
const owner = options.owner; |
|
|
|
const owner = options.owner; |
|
|
|
const reponame = options.reponame; |
|
|
|
const reponame = options.reponame; |
|
|
|
const rev = options.rev; |
|
|
|
const rev = options.rev; |
|
|
|
const branch = options.branch; |
|
|
|
const branch = options.branch; |
|
|
|
const skipGitLoader = options.skipGitLoader; |
|
|
|
const skipGitLoader = options.skipGitLoader; |
|
|
|
const local = join(options.app.get("gitpath"), "r"); |
|
|
|
const local = join(settings.gitpath, "r"); |
|
|
|
const tmp = join(options.app.get("tmpcodepath"), rev.substr(0, maxTmpcodepathLength)); |
|
|
|
const tmp = join(settings.tmpcodepath, rev.substr(0, maxTmpcodepathLength)); |
|
|
|
const exported = tmp + codePostfix; |
|
|
|
const exported = tmp + codePostfix; |
|
|
|
const release = join(options.app.get("releasepath"), owner, reponame, branch, rev); |
|
|
|
const release = join(settings.releasepath, owner, reponame, branch, rev); |
|
|
|
const statusQueue = queue((task: (callback: any) => void, queueCallback) => task(queueCallback), 1); |
|
|
|
const statusQueue = queue((task: (callback: any) => void, queueCallback) => task(queueCallback), 1); |
|
|
|
const actualGitLoader = wrapGitLoader(skipGitLoader); |
|
|
|
const actualGitLoader = wrapGitLoader(skipGitLoader); |
|
|
|
const date = new Date(); |
|
|
|
const date = new Date(); |
|
|
@ -87,7 +86,7 @@ export const build = (options, buildCallback) => { |
|
|
|
const version = `${versionMajor}.${versionMinor}.${versionBuild}.${versionRev}`; |
|
|
|
const version = `${versionMajor}.${versionMinor}.${versionBuild}.${versionRev}`; |
|
|
|
const versionInfo = `${version}; built from ${rev}; repository: ${owner}/${reponame}; branch: ${branch}`; |
|
|
|
const versionInfo = `${version}; built from ${rev}; repository: ${owner}/${reponame}; branch: ${branch}`; |
|
|
|
|
|
|
|
|
|
|
|
statusQueue.push((queueCallback) => notifyStatus({ |
|
|
|
statusQueue.push((queueCallback) => notifyStatus(settings, { |
|
|
|
description: "Preparing to build...", |
|
|
|
description: "Preparing to build...", |
|
|
|
hash: rev, |
|
|
|
hash: rev, |
|
|
|
owner, |
|
|
|
owner, |
|
|
@ -97,9 +96,9 @@ export const build = (options, buildCallback) => { |
|
|
|
|
|
|
|
|
|
|
|
mkdirsSync(release); |
|
|
|
mkdirsSync(release); |
|
|
|
|
|
|
|
|
|
|
|
writeFileSync(join(options.app.get("releasepath"), owner, reponame, branch, "latest.id"), rev); |
|
|
|
writeFileSync(join(settings.releasepath, owner, reponame, branch, "latest.id"), rev); |
|
|
|
mkdirsSync(join(options.app.get("releasepath"), owner, reponame, "$revs")); |
|
|
|
mkdirsSync(join(settings.releasepath, owner, reponame, "$revs")); |
|
|
|
writeFileSync(join(options.app.get("releasepath"), owner, reponame, "$revs", `${rev}.branch`), branch); |
|
|
|
writeFileSync(join(settings.releasepath, owner, reponame, "$revs", `${rev}.branch`), branch); |
|
|
|
|
|
|
|
|
|
|
|
const createErrorMessageForMail = (doneErr) => { |
|
|
|
const createErrorMessageForMail = (doneErr) => { |
|
|
|
if (!doneErr) { |
|
|
|
if (!doneErr) { |
|
|
@ -127,7 +126,7 @@ export const build = (options, buildCallback) => { |
|
|
|
|
|
|
|
|
|
|
|
writeReport(release, doneErr, result, (writeErr) => { |
|
|
|
writeReport(release, doneErr, result, (writeErr) => { |
|
|
|
statusQueue.push((queueCallback) => parallel([ |
|
|
|
statusQueue.push((queueCallback) => parallel([ |
|
|
|
(parallelCallback) => notifyStatus({ |
|
|
|
(parallelCallback) => notifyStatus(settings, { |
|
|
|
description: errorMessage || warnMessage || infoMessage || "Success", |
|
|
|
description: errorMessage || warnMessage || infoMessage || "Success", |
|
|
|
hash: rev, |
|
|
|
hash: rev, |
|
|
|
owner, |
|
|
|
owner, |
|
|
@ -191,7 +190,7 @@ export const build = (options, buildCallback) => { |
|
|
|
return done("MBSMalformed"); |
|
|
|
return done("MBSMalformed"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return processTask(value, { |
|
|
|
return processTask(settings, value, { |
|
|
|
branch, |
|
|
|
branch, |
|
|
|
exported, |
|
|
|
exported, |
|
|
|
owner, |
|
|
|
owner, |
|
|
|