protected async release()

in src/commands/codepush/lib/codepush-release-command-base.ts [95:169]


  protected async release(client: AppCenterClient): Promise<CommandResult> {
    this.rollout = Number(this.specifiedRollout);

    const validationResult: CommandResult = await this.validate(client);
    if (!validationResult.succeeded) {
      return validationResult;
    }

    this.deploymentName = this.specifiedDeploymentName;

    if (this.privateKeyPath) {
      const appInfo = (
        await out.progress(
          "Getting app info...",
          clientRequest<models.AppResponse>((cb) => client.appsOperations.get(this.app.ownerName, this.app.appName, cb))
        )
      ).result;
      const platform = appInfo.platform.toLowerCase();

      // In React-Native case we should add "CodePush" name folder as root for relase files for keeping sync with React Native client SDK.
      // Also single file also should be in "CodePush" folder.
      if (
        platform === "react-native" &&
        (getLastFolderInPath(this.updateContentsPath) !== "CodePush" || !isDirectory(this.updateContentsPath))
      ) {
        await moveReleaseFilesInTmpFolder(this.updateContentsPath).then((tmpPath: string) => {
          this.updateContentsPath = tmpPath;
        });
      }

      await sign(this.privateKeyPath, this.updateContentsPath);
    }

    const updateContentsZipPath = await zip(this.updateContentsPath);

    try {
      const app = this.app;

      this.checkTargetBinaryVersion(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,
          disabled: this.disabled,
          mandatory: this.mandatory,
          rollout: this.rollout,
        })
      );

      out.text(
        `Successfully released an update containing the "${this.updateContentsPath}" ` +
          `${fs.lstatSync(this.updateContentsPath).isDirectory() ? "directory" : "file"}` +
          ` to the "${this.deploymentName}" deployment of the "${this.app.appName}" app.`
      );

      return success();
    } catch (error) {
      if (error.response && error.response.statusCode === 409 && this.disableDuplicateReleaseError) {
        // 409 (Conflict) status code means that uploaded package is identical
        // to the contents of the specified deployment's current release
        console.warn(chalk.yellow("[Warning] " + error.response.body));
        return success();
      } else {
        debug(`Failed to release a CodePush update - ${inspect(error)}`);
        return failure(ErrorCodes.Exception, error.response ? error.response.body : error);
      }
    } finally {
      await pfs.rmDir(updateContentsZipPath);
    }
  }