Set up full input testing (#150)

* Extract main loop to something testable

* Revert "Extract main loop to something testable"

This reverts commit 35a78459698fe267933c554283212c2d06ed4bf0.

* Extract code that interacts with Google Play
We can now test our input flow as a whole

* Create some basic tests for `completed` status publishing

* Fix applying inputs
We don't want to be keeping values between runs

* Drop some redundant tests

* Create basic tests for draft rollout

* Run build

* Fix userFraction bug

* Improve readability of initialising inputs

* Fix runUpload mocking

* Migrate to github-action-ts-run-api
This commit is contained in:
Jack Boswell
2022-10-23 18:18:11 -07:00
committed by GitHub
parent 4d510d380a
commit b84eace68d
7 changed files with 901 additions and 36 deletions

View File

@@ -34,7 +34,47 @@ export interface EditOptions {
existingEditId?: string;
}
export async function uploadToPlayStore(options: EditOptions, releaseFiles: string[]): Promise<string | void> {
export async function runUpload(
packageName: string,
track: string,
inAppUpdatePriority: number | undefined,
userFraction: number | undefined,
whatsNewDir: string | undefined,
mappingFile: string | undefined,
debugSymbols: string | undefined,
name: string | undefined,
changesNotSentForReview: boolean,
existingEditId: string | undefined,
status: string,
validatedReleaseFiles: string[]
) {
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/androidpublisher']
});
const authClient = await auth.getClient();
const result = await uploadToPlayStore({
auth: authClient,
applicationId: packageName,
track: track,
inAppUpdatePriority: inAppUpdatePriority || 0,
userFraction: userFraction,
whatsNewDir: whatsNewDir,
mappingFile: mappingFile,
debugSymbols: debugSymbols,
name: name,
changesNotSentForReview: changesNotSentForReview,
existingEditId: existingEditId,
status: status
}, validatedReleaseFiles);
if (result) {
console.log(`Finished uploading to the Play Store: ${result}`)
}
}
async function uploadToPlayStore(options: EditOptions, releaseFiles: string[]): Promise<string | void> {
// 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")

View File

@@ -1,16 +1,10 @@
import * as core from '@actions/core';
import * as fs from "fs";
import {uploadToPlayStore} from "./edits";
import { runUpload } from "./edits";
import { validateInAppUpdatePriority, validateReleaseFiles, validateStatus, validateUserFraction } from "./input-validation"
import * as google from '@googleapis/androidpublisher';
import { unlink, writeFile } from 'fs/promises';
import { exit } from 'process';
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/androidpublisher']
});
async function run() {
export async function run() {
try {
const serviceAccountJson = core.getInput('serviceAccountJson', { required: false });
const serviceAccountJsonRaw = core.getInput('serviceAccountJsonPlainText', { required: false});
@@ -34,7 +28,7 @@ async function run() {
// Validate user fraction
let userFractionFloat: number | undefined
if (userFraction != undefined) {
if (userFraction) {
userFractionFloat = parseFloat(userFraction)
} else {
userFractionFloat = undefined
@@ -74,26 +68,20 @@ async function run() {
return
}
const authClient = await auth.getClient();
const result = await uploadToPlayStore({
auth: authClient,
applicationId: packageName,
track: track,
inAppUpdatePriority: inAppUpdatePriorityInt || 0,
userFraction: userFractionFloat,
whatsNewDir: whatsNewDir,
mappingFile: mappingFile,
debugSymbols: debugSymbols,
name: releaseName,
changesNotSentForReview: changesNotSentForReview,
existingEditId: existingEditId,
status: status
}, validatedReleaseFiles);
if (result) {
console.log(`Finished uploading to the Play Store: ${result}`)
}
await runUpload(
packageName,
track,
inAppUpdatePriorityInt,
userFractionFloat,
whatsNewDir,
mappingFile,
debugSymbols,
releaseName,
changesNotSentForReview,
existingEditId,
status,
validatedReleaseFiles
)
} catch (error: unknown) {
if (error instanceof Error) {
core.setFailed(error.message)
@@ -109,7 +97,7 @@ async function run() {
}
}
async function validateServiceAccountJson(serviceAccountJsonRaw: string | undefined, serviceAccountJson: string | undefined) {
async function validateServiceAccountJson(serviceAccountJsonRaw: string | undefined, serviceAccountJson: string | undefined): Promise<string | undefined> {
if (serviceAccountJson && serviceAccountJsonRaw) {
// If the user provided both, print a warning one will be ignored
core.warning('Both \'serviceAccountJsonPlainText\' and \'serviceAccountJson\' were provided! \'serviceAccountJson\' will be ignored.')
@@ -127,8 +115,7 @@ async function validateServiceAccountJson(serviceAccountJsonRaw: string | undefi
core.exportVariable("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountJson)
} else {
// If the user provided neither, fail and exit
core.setFailed("You must provide one of 'serviceAccountJsonPlainText' or 'serviceAccountJson' to use this action")
exit()
return Promise.reject("You must provide one of 'serviceAccountJsonPlainText' or 'serviceAccountJson' to use this action")
}
}