GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
7.0 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const fs = require("fs-extra");
  5. const command_1 = require("../command");
  6. const utils = require("../utils");
  7. const requireAuth_1 = require("../requireAuth");
  8. const client_1 = require("../appdistribution/client");
  9. const error_1 = require("../error");
  10. const distribution_1 = require("../appdistribution/distribution");
  11. const options_parser_util_1 = require("../appdistribution/options-parser-util");
  12. function getReleaseNotes(releaseNotes, releaseNotesFile) {
  13. if (releaseNotes) {
  14. return releaseNotes.replace(/\\n/g, "\n");
  15. }
  16. else if (releaseNotesFile) {
  17. (0, options_parser_util_1.ensureFileExists)(releaseNotesFile);
  18. return fs.readFileSync(releaseNotesFile, "utf8");
  19. }
  20. return "";
  21. }
  22. exports.command = new command_1.Command("appdistribution:distribute <release-binary-file>")
  23. .description("upload a release binary")
  24. .option("--app <app_id>", "the app id of your Firebase app")
  25. .option("--release-notes <string>", "release notes to include")
  26. .option("--release-notes-file <file>", "path to file with release notes")
  27. .option("--testers <string>", "a comma separated list of tester emails to distribute to")
  28. .option("--testers-file <file>", "path to file with a comma separated list of tester emails to distribute to")
  29. .option("--groups <string>", "a comma separated list of group aliases to distribute to")
  30. .option("--groups-file <file>", "path to file with a comma separated list of group aliases to distribute to")
  31. .before(requireAuth_1.requireAuth)
  32. .action(async (file, options) => {
  33. const appName = (0, options_parser_util_1.getAppName)(options);
  34. const distribution = new distribution_1.Distribution(file);
  35. const releaseNotes = getReleaseNotes(options.releaseNotes, options.releaseNotesFile);
  36. const testers = (0, options_parser_util_1.getTestersOrGroups)(options.testers, options.testersFile);
  37. const groups = (0, options_parser_util_1.getTestersOrGroups)(options.groups, options.groupsFile);
  38. const requests = new client_1.AppDistributionClient();
  39. let aabInfo;
  40. if (distribution.distributionFileType() === distribution_1.DistributionFileType.AAB) {
  41. try {
  42. aabInfo = await requests.getAabInfo(appName);
  43. }
  44. catch (err) {
  45. if (err.status === 404) {
  46. throw new error_1.FirebaseError(`App Distribution could not find your app ${options.app}. ` +
  47. `Make sure to onboard your app by pressing the "Get started" ` +
  48. "button on the App Distribution page in the Firebase console: " +
  49. "https://console.firebase.google.com/project/_/appdistribution", { exit: 1 });
  50. }
  51. throw new error_1.FirebaseError(`failed to determine AAB info. ${err.message}`, { exit: 1 });
  52. }
  53. if (aabInfo.integrationState !== client_1.IntegrationState.INTEGRATED &&
  54. aabInfo.integrationState !== client_1.IntegrationState.AAB_STATE_UNAVAILABLE) {
  55. switch (aabInfo.integrationState) {
  56. case client_1.IntegrationState.PLAY_ACCOUNT_NOT_LINKED: {
  57. throw new error_1.FirebaseError("This project is not linked to a Google Play account.");
  58. }
  59. case client_1.IntegrationState.APP_NOT_PUBLISHED: {
  60. throw new error_1.FirebaseError('"This app is not published in the Google Play console.');
  61. }
  62. case client_1.IntegrationState.NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT: {
  63. throw new error_1.FirebaseError("App with matching package name does not exist in Google Play.");
  64. }
  65. case client_1.IntegrationState.PLAY_IAS_TERMS_NOT_ACCEPTED: {
  66. throw new error_1.FirebaseError("You must accept the Play Internal App Sharing (IAS) terms to upload AABs.");
  67. }
  68. default: {
  69. throw new error_1.FirebaseError("App Distribution failed to process the AAB: " + aabInfo.integrationState);
  70. }
  71. }
  72. }
  73. }
  74. utils.logBullet("uploading binary...");
  75. let releaseName;
  76. try {
  77. const operationName = await requests.uploadRelease(appName, distribution);
  78. const uploadResponse = await requests.pollUploadStatus(operationName);
  79. const release = uploadResponse.release;
  80. switch (uploadResponse.result) {
  81. case client_1.UploadReleaseResult.RELEASE_CREATED:
  82. utils.logSuccess(`uploaded new release ${release.displayVersion} (${release.buildVersion}) successfully!`);
  83. break;
  84. case client_1.UploadReleaseResult.RELEASE_UPDATED:
  85. utils.logSuccess(`uploaded update to existing release ${release.displayVersion} (${release.buildVersion}) successfully!`);
  86. break;
  87. case client_1.UploadReleaseResult.RELEASE_UNMODIFIED:
  88. utils.logSuccess(`re-uploaded already existing release ${release.displayVersion} (${release.buildVersion}) successfully!`);
  89. break;
  90. default:
  91. utils.logSuccess(`uploaded release ${release.displayVersion} (${release.buildVersion}) successfully!`);
  92. }
  93. utils.logSuccess(`View this release in the Firebase console: ${release.firebaseConsoleUri}`);
  94. utils.logSuccess(`Share this release with testers who have access: ${release.testingUri}`);
  95. utils.logSuccess(`Download the release binary (link expires in 1 hour): ${release.binaryDownloadUri}`);
  96. releaseName = uploadResponse.release.name;
  97. }
  98. catch (err) {
  99. if (err.status === 404) {
  100. throw new error_1.FirebaseError(`App Distribution could not find your app ${options.app}. ` +
  101. `Make sure to onboard your app by pressing the "Get started" ` +
  102. "button on the App Distribution page in the Firebase console: " +
  103. "https://console.firebase.google.com/project/_/appdistribution", { exit: 1 });
  104. }
  105. throw new error_1.FirebaseError(`failed to upload release. ${err.message}`, { exit: 1 });
  106. }
  107. if (aabInfo && !aabInfo.testCertificate) {
  108. aabInfo = await requests.getAabInfo(appName);
  109. if (aabInfo.testCertificate) {
  110. utils.logBullet("After you upload an AAB for the first time, App Distribution " +
  111. "generates a new test certificate. All AAB uploads are re-signed with this test " +
  112. "certificate. Use the certificate fingerprints below to register your app " +
  113. "signing key with API providers, such as Google Sign-In and Google Maps.\n" +
  114. `MD-1 certificate fingerprint: ${aabInfo.testCertificate.hashMd5}\n` +
  115. `SHA-1 certificate fingerprint: ${aabInfo.testCertificate.hashSha1}\n` +
  116. `SHA-256 certificate fingerprint: ${aabInfo.testCertificate.hashSha256}`);
  117. }
  118. }
  119. await requests.updateReleaseNotes(releaseName, releaseNotes);
  120. await requests.distribute(releaseName, testers, groups);
  121. });