72 lines
2.4 KiB
JavaScript
72 lines
2.4 KiB
JavaScript
import { hostPlatform, targetArchs } from './system.js';
|
|
import { localPlace, remotePlace } from './places.js';
|
|
import { log, wasReported } from './log.js';
|
|
import { Cloud } from './cloud.js';
|
|
import build from './build.js';
|
|
import patchesJson from '../patches/patches.json';
|
|
import path from 'path';
|
|
import { verify } from './verify.js';
|
|
import { version } from '../package.json';
|
|
|
|
const cloud = new Cloud({ owner: 'zeit', repo: 'pkg-fetch' });
|
|
|
|
export function dontBuild (nodeVersion, targetPlatform, targetArch) {
|
|
// https://support.apple.com/en-us/HT201948
|
|
// don't disable macos-x86 because it is not possible
|
|
// to cross-compile for x86 from macos otherwise
|
|
const major = nodeVersion.match(/^v?(\d+)/)[1] | 0;
|
|
if (process.env.PKG_FETCH_ONLY_NODE7 &&
|
|
major !== 7) return true;
|
|
if (process.env.PKG_FETCH_EXCEPT_NODE7 &&
|
|
major === 7) return true;
|
|
// node 0.12 does not compile on arm
|
|
if (/^arm/.test(targetArch) &&
|
|
major === 0) return true;
|
|
// obstacles on freebsd x86 for node4
|
|
if (targetPlatform === 'freebsd' &&
|
|
targetArch === 'x86' &&
|
|
major < 6) return true;
|
|
if (targetPlatform === 'freebsd' &&
|
|
major < 4) return true;
|
|
if (targetPlatform === 'alpine' &&
|
|
(targetArch !== 'x64' ||
|
|
major < 6)) return true;
|
|
return false;
|
|
}
|
|
|
|
export async function main () {
|
|
if (!process.env.GITHUB_USERNAME) {
|
|
throw wasReported('No github credentials. Upload will fail!');
|
|
}
|
|
|
|
for (const nodeVersion in patchesJson) {
|
|
for (const targetArch of targetArchs) {
|
|
if (dontBuild(nodeVersion, hostPlatform, targetArch)) continue;
|
|
const local = localPlace({ from: 'built', arch: targetArch,
|
|
nodeVersion, platform: hostPlatform, version });
|
|
const short = path.basename(local);
|
|
log.info(`Building ${short}...`);
|
|
await build(nodeVersion, targetArch, local);
|
|
log.info(`Verifying ${short}...`);
|
|
await verify(local);
|
|
log.info(`Uploading ${short}...`);
|
|
const remote = remotePlace({ arch: targetArch,
|
|
nodeVersion, platform: hostPlatform, version });
|
|
try {
|
|
await cloud.upload(local, remote);
|
|
} catch (error) {
|
|
// TODO catch only network errors
|
|
if (!error.wasReported) log.error(error);
|
|
log.info('Meanwhile i will continue making binaries');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!module.parent) {
|
|
main().catch((error) => {
|
|
if (!error.wasReported) log.error(error);
|
|
process.exit(2);
|
|
});
|
|
}
|