From 7bfdc39700314fee1db9348099529fbe0aa09fec Mon Sep 17 00:00:00 2001 From: calebboyd Date: Mon, 15 Apr 2019 17:12:41 -0500 Subject: [PATCH] chore: add azure-pipeline.yml --- azure-pipelines.yml | 23 ++++++++++ package.json | 1 + src/steps/cli.ts | 3 +- tasks/build.ts | 100 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 azure-pipelines.yml create mode 100644 tasks/build.ts diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..14bcedf --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,23 @@ +strategy: + matrix: + linux: + imageName: 'ubuntu-16.04' + mac: + imageName: 'macos-10.13' + windows: + imageName: 'vs2017-win2016' + alpine: + imageName: 'ubuntu-16.04' + +pool: + vmImage: $(imageName) + +steps: +- task: NodeTool@0 + inputs: + versionSpec: '10.x' +- script: | + node -p "process.env.BUILD_REASON" + npm install + npm test + npm run ci:build diff --git a/package.json b/package.json index 0d13477..0c8c220 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "Caleb Boyd " ], "scripts": { + "ci:build": "ts-node tasks/build", "asset-compile": "ts-node tasks/asset-compile", "test": "mocha", "lint": "tslint \"{src,plugins,tasks}/**/*.ts\" --fix", diff --git a/src/steps/cli.ts b/src/steps/cli.ts index 69a62ed..6f80e15 100644 --- a/src/steps/cli.ts +++ b/src/steps/cli.ts @@ -51,7 +51,8 @@ export default async function cli(compiler: NexeCompiler, next: () => Promise { + console.error(x) + process.exit(1) + }) + } +} + +async function build() { + if (isPullRequest) { + return + } + const releases = await getUnBuiltReleases({ headers }) + if (!releases.length) { + return + } + const windowsBuild = releases.find(x => x.platform === 'windows'), + macBuild = releases.find(x => x.platform === 'mac'), + linuxOrAlpine = releases.find(x => x.platform === 'linux' || x.platform === 'alpine') + + let target: NexeTarget + + if (env.NEXE_VERSION) target = getTarget(env.NEXE_VERSION) + else if (isWindows) target = windowsBuild + else if (isMac) target = macBuild + else target = linuxOrAlpine + + if (!target) { + return console.log('Nothing to build...') + } + + const output = process.platform === 'win32' ? './out.exe' : './out', + options = { + mangle: false, + build: true, + target, + output + } + console.log('Building: ', target) + const stop = keepalive() + + if (['arm7l', 'arm6l', 'arm64', 'alpine'].includes(target.platform)) { + await runDockerBuild(target) + } else { + await nexe.compile(options) + } + stop() + if (await pathExistsAsync(output)) { + await assertNexeBinary(output) + const gitRelease = await getLatestGitRelease({ headers }), + unbuiltReleases = await getUnBuiltReleases({ headers }) + if (!unbuiltReleases.some(x => targetsEqual(x, target))) { + console.log(`${target} already uploaded.`) + return + } + await got(gitRelease.upload_url.split('{')[0], { + query: { name: target.toString() }, + body: await readFileAsync(output), + headers: { + ...headers, + 'Content-Type': 'application/octet-stream' + } + }).catch(reason => { + console.log(reason && reason.response && reason.response.body) + throw reason + }) + console.log(target + ' uploaded.') + } +} + +function keepalive() { + const keepalive = setInterval(() => console.log('Building...'), 300 * 1000) + return () => clearInterval(keepalive) +} + +function assertNexeBinary(file: string) { + return execFileAsync(file).catch(e => { + if (e && e.stack && e.stack.includes('Invalid Nexe binary')) { + return + } + throw e + }) +}