From 4fd5ad35636109d4d627115639d4d47ab5477a79 Mon Sep 17 00:00:00 2001 From: Amadeu Cavalcante Date: Wed, 19 Aug 2020 09:38:30 -0300 Subject: [PATCH 1/2] Update README.md If you do ``` > fs.existsSync("distribution/whatsnew") true > fs.existsSync("/distribution/whatsnew") false > fs.existsSync("./distribution/whatsnew") true ``` `/` will lead you to the wrong directory. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cdf2be7c..f84bf357 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,6 @@ with: releaseFile: ${{ SIGNED_RELEASE_FILE}} track: beta userFraction: 0.33 - whatsNewDirectory: /distribution/whatsnew - mappingFile: /app/build/outputs/mapping/release/mapping.txt + whatsNewDirectory: distribution/whatsnew + mappingFile: app/build/outputs/mapping/release/mapping.txt ``` From caa567f814ec1ef5e738a123640b4aebcf5df752 Mon Sep 17 00:00:00 2001 From: Drew Heavner Date: Thu, 20 Aug 2020 13:32:14 -0400 Subject: [PATCH 2/2] Fixed #10 - Added support for `internalsharing` uploading --- README.md | 12 +++++++++++- action.yml | 3 +++ lib/edits.js | 43 +++++++++++++++++++++++++++++++++++++++++++ src/edits.ts | 48 +++++++++++++++++++++++++++++++++++++++++++++++- src/main.ts | 7 ++++++- 5 files changed, 110 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cdf2be7c..757cc672 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ The service account json in plain text, provided via a secret, etc. **Required:** The track in which you want to assign the uploaded app. **Default:** `production` -_Values:_ `alpha`, `beta`, `internal`, `production` +_Values:_ `alpha`, `beta`, `internal`, `production`, `internalsharing` ### `userFraction` @@ -54,6 +54,16 @@ where `whatsNewDirectory` is the path you pass to the action. The mapping.txt file used to de-obfuscate your stack traces from crash reports +## Outputs + +### `internalSharingDownloadUrl` + +The download url for an app that was uploaded using the `track` `internalsharing` + +### ENV VAR: `INTERNAL_SHARING_DOWNLOAD_URL` + +The environment variable that is set when using the `track` `internalsharing` + ## Example usage ```yaml diff --git a/action.yml b/action.yml index 3afcf416..5f1e171b 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,9 @@ inputs: mappingFile: description: 'The mapping.txt file used to de-obfuscate your stack traces from crash reports' required: false +outputs: + internalSharingDownloadUrl: + description: "The internal app sharing download url if track was 'internalsharing'" runs: using: 'node12' main: 'lib/main.js' diff --git a/lib/edits.js b/lib/edits.js index 95ee695e..ae699bb9 100644 --- a/lib/edits.js +++ b/lib/edits.js @@ -24,6 +24,21 @@ const whatsnew_1 = require("./whatsnew"); const androidPublisher = googleapis_1.google.androidpublisher('v3'); function uploadRelease(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); + return Promise.resolve(res.downloadUrl); + } + else if (releaseFile.endsWith('.aab')) { + const res = yield internalSharingUploadBundle(options, releaseFile); + return Promise.resolve(res.downloadUrl); + } + else { + return Promise.reject(`Unrecognized Release File`); + } + } const appEdit = yield androidPublisher.edits.insert({ auth: options.auth, packageName: options.applicationId @@ -121,6 +136,34 @@ function uploadMappingFile(appEdit, versionCode, options) { } }); } +function internalSharingUploadApk(options, apkReleaseFile) { + return __awaiter(this, void 0, void 0, function* () { + core.debug(`[packageName=${options.applicationId}]: Uploading Internal Sharing APK @ ${apkReleaseFile}`); + const res = yield androidPublisher.internalappsharingartifacts.uploadapk({ + auth: options.auth, + packageName: options.applicationId, + media: { + mimeType: 'application/vnd.android.package-archive', + body: fs.createReadStream(apkReleaseFile) + } + }); + return res.data; + }); +} +function internalSharingUploadBundle(options, bundleReleaseFile) { + return __awaiter(this, void 0, void 0, function* () { + core.debug(`[packageName=${options.applicationId}]: Uploading Internal Sharing Bundle @ ${bundleReleaseFile}`); + const res = yield androidPublisher.internalappsharingartifacts.uploadbundle({ + auth: options.auth, + packageName: options.applicationId, + media: { + mimeType: 'application/octet-stream', + body: fs.createReadStream(bundleReleaseFile) + } + }); + return res.data; + }); +} function uploadApk(appEdit, options, apkReleaseFile) { return __awaiter(this, void 0, void 0, function* () { core.debug(`[${appEdit.id}, packageName=${options.applicationId}]: Uploading APK @ ${apkReleaseFile}`); diff --git a/src/edits.ts b/src/edits.ts index 46e9c253..65346490 100644 --- a/src/edits.ts +++ b/src/edits.ts @@ -10,6 +10,7 @@ import AppEdit = androidpublisher_v3.Schema$AppEdit; import Apk = androidpublisher_v3.Schema$Apk; import Bundle = androidpublisher_v3.Schema$Bundle; import Track = androidpublisher_v3.Schema$Track; +import InternalAppSharingArtifact = androidpublisher_v3.Schema$InternalAppSharingArtifact; import {Compute} from "google-auth-library/build/src/auth/computeclient"; import {JWT} from "google-auth-library/build/src/auth/jwtclient"; import {UserRefreshClient} from "google-auth-library/build/src/auth/refreshclient"; @@ -26,7 +27,21 @@ export interface EditOptions { mappingFile?: string; } -export async function uploadRelease(options: EditOptions, releaseFile: string) { +export async function uploadRelease(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) + return Promise.resolve(res.downloadUrl) + } else if (releaseFile.endsWith('.aab')) { + const res = await internalSharingUploadBundle(options, releaseFile) + return Promise.resolve(res.downloadUrl) + } else { + return Promise.reject(`Unrecognized Release File`) + } + } + const appEdit = await androidPublisher.edits.insert({ auth: options.auth, packageName: options.applicationId @@ -124,8 +139,39 @@ async function uploadMappingFile(appEdit: AppEdit, versionCode: number, options: } } +async function internalSharingUploadApk(options: EditOptions, apkReleaseFile: string): Promise { + core.debug(`[packageName=${options.applicationId}]: Uploading Internal Sharing APK @ ${apkReleaseFile}`); + + const res = await androidPublisher.internalappsharingartifacts.uploadapk({ + auth: options.auth, + packageName: options.applicationId, + media: { + mimeType: 'application/vnd.android.package-archive', + body: fs.createReadStream(apkReleaseFile) + } + }); + + return res.data; +} + +async function internalSharingUploadBundle(options: EditOptions, bundleReleaseFile: string): Promise { + core.debug(`[packageName=${options.applicationId}]: Uploading Internal Sharing Bundle @ ${bundleReleaseFile}`); + + const res = await androidPublisher.internalappsharingartifacts.uploadbundle({ + auth: options.auth, + packageName: options.applicationId, + media: { + mimeType: 'application/octet-stream', + body: fs.createReadStream(bundleReleaseFile) + } + }); + + return res.data; +} + async function uploadApk(appEdit: AppEdit, options: EditOptions, apkReleaseFile: string): Promise { core.debug(`[${appEdit.id}, packageName=${options.applicationId}]: Uploading APK @ ${apkReleaseFile}`); + const res = await androidPublisher.edits.apks.upload({ auth: options.auth, packageName: options.applicationId, diff --git a/src/main.ts b/src/main.ts index ed1ae7ff..6cb36b13 100644 --- a/src/main.ts +++ b/src/main.ts @@ -69,7 +69,7 @@ async function run() { const authClient = await auth.getClient(); - await uploadRelease({ + const downloadUrl = await uploadRelease({ auth: authClient, applicationId: packageName, track: track, @@ -78,6 +78,11 @@ async function run() { mappingFile: mappingFile }, releaseFile); + if (downloadUrl) { + core.setOutput('internalSharingDownloadUrl', downloadUrl); + core.exportVariable('INTERNAL_SHARING_DOWNLOAD_URL', downloadUrl); + } + console.log(`Finished uploading ${releaseFile} to the Play Store`) } catch (error) { core.setFailed(error.message)