diff --git a/.travis.yml b/.travis.yml index f3c92a8..530b4e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,9 @@ +os: osx language: node_js node_js: - '6' script: npm run nexe-build env: - global: - secure: LyC6djYqPfPKz5gHILES9JmSRxQ+ntKOcoaZNM5WID0+gogUoXZBhcmmtvq9RnMpFZN3pYujY6LB5iy7QS2seGjg+feyewNKI30yIK6N9ulJyZZKmrJVDdRx4wvl8YVTkttjcJFkanDGa6zRvFfFDKx/iIdcWLEpnqR/WO1ppf8= + - secure: LyC6djYqPfPKz5gHILES9JmSRxQ+ntKOcoaZNM5WID0+gogUoXZBhcmmtvq9RnMpFZN3pYujY6LB5iy7QS2seGjg+feyewNKI30yIK6N9ulJyZZKmrJVDdRx4wvl8YVTkttjcJFkanDGa6zRvFfFDKx/iIdcWLEpnqR/WO1ppf8= +notifications: + email: false diff --git a/.vscode/settings.json b/.vscode/settings.json index cc468c9..21d9a88 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "prettier.semi": false, "prettier.singleQuote": true, "prettier.typescriptEnable": ["typescript"], + "editor.trimAutoWhitespace": true, "files.exclude": { "**/.git": true, "**/.svn": true, diff --git a/circle.yml b/circle.yml index 3c14fff..3590eff 100644 --- a/circle.yml +++ b/circle.yml @@ -1,3 +1,8 @@ +machine: + node: + version: 6.11.2 + services: + - docker test: override: - npm run nexe-build diff --git a/src/compiler.ts b/src/compiler.ts index 2564272..c820bc6 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -135,7 +135,11 @@ export class NexeCompiler { } private async _fetchPrebuiltBinaryAsync(target: NexeTarget) { - const githubRelease = await getLatestGitRelease() + const githubRelease = await getLatestGitRelease({ + headers: { + 'User-Agent': 'nexe (https://www.npmjs.com/package/nexe)' + } + }) const assetName = target.toString() const asset = githubRelease.assets.find(x => x.name === assetName) diff --git a/tasks/build.ts b/tasks/build.ts index c1ae17d..1f5aac9 100644 --- a/tasks/build.ts +++ b/tasks/build.ts @@ -12,13 +12,16 @@ import got = require('got') const env = process.env, branchName = env.CIRCLE_BRANCH || env.APPVEYOR_REPO_BRANCH || env.TRAVIS_BRANCH || '', isScheduled = Boolean(env.APPVEYOR_SCHEDULED_BUILD || env.NEXE_TRIGGERED), - isLinux = Boolean(env.TRAVIS), + isLinux = Boolean(env.CIRCLECI), isWindows = Boolean(env.APPVEYOR), - isMac = Boolean(env.CIRCLECI), + isMac = Boolean(env.TRAVIS), isPullRequest = Boolean(env.CIRCLE_PR_NUMBER) || Boolean(env.APPVEYOR_PULL_REQUEST_NUMBER) || Boolean(env.TRAVIS_PULL_REQUEST_BRANCH), - headers = { 'Authorization': 'token ' + env.GITHUB_TOKEN } + headers = { + 'Authorization': 'token ' + env.GITHUB_TOKEN, + 'User-Agent': 'nexe (https://www.npmjs.com/package/nexe)' + } if (require.main === module) { if (!isPullRequest) { @@ -57,7 +60,7 @@ async function build () { options = { empty: true, build: true, - target, //FIXME + target, output } @@ -78,7 +81,8 @@ async function build () { body: await readFileAsync(output), headers: { 'Authorization': 'token ' + env.GITHUB_TOKEN, - 'Content-Type': 'application/octet-stream' + 'Content-Type': 'application/octet-stream', + 'User-Agent': 'nexe (https://www.npmjs.com/package/nexe)' } }) console.log(target + ' uploaded.') diff --git a/tasks/ci.ts b/tasks/ci.ts index e4ddd7c..57ee3a1 100644 --- a/tasks/ci.ts +++ b/tasks/ci.ts @@ -3,7 +3,7 @@ import got = require('got') import * as assert from 'assert' const { env } = process -export function triggerDockerBuild(release: NexeTarget, branch: string) { +export function triggerMacBuild(release: NexeTarget, branch: string) { assert.ok(env.TRAVIS_TOKEN) const travis = `https://api.travis-ci.org/repo/nexe%2Fnexe/requests` return got(travis, { @@ -14,7 +14,7 @@ export function triggerDockerBuild(release: NexeTarget, branch: string) { config: { merge_mode: 'deep_merge', env: { - NEXE_VERSION: release + NEXE_VERSION: release.toString() } } } @@ -26,7 +26,7 @@ export function triggerDockerBuild(release: NexeTarget, branch: string) { }) } -export function triggerMacBuild (release: NexeTarget, branch: string) { +export function triggerDockerBuild (release: NexeTarget, branch: string) { assert.ok(env.CIRCLE_TOKEN) const circle = `https://circleci.com/api/v1.1/project/github/nexe/nexe/tree/${branch}?circle-token=${env.CIRCLE_TOKEN}` return got(circle, { diff --git a/tasks/docker.ts b/tasks/docker.ts index 952fdee..77721d4 100644 --- a/tasks/docker.ts +++ b/tasks/docker.ts @@ -1,32 +1,73 @@ import { NexeTarget } from '../src/target' -import { writeFileAsync } from '../src/util' -import exec = require('execa') +import { writeFileAsync, readFileAsync } from '../src/util' +import { spawn } from 'child_process' +import got = require('got') +import { createWriteStream, WriteStream } from 'fs' -function alpine (target: NexeTarget, nexeVersion: string) { - const version = target.version +function alpine (target: NexeTarget, nexeVersion: string) { return ` -FROM i386/alpine:3.6 +FROM i386/alpine:3.4 RUN apk add --no-cache curl make gcc g++ binutils-gold python linux-headers paxctl libgcc libstdc++ git vim tar gzip wget +ENV NODE_VERSION=${target.version} +ENV NEXE_VERSION=beta WORKDIR / -RUN curl -sSL https://nodejs.org/dist/v${version}/node-v${version}.tar.gz | tar -xz && \ - cd /node-v${version} && \ + +RUN curl -sSL https://nodejs.org/dist/v\${NODE_VERSION}/node-v\${NODE_VERSION}.tar.gz | tar -xz && \ + cd /node-v\${NODE_VERSION} && \ ./configure --prefix=/usr --fully-static && \ - make -j$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \ + make -j$(getconf _NPROCESSORS_ONLN) && \ make install && \ paxctl -cm /usr/bin/node -RUN mkdir nexe_temp && mv node-v${version} nexe_temp/${version} -RUN npm i nexe@beta -g -ENV NEXE_TEMP=/nexe_temp +RUN mkdir /nexe_temp && mv node-v\${NODE_VERSION} /nexe_temp/\${NODE_VERSION} && \ + npm install -g nexe@\${NEXE_VERSION} && \ + nexe --build --empty --temp /nexe_temp -c="--fully-static" -o out +`.trim() +} -RUN nexe --empty -c="--fully-static" -o /nexe-out`.trim() +export async function runAsync (command: string, output: WriteStream) { + const commands = command.split(/\r?\n/) + .filter(x => x.trim()) + .map(x => x.trim().split(' ')) + const sequence = Promise.resolve() + for (const command of commands) { + await new Promise((resolve, reject) => { + const cp = spawn(command.shift() as string, command) + cp.stderr.pipe(output) + cp.stdout.pipe(output) + const close = function (this: any, e: Error) { + this.kill() + e ? reject(e) : resolve() + } + cp.on('error', (e) => { + output.write(e.stack) + }) + .on('close', close) + .on('exit', close) + }) + } } export async function runAlpineBuild (target: NexeTarget, nexeVersion: string) { await writeFileAsync('Dockerfile', alpine(target, nexeVersion)) - const option = { stido: 'inherit' } as any - await exec('docker', ['build', '-t', 'nexe-alpine', '.'], option) - await exec('docker', ['run', '--name', 'nexe', 'nexe-alpine'], option) - await exec('docker', ['cp', 'nexe:/nexe-out', 'out'], option) - await exec('docker', ['rm', 'nexe'], option) + const outFilename = 'nexe-alpine-build-log.txt' + const output = createWriteStream(outFilename) + try { + await runAsync(` + docker build -t nexe-alpine . + docker run -d --name nexe nexe-alpine sh + docker cp nexe:/out out + docker rm nexe + `, output) + } catch(e) { + console.log(e) + } finally { + output.close() + await got(`https://transfer.sh/${Math.random().toString(36).substring(2)}.txt`, { + body: await readFileAsync(outFilename), + method: 'PUT' + }) + .then(x => console.log(x.body)) + .catch(e => console.log('Error posting log', e)) + } }