Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CodePush release flow #631

Merged
merged 18 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
"--debug-brk",
"--no-timeouts",
"--colors",
"--compilers",
"ts:ts-node/register",
"--require",
"ts-node/register",
"--recursive",
"./test/**/*-test.[tj]s"
], //you can specify paths to specific tests here
Expand Down
97 changes: 97 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"@types/mkdirp": "^0.5.2",
"@types/wordwrap": "^1.0.0",
"@types/yazl": "^2.4.1",
"appcenter-file-upload-client": "0.0.9",
"azure-storage": "^2.10.3",
"bplist": "0.0.4",
"chalk": "^2.4.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,19 @@ import { AppCommand, CommandResult, ErrorCodes, failure, hasArg, help, longName,
import { CommandArgs } from "../../../util/commandline/command";
import { AppCenterClient, models, clientRequest } from "../../../util/apis";
import { out } from "../../../util/interaction";
import { getUser, DefaultApp } from "../../../util/profile/index";
import { inspect } from "util";
import * as fs from "fs";
import * as pfs from "../../../util/misc/promisfied-fs";
import chalk from "chalk";
import { sign, zip } from "../lib/update-contents-tasks";
import { isBinaryOrZip, getLastFolderInPath, moveReleaseFilesInTmpFolder, isDirectory } from "../lib/file-utils";
import { environments } from "../lib/environment";
import { isValidRange, isValidRollout, isValidDeployment, validateVersion } from "../lib/validation-utils";
import { LegacyCodePushRelease } from "../lib/release-strategy/index";
import { getTokenFromEnvironmentVar } from "../../../util/profile/environment-vars";

const debug = require("debug")("appcenter-cli:commands:codepush:release-skeleton");

export interface ReleaseStrategy {
release(client: AppCenterClient, app: DefaultApp, deploymentName: string, updateContentsZipPath: string, updateMetadata: {
appVersion?: string;
description?: string;
isDisabled?: boolean;
isMandatory?: boolean;
rollout?: number;
}, token?: string, serverUrl?: string): Promise<void>;
}
import { sign, zip } from "./update-contents-tasks";
import { isBinaryOrZip, getLastFolderInPath, moveReleaseFilesInTmpFolder, isDirectory } from "./file-utils";
import { isValidRange, isValidRollout, isValidDeployment, validateVersion } from "./validation-utils";
import FileUploadClient, { MessageLevel } from "appcenter-file-upload-client";
import { DefaultApp } from "../../../util/profile";

const debug = require("debug")("appcenter-cli:commands:codepush:release-base");

export default class CodePushReleaseCommandSkeleton extends AppCommand {
export default class CodePushReleaseCommandBase extends AppCommand {
@help("Deployment to release the update to")
@shortName("d")
@longName("deployment-name")
Expand Down Expand Up @@ -75,13 +63,12 @@ export default class CodePushReleaseCommandSkeleton extends AppCommand {

protected targetBinaryVersion: string;

private readonly releaseStrategy: ReleaseStrategy;
private readonly fileUploadClient: FileUploadClient;

constructor(args: CommandArgs) {
super(args);

// Сurrently use old service due to we have limitation of 1MB payload limit through bifrost service
this.releaseStrategy = new LegacyCodePushRelease();
this.fileUploadClient = new FileUploadClient();
}

public async run(client: AppCenterClient): Promise<CommandResult> {
Expand Down Expand Up @@ -114,18 +101,19 @@ export default class CodePushReleaseCommandSkeleton extends AppCommand {

try {
const app = this.app;
const serverUrl = this.getServerUrl();
const token = this.token || getTokenFromEnvironmentVar() || await getUser().accessToken;

this.checkTargetBinaryVersion(this.targetBinaryVersion);

await out.progress("Creating CodePush release...", this.releaseStrategy.release(client, app, this.deploymentName, updateContentsZipPath, {
appVersion: this.targetBinaryVersion,
const releaseUpload = this.upload(client, app, this.deploymentName, updateContentsZipPath);
await out.progress("Uploading bundle...", releaseUpload);
await out.progress("Creating CodePush release...", this.createRelease(client, app, this.deploymentName, {
releaseUpload: await releaseUpload,
targetBinaryVersion: this.targetBinaryVersion,
description: this.description,
isDisabled: this.disabled,
isMandatory: this.mandatory,
disabled: this.disabled,
mandatory: this.mandatory,
rollout: this.rollout
}, token, serverUrl));
}));

out.text(`Successfully released an update containing the "${this.updateContentsPath}" `
+ `${fs.lstatSync(this.updateContentsPath).isDirectory() ? "directory" : "file"}`
Expand All @@ -147,27 +135,55 @@ export default class CodePushReleaseCommandSkeleton extends AppCommand {
}
}

private checkTargetBinaryVersion(version: string): void {
const warningVersion = validateVersion(version);
private async upload(client: AppCenterClient, app: DefaultApp, deploymentName: string, updateContentsZipPath: string): Promise<models.CodePushReleaseUpload> {
debug(`Starting release upload on deployment: ${deploymentName} with zip file: ${updateContentsZipPath}`);

if (warningVersion) {
out.text(`\nYour target-binary-version "${version}" will be treated as "${warningVersion}".\n`);
}
const releaseUpload = (await clientRequest<models.CodePushReleaseUpload>(
(cb) => client.codePushDeploymentUpload.create(
deploymentName,
app.ownerName,
app.appName,
cb
)
)).result;

await this.uploadBundle(releaseUpload, updateContentsZipPath);
return releaseUpload;
}

private getServerUrl(): string | undefined {
const environment = environments(this.getEnvironmentName());
return environment && environment.managementEndpoint;
public async createRelease(client: AppCenterClient, app: DefaultApp, deploymentName: string, uploadedRelease: models.CodePushUploadedRelease): Promise<void> {
debug(`Starting release process on deployment: ${deploymentName} with uploaded release metadata: ${inspect(uploadedRelease)}`);

await clientRequest<models.CodePushRelease>(
(cb) => client.codePushDeploymentReleases.create(
deploymentName,
uploadedRelease,
app.ownerName,
app.appName,
cb
)
);
}

private getEnvironmentName(): string | undefined {
if (this.environmentName) {
return this.environmentName;
}
private async uploadBundle(releaseUpload: models.CodePushReleaseUpload, bundleZipPath: string): Promise<void> {
debug(`Starting to upload the release bundle: ${bundleZipPath} with upload data: ${inspect(releaseUpload)}`);

const user = getUser();
if (user) {
return user.environment;
await this.fileUploadClient.upload({
assetId: releaseUpload.id,
assetDomain: releaseUpload.uploadDomain,
assetToken: releaseUpload.token,
file: bundleZipPath,
onMessage: (message: string, level: MessageLevel) => {
debug(`Upload client message: ${message}`);
}
});
}

private checkTargetBinaryVersion(version: string): void {
const warningVersion = validateVersion(version);

if (warningVersion) {
out.text(`\nYour target-binary-version "${version}" will be treated as "${warningVersion}".\n`);
}
}

Expand Down
31 changes: 0 additions & 31 deletions src/commands/codepush/lib/release-strategy/appcenter-release.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/commands/codepush/lib/release-strategy/index.ts

This file was deleted.

Loading