From 7774099a1b7f49c72917ed98eae8f6e57df78ff3 Mon Sep 17 00:00:00 2001 From: "Jack Boswell (boswelja)" Date: Fri, 23 Oct 2020 16:26:01 +1300 Subject: [PATCH] Separate internal sharing uploading into it's own function Also skip unneeded setup when uploading to internal sharing --- lib/edits.js | 103 +++++++++++++++++++++++++++++---------------------- src/edits.ts | 100 +++++++++++++++++++++++++++---------------------- 2 files changed, 113 insertions(+), 90 deletions(-) diff --git a/lib/edits.js b/lib/edits.js index efc69c51..eb907305 100644 --- a/lib/edits.js +++ b/lib/edits.js @@ -37,60 +37,73 @@ const whatsnew_1 = require("./whatsnew"); const androidPublisher = googleapis_1.google.androidpublisher('v3'); function uploadToPlayStore(options, releaseFiles) { return __awaiter(this, void 0, void 0, function* () { - const appEdit = yield androidPublisher.edits.insert({ - auth: options.auth, - packageName: options.applicationId - }); - yield validateSelectedTrack(appEdit.data, options).catch(reason => { - core.setFailed(reason); - return Promise.reject(reason); - }); - var versionCodes = new Array(); - releaseFiles.forEach((releaseFile) => __awaiter(this, void 0, void 0, function* () { - core.debug(`Uploading ${releaseFile}`); - const versionCode = yield uploadRelease(appEdit.data, options, releaseFile).catch(reason => { + if (options.track === 'internalappsharing') { + core.debug("Track is Internal app sharing, switch to special upload api"); + releaseFiles.forEach((releaseFile) => __awaiter(this, void 0, void 0, function* () { + core.debug(`Uploading ${releaseFile}`); + yield uploadInternalSharingRelease(options, releaseFile).catch(reason => { + core.setFailed(reason); + return Promise.reject(reason); + }); + })); + } + else { + const appEdit = yield androidPublisher.edits.insert({ + auth: options.auth, + packageName: options.applicationId + }); + yield validateSelectedTrack(appEdit.data, options).catch(reason => { core.setFailed(reason); return Promise.reject(reason); }); - versionCodes.push(versionCode); - })); - const track = addReleasesToTrack(appEdit.data, options, versionCodes); - const res = yield androidPublisher.edits.commit({ - auth: options.auth, - editId: appEdit.data.id, - packageName: options.applicationId - }); - if (res.data.id != null) { - core.debug(`Successfully committed ${res.data.id}`); - return Promise.resolve(res.data.id); - } - else { - core.setFailed(`Error ${res.status}: ${res.statusText}`); - return Promise.reject(res.status); + // Check the 'track' for 'internalsharing', if so switch to a non-track api + var versionCodes = new Array(); + releaseFiles.forEach((releaseFile) => __awaiter(this, void 0, void 0, function* () { + core.debug(`Uploading ${releaseFile}`); + const versionCode = yield uploadRelease(appEdit.data, options, releaseFile).catch(reason => { + core.setFailed(reason); + return Promise.reject(reason); + }); + versionCodes.push(versionCode); + })); + const track = addReleasesToTrack(appEdit.data, options, versionCodes); + const res = yield androidPublisher.edits.commit({ + auth: options.auth, + editId: appEdit.data.id, + packageName: options.applicationId + }); + if (res.data.id != null) { + core.debug(`Successfully committed ${res.data.id}`); + return Promise.resolve(res.data.id); + } + else { + core.setFailed(`Error ${res.status}: ${res.statusText}`); + return Promise.reject(res.status); + } } }); } exports.uploadToPlayStore = uploadToPlayStore; +function uploadInternalSharingRelease(options, releaseFile) { + return __awaiter(this, void 0, void 0, function* () { + if (releaseFile.endsWith('.apk')) { + const res = yield internalSharingUploadApk(options, releaseFile); + console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`); + return Promise.resolve(res.downloadUrl); + } + else if (releaseFile.endsWith('.aab')) { + const res = yield internalSharingUploadBundle(options, releaseFile); + console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`); + return Promise.resolve(res.downloadUrl); + } + else { + core.setFailed(`${releaseFile} is invalid`); + return Promise.reject(`${releaseFile} is invalid`); + } + }); +} function uploadRelease(appEdit, options, releaseFile) { return __awaiter(this, void 0, void 0, function* () { - // Check the 'track' for 'internalsharing', if so switch to a non-track api - if (options.track === 'internalsharing') { - core.debug("Track is Internal app sharing, switch to special upload api"); - if (releaseFile.endsWith('.apk')) { - const res = yield internalSharingUploadApk(options, releaseFile); - console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`); - return Promise.resolve(undefined); - } - else if (releaseFile.endsWith('.aab')) { - const res = yield internalSharingUploadBundle(options, releaseFile); - console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`); - return Promise.resolve(undefined); - } - else { - core.setFailed(`${releaseFile} is invalid`); - return Promise.reject(`${releaseFile} is invalid`); - } - } if (releaseFile.endsWith('.apk')) { const apk = yield uploadApk(appEdit, options, releaseFile); yield uploadMappingFile(appEdit, apk.versionCode, options); diff --git a/src/edits.ts b/src/edits.ts index 0bff373b..d517c92c 100644 --- a/src/edits.ts +++ b/src/edits.ts @@ -28,60 +28,70 @@ export interface EditOptions { } export async function uploadToPlayStore(options: EditOptions, releaseFiles: string[]): Promise { - const appEdit = await androidPublisher.edits.insert({ - auth: options.auth, - packageName: options.applicationId - }); - - await validateSelectedTrack(appEdit.data, options).catch(reason => { - core.setFailed(reason); - return Promise.reject(reason); - }); - - var versionCodes = new Array(); - releaseFiles.forEach(async releaseFile => { - core.debug(`Uploading ${releaseFile}`); - const versionCode = await uploadRelease(appEdit.data, options, releaseFile).catch(reason => { + if (options.track === 'internalappsharing') { + core.debug("Track is Internal app sharing, switch to special upload api") + releaseFiles.forEach(async releaseFile => { + core.debug(`Uploading ${releaseFile}`); + await uploadInternalSharingRelease(options, releaseFile).catch(reason => { + core.setFailed(reason); + return Promise.reject(reason); + }); + }); + } else { + const appEdit = await androidPublisher.edits.insert({ + auth: options.auth, + packageName: options.applicationId + }); + + await validateSelectedTrack(appEdit.data, options).catch(reason => { core.setFailed(reason); return Promise.reject(reason); }); - versionCodes.push(versionCode!); - }); + + // Check the 'track' for 'internalsharing', if so switch to a non-track api + var versionCodes = new Array(); + releaseFiles.forEach(async releaseFile => { + core.debug(`Uploading ${releaseFile}`); + const versionCode = await uploadRelease(appEdit.data, options, releaseFile).catch(reason => { + core.setFailed(reason); + return Promise.reject(reason); + }); + versionCodes.push(versionCode!); + }); + + const track = addReleasesToTrack(appEdit.data, options, versionCodes); + const res = await androidPublisher.edits.commit({ + auth: options.auth, + editId: appEdit.data.id!, + packageName: options.applicationId + }); + + if (res.data.id != null) { + core.debug(`Successfully committed ${res.data.id}`); + return Promise.resolve(res.data.id!); + } else { + core.setFailed(`Error ${res.status}: ${res.statusText}`); + return Promise.reject(res.status); + } + } +} - const track = addReleasesToTrack(appEdit.data, options, versionCodes); - const res = await androidPublisher.edits.commit({ - auth: options.auth, - editId: appEdit.data.id!, - packageName: options.applicationId - }); - - if (res.data.id != null) { - core.debug(`Successfully committed ${res.data.id}`); - return Promise.resolve(res.data.id!); +async function uploadInternalSharingRelease(options: EditOptions, releaseFile: string): Promise { + if (releaseFile.endsWith('.apk')) { + const res = await internalSharingUploadApk(options, releaseFile) + console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`) + return Promise.resolve(res.downloadUrl) + } else if (releaseFile.endsWith('.aab')) { + const res = await internalSharingUploadBundle(options, releaseFile) + console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`) + return Promise.resolve(res.downloadUrl) } else { - core.setFailed(`Error ${res.status}: ${res.statusText}`); - return Promise.reject(res.status); + core.setFailed(`${releaseFile} is invalid`) + return Promise.reject(`${releaseFile} is invalid`) } } async function uploadRelease(appEdit: AppEdit, options: EditOptions, releaseFile: string): Promise { - // Check the 'track' for 'internalsharing', if so switch to a non-track api - if (options.track === 'internalsharing'){ - core.debug("Track is Internal app sharing, switch to special upload api") - if (releaseFile.endsWith('.apk')) { - const res = await internalSharingUploadApk(options, releaseFile) - console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`) - return Promise.resolve(undefined) - } else if (releaseFile.endsWith('.aab')) { - const res = await internalSharingUploadBundle(options, releaseFile) - console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`) - return Promise.resolve(undefined) - } else { - core.setFailed(`${releaseFile} is invalid`) - return Promise.reject(`${releaseFile} is invalid`) - } - } - if (releaseFile.endsWith('.apk')) { const apk = await uploadApk(appEdit, options, releaseFile); await uploadMappingFile(appEdit, apk.versionCode!, options);