From 994531d8bbfa62d849b65a5828f87f3b4c8983fa Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 6 Mar 2019 18:15:52 -0600 Subject: [PATCH] Add task for packaging release (#6) * Add task for packaging release * Modify package task to package a single binary This is so it can be used as part of the build/release script. * Package release as part of Travis deploy * Set platform env var * Add arch env var * Make version available to the code * Use tar for Linux and zip for Mac & Windows --- .gitignore | 1 + .travis.yml | 18 +++++++++++------- build/tasks.ts | 26 ++++++++++++++++++++++++++ packages/runner/src/runner.ts | 5 +++-- packages/server/scripts/nexe.js | 7 ++++--- packages/server/src/cli.ts | 2 +- packages/server/webpack.config.js | 2 +- scripts/webpack.general.config.js | 1 + 8 files changed, 48 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 647d88c5..9ced34fb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules dist out .DS_Store +release diff --git a/.travis.yml b/.travis.yml index 540780cf..8b6f956d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: node_js node_js: - 8.9.3 +env: + - VERSION="1.31.1-$TRAVIS_BUILD_NUMBER" matrix: include: - os: linux @@ -12,22 +14,24 @@ before_install: script: - scripts/build.sh before_deploy: -- export TRAVIS_TAG="1.31.1-$TRAVIS_BUILD_NUMBER" -- echo "$TRAVIS_TAG" "$TRAVIS_COMMIT" +- echo "$VERSION" "$TRAVIS_COMMIT" - git config --local user.name "$USER_NAME" - git config --local user.email "$USER_EMAIL" -- git tag "$TRAVIS_TAG" "$TRAVIS_COMMIT" +- git tag "$VERSION" "$TRAVIS_COMMIT" +- yarn task package "$VERSION" deploy: provider: releases file_glob: true draft: true - tag_name: $TRAVIS_TAG - target_commitish: $TRAVIS_COMMIT - name: $TRAVIS_TAG + tag_name: "$VERSION" + target_commitish: "$TRAVIS_COMMIT" + name: "$VERSION" skip_cleanup: true api_key: secure: YL/x24KjYjgYXPcJWk3FV7FGxI79Mh6gBECQEcdlf3fkLEoKFVgzHBoUNWrFPzyR4tgLyWNAgcpD9Lkme1TRWTom7UPjXcwMNyLcLa+uec7ciSAnYD9ntLTpiCuPDD1u0LtRGclSi/EHQ+F8YVq+HZJpXTsJeAmOmihma3GVbGKSZr+BRum+0YZSG4w+o4TOlYzw/4bLWS52MogZcwpjd+hemBbgXLuGU2ziKv2vEKCZFbEeA16II4x1WLI4mutDdCeh7+3aLzGLwDa49NxtsVYNjyNFF75JhCTCNA55e2YMiLz9Uq69IXe/mi5F7xUaFfhIqqLNyKBnKeEOzu3dYnc+8n3LjnQ+00PmkF05nx9kBn3UfV1kwQGh6QbyDmTtBP07rtUMyI14aeQqHjxsaVRdMnwj9Q2DjXRr8UDqESZF0rmK3pHCXS2fBhIzLE8tLVW5Heiba2pQRFMHMZW+KBE97FzcFh7is90Ait3T8enfcd/PWFPYoBejDAdjwxwOkezh5N5ZkYquEfDYuWrFi6zRFCktsruaAcA+xGtTf9oilBBzUqu8Ie+YFWH5me83xakcblJWdaW/D2rLJAJH3m6LFm8lBqyUgDX5t/etob6CpDuYHu5D1J3XINOj/+aLAcadq6qlh70PMZS3zYffUu3JlzaD2amlSHIT8b5YXFc= - file: packages/server/cli-* + file: + - release/*.tar.gz + - release/*.zip on: repo: codercom/code-server branch: master diff --git a/build/tasks.ts b/build/tasks.ts index 431fe502..0831fb5f 100644 --- a/build/tasks.ts +++ b/build/tasks.ts @@ -260,4 +260,30 @@ const ensurePatched = register("vscode:patch", async (runner) => { } }); +register("package", async (runner, releaseTag) => { + if (!releaseTag) { + throw new Error("Please specify the release tag."); + } + + const releasePath = path.resolve(__dirname, "../release"); + + const archiveName = `code-server-${releaseTag}-${os.platform()}-${os.arch()}`; + const archiveDir = path.join(releasePath, archiveName); + fse.removeSync(archiveDir); + fse.mkdirpSync(archiveDir); + + const binaryPath = path.join(__dirname, `../packages/server/cli-${os.platform()}-${os.arch()}`); + const binaryDestination = path.join(archiveDir, "code-server"); + fse.copySync(binaryPath, binaryDestination); + fs.chmodSync(binaryDestination, "755"); + ["README.md", "LICENSE"].forEach((fileName) => { + fse.copySync(path.resolve(__dirname, `../${fileName}`), path.join(archiveDir, fileName)); + }); + + runner.cwd = releasePath; + await os.platform() === "linux" + ? runner.execute("tar", ["-cvzf", `${archiveName}.tar.gz`, `${archiveName}`]) + : runner.execute("zip", ["-r", `${archiveName}.zip`, `${archiveName}`]); +}); + run(); diff --git a/packages/runner/src/runner.ts b/packages/runner/src/runner.ts index f057aa1b..93bea483 100644 --- a/packages/runner/src/runner.ts +++ b/packages/runner/src/runner.ts @@ -40,7 +40,8 @@ const execute = (command: string, args: string[] = [], options: cp.SpawnOptions, return prom; }; -export type TaskFunction = (runner: Runner) => void | Promise; +// tslint:disable-next-line no-any +export type TaskFunction = (runner: Runner, ...args: any[]) => void | Promise; export interface Runner { cwd: string; @@ -95,7 +96,7 @@ export const run = (name: string = process.argv[2]): void | Promise => { env: env as NodeJS.ProcessEnv, }, log); }, - }); + }, ...process.argv.slice(3)); if (prom) { activated.set(name, prom); diff --git a/packages/server/scripts/nexe.js b/packages/server/scripts/nexe.js index 8c1a29fb..5de18bd4 100644 --- a/packages/server/scripts/nexe.js +++ b/packages/server/scripts/nexe.js @@ -14,16 +14,17 @@ fs.writeFileSync(shimPath, shimContent); const nexe = require("nexe"); +const target = `${os.platform()}-${os.arch()}`; nexe.compile({ debugBundle: true, input: path.join(__dirname, "../out/cli.js"), - output: `cli-${process.env.TRAVIS_OS_NAME || os.platform()}`, - targets: [os.platform()], + output: `cli-${target}`, + targets: [target], /** * To include native extensions, do NOT install node_modules for each one. They * are not required as each extension is built using webpack. */ -resources: [ + resources: [ path.join(__dirname, "../package.json"), path.join(__dirname, "../build/**/*"), ], diff --git a/packages/server/src/cli.ts b/packages/server/src/cli.ts index 7bedae71..2f1da114 100644 --- a/packages/server/src/cli.ts +++ b/packages/server/src/cli.ts @@ -114,7 +114,7 @@ export class Entry extends Command { } } - logger.info("\u001B[1mcode-server v1.0.0"); + logger.info(`\u001B[1mcode-server ${process.env.VERSION ? `v${process.env.VERSION}` : "development"}`); // TODO: fill in appropriate doc url logger.info("Additional documentation: http://github.com/codercom/code-server"); logger.info("Initializing", field("data-dir", dataDir), field("working-dir", workingDir), field("log-dir", logDir)); diff --git a/packages/server/webpack.config.js b/packages/server/webpack.config.js index 0df82de3..596ff0be 100644 --- a/packages/server/webpack.config.js +++ b/packages/server/webpack.config.js @@ -24,7 +24,7 @@ module.exports = merge( }, resolve: { alias: { - "node-pty": "node-pty-prebuilt", + "node-pty": "node-pty-prebuilt", }, }, externals: ["tslib", "trash"], diff --git a/scripts/webpack.general.config.js b/scripts/webpack.general.config.js index 26587519..83215fa8 100644 --- a/scripts/webpack.general.config.js +++ b/scripts/webpack.general.config.js @@ -118,6 +118,7 @@ module.exports = (options = {}) => ({ "process.env.NODE_ENV": `"${environment}"`, "process.env.LOG_LEVEL": `"${process.env.LOG_LEVEL || ""}"`, "process.env.SERVICE_URL": `"${process.env.SERVICE_URL || ""}"`, + "process.env.VERSION": `"${process.env.VERSION || ""}"`, }), ], stats: {