chore: add azure-pipeline.yml

This commit is contained in:
calebboyd
2019-04-15 17:12:41 -05:00
parent 9486399cec
commit 7bfdc39700
4 changed files with 126 additions and 1 deletions
+23
View File
@@ -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
+1
View File
@@ -9,6 +9,7 @@
"Caleb Boyd <caleb.boyd@hotmail.com>"
],
"scripts": {
"ci:build": "ts-node tasks/build",
"asset-compile": "ts-node tasks/asset-compile",
"test": "mocha",
"lint": "tslint \"{src,plugins,tasks}/**/*.ts\" --fix",
+2 -1
View File
@@ -51,7 +51,8 @@ export default async function cli(compiler: NexeCompiler, next: () => Promise<vo
: inputFileLogOutput
}' written to: ${outputFileLogOutput}`
)
res(compiler.quit())
compiler.quit()
res(output)
}
})
})
+100
View File
@@ -0,0 +1,100 @@
import * as nexe from '../lib/nexe'
import { getUnBuiltReleases, getLatestGitRelease } from '../lib/releases'
import { runDockerBuild } from './docker'
import { getTarget, targetsEqual, NexeTarget } from '../lib/target'
import { pathExistsAsync, readFileAsync, execFileAsync } from '../lib/util'
import got = require('got')
const env = process.env,
isPullRequest = env.BUILD_REASON === 'PullRequest',
isWindows = process.platform === 'win32',
isMac = process.platform === 'darwin',
headers = {
Authorization: 'token ' + env.GITHUB_TOKEN,
'User-Agent': 'nexe (https://www.npmjs.com/package/nexe)'
}
if (require.main === module) {
if (!isPullRequest) {
build().catch(x => {
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
})
}