Skip to content

Commit

Permalink
Add task for packaging release (coder#6)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
code-asher authored Mar 7, 2019
1 parent 8916cb9 commit 994531d
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
dist
out
.DS_Store
release
18 changes: 11 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: node_js
node_js:
- 8.9.3
env:
- VERSION="1.31.1-$TRAVIS_BUILD_NUMBER"
matrix:
include:
- os: linux
Expand All @@ -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
26 changes: 26 additions & 0 deletions build/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
5 changes: 3 additions & 2 deletions packages/runner/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const execute = (command: string, args: string[] = [], options: cp.SpawnOptions,
return prom;
};

export type TaskFunction = (runner: Runner) => void | Promise<void>;
// tslint:disable-next-line no-any
export type TaskFunction = (runner: Runner, ...args: any[]) => void | Promise<void>;

export interface Runner {
cwd: string;
Expand Down Expand Up @@ -95,7 +96,7 @@ export const run = (name: string = process.argv[2]): void | Promise<void> => {
env: env as NodeJS.ProcessEnv,
}, log);
},
});
}, ...process.argv.slice(3));

if (prom) {
activated.set(name, prom);
Expand Down
7 changes: 4 additions & 3 deletions packages/server/scripts/nexe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*"),
],
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion packages/server/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = merge(
},
resolve: {
alias: {
"node-pty": "node-pty-prebuilt",
"node-pty": "node-pty-prebuilt",
},
},
externals: ["tslib", "trash"],
Expand Down
1 change: 1 addition & 0 deletions scripts/webpack.general.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 994531d

Please sign in to comment.