diff --git a/README.md b/README.md index f83872f2..cdf2be7c 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,15 @@ This action will help you upload an Android `.apk` or `.aab` (Android App Bundle ## Inputs +_You must provide one of either `serviceAccountJson` or `serviceAccountJsonPlainText`_ + ### `serviceAccountJson` -**Required:** The service account json private key file to authorize the upload request +The service account json private key file to authorize the upload request + +### `serviceAccountJsonPlainText` + +The service account json in plain text, provided via a secret, etc. ### `packageName` diff --git a/action.yml b/action.yml index 65c2a9e7..3afcf416 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,10 @@ branding: inputs: serviceAccountJson: description: 'The service account json private key file to authorize the upload request' - required: true + required: false + serviceAccountJsonPlainText: + description: 'The raw json text of the service account private key to authorize the upload request' + required: false packageName: description: 'The package name, or Application Id, of the app you are uploading' required: true diff --git a/lib/main.js b/lib/main.js index d5f29975..951e9a3b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,13 +26,32 @@ const auth = new google.auth.GoogleAuth({ function run() { return __awaiter(this, void 0, void 0, function* () { try { - const serviceAccountJson = core.getInput('serviceAccountJson', { required: true }); + const serviceAccountJson = core.getInput('serviceAccountJson', { required: false }); + const serviceAccountJsonRaw = core.getInput('serviceAccountJsonPlainText', { required: false }); const packageName = core.getInput('packageName', { required: true }); const releaseFile = core.getInput('releaseFile', { required: true }); const track = core.getInput('track', { required: true }); const userFraction = core.getInput('userFraction', { required: false }); const whatsNewDir = core.getInput('whatsNewDirectory', { required: false }); const mappingFile = core.getInput('mappingFile', { required: false }); + if (!serviceAccountJson && !serviceAccountJsonRaw) { + console.log("No service account json key provided!"); + core.setFailed("You must provide one of 'serviceAccountJson' or 'serviceAccountJsonPlainText' to use this action"); + } + // If the user has provided the raw plain text via secrets, or w/e, then write to file and + // set appropriate env variable for the auth + if (serviceAccountJsonRaw) { + const serviceAccountFile = "./serviceAccountJson.json"; + fs.writeFileSync(serviceAccountFile, serviceAccountJsonRaw, { + encoding: 'utf8' + }); + // Insure that the api can find our service account credentials + core.exportVariable("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountFile); + } + if (serviceAccountJson) { + // Insure that the api can find our service account credentials + core.exportVariable("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountJson); + } // verify inputs let userFractionFloat = parseFloat(userFraction); if (!isNaN(userFractionFloat)) { @@ -57,8 +76,6 @@ function run() { core.setFailed(`Unable to find 'mappingFile' @ ${mappingFile}`); return; } - // Insure that the api can find our service account credentials - core.exportVariable("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountJson); const authClient = yield auth.getClient(); yield edits_1.uploadRelease({ auth: authClient, diff --git a/src/main.ts b/src/main.ts index 6085fc97..ed1ae7ff 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,8 @@ const auth = new google.auth.GoogleAuth({ async function run() { try { - const serviceAccountJson = core.getInput('serviceAccountJson', { required: true }); + const serviceAccountJson = core.getInput('serviceAccountJson', { required: false }); + const serviceAccountJsonRaw = core.getInput('serviceAccountJsonPlainText', { required: false}); const packageName = core.getInput('packageName', { required: true }); const releaseFile = core.getInput('releaseFile', { required: true }); const track = core.getInput('track', { required: true }); @@ -17,6 +18,28 @@ async function run() { const whatsNewDir = core.getInput('whatsNewDirectory', { required: false }); const mappingFile = core.getInput('mappingFile', { required: false }); + if (!serviceAccountJson && !serviceAccountJsonRaw) { + console.log("No service account json key provided!"); + core.setFailed("You must provide one of 'serviceAccountJson' or 'serviceAccountJsonPlainText' to use this action"); + } + + // If the user has provided the raw plain text via secrets, or w/e, then write to file and + // set appropriate env variable for the auth + if (serviceAccountJsonRaw) { + const serviceAccountFile = "./serviceAccountJson.json"; + fs.writeFileSync(serviceAccountFile, serviceAccountJsonRaw, { + encoding: 'utf8' + }); + + // Insure that the api can find our service account credentials + core.exportVariable("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountFile); + } + + if (serviceAccountJson) { + // Insure that the api can find our service account credentials + core.exportVariable("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountJson); + } + // verify inputs let userFractionFloat: number | undefined = parseFloat(userFraction); if (!isNaN(userFractionFloat)) { @@ -44,9 +67,6 @@ async function run() { return } - // Insure that the api can find our service account credentials - core.exportVariable("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountJson); - const authClient = await auth.getClient(); await uploadRelease({