Skip to content

Commit

Permalink
feature: Infer status from provided parameters (r0adkll#122)
Browse files Browse the repository at this point in the history
* Mark status as deprecated

* Make userFraction required & provide a default
We'll use this to infer `inProgress` or `completed`

* Infer status from userFraction

* Fix workflow

* Update README

* Run build

* Add support for drafts again

* Pass in isDraft

* Warn about setting draft and userFraction simultaneously

* Expose isDraft

* Do a build

* Allow passing status in again
This will be required for draft/halted
It is optional though, if it's not specified, we have updated logic for inferring it

* Update userFraction description

* Revert "Fix workflow"

This reverts commit ad98b3d.

* Remove deprecated tag from status

* Move status back

* Allow 0 userFraction

* Run build
  • Loading branch information
boswelja authored Sep 11, 2022
1 parent 7406d2c commit c16321c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ This action will help you upload an Android `.apk` or `.aab` (Android App Bundle
| track | The track in which you want to assign the uploaded app. Defaults to `production` | One of `production`, `beta`, `alpha`, `internalsharing`, `internal`, or a custom track name (case sensitive) | true |
| releaseName | The release name. Not required to be unique. Default is configured by Google Play Console | A user-friendly update name, e.g. `v1.0.0` | false |
| inAppUpdatePriority | In-app update priority of the release. All newly added APKs in the release will be considered at this priority. Defaults to `0` | `[0-5]`, where `5` is the highest priority | false |
| userFraction | Percentage of users who should get the staged version of the app. Defaults to `1.0` | `(0.0-1.0)` | false |
| status | Release status. This can be set to `draft` to complete the release at some other time. Defaults to `completed` if targeting 100% rollout, else `inProgress` | One of `completed`, `inProgress`, `halted`, `draft` | false |
| userFraction | Percentage of users who should get the staged version of the app. Defaults to `1.0` | `[0.0-1.0]` | true |
| status | Release status. Defaults to `completed` if targeting 100% rollout, `halted` for 0%, and `inProgress` for anything in between | One of `completed`, `inProgress`, `halted`, `draft` | false |
| whatsNewDirectory | The directory of localized "whats new" files to upload as the release notes. The files contained in the `whatsNewDirectory` MUST use the pattern `whatsnew-<LOCALE>` where `LOCALE` is using the [`BCP 47`](https://tools.ietf.org/html/bcp47) format | A path to a valid `whatsNewDirectory` | false |
| mappingFile | The mapping.txt file used to de-obfuscate your stack traces from crash reports | A path to a valid `mapping.txt` file | false |
| changesNotSentForReview | Indicates that the changes in this edit will not be reviewed until they are explicitly sent for review from the Google Play Console. Defaults to `false` | `true` or `false` | `false` |
Expand Down
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ inputs:
required: false
userFraction:
description: "Portion of users who should get the staged version of the app. Accepts values between 0.0 and 1.0 (exclusive-exclusive)."
required: false
required: true
default: 1.0
status:
description: "Release status. This can be set to 'draft' to complete the release at some other time."
required: false
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

13 changes: 3 additions & 10 deletions src/edits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export interface EditOptions {
applicationId: string;
track: string;
inAppUpdatePriority: number;
userFraction?: number;
userFraction: number;
whatsNewDir?: string;
mappingFile?: string;
name?: string;
status?: string;
status: string;
changesNotSentForReview?: boolean;
existingEditId?: string;
}
Expand Down Expand Up @@ -145,14 +145,7 @@ async function validateSelectedTrack(appEditId: string, options: EditOptions): P
}

async function addReleasesToTrack(appEditId: string, options: EditOptions, versionCodes: number[]): Promise<Track> {
let status: string | undefined = options.status;
if (!status) {
if (options.userFraction != undefined) {
status = 'inProgress';
} else {
status = 'completed';
}
}
const status = options.status

core.debug(`Creating Track Release for Edit(${appEditId}) for Track(${options.track}) with a UserFraction(${options.userFraction}), Status(${status}), and VersionCodes(${versionCodes})`);
const res = await androidPublisher.edits.tracks
Expand Down
60 changes: 46 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ async function run() {
const releaseName = core.getInput('releaseName', { required: false });
const track = core.getInput('track', { required: true });
const inAppUpdatePriority = core.getInput('inAppUpdatePriority', { required: false });
const userFraction = core.getInput('userFraction', { required: false });
const status = core.getInput('status', { required: false });
const userFraction = parseFloat(core.getInput('userFraction', { required: true }));
var status = core.getInput('status', { required: false });
const whatsNewDir = core.getInput('whatsNewDirectory', { required: false });
const mappingFile = core.getInput('mappingFile', { required: false });
const changesNotSentForReview = core.getInput('changesNotSentForReview', { required: false }) == 'true';
const existingEditId = core.getInput('existingEditId')
const existingEditId = core.getInput('existingEditId');

// Validate that we have a service account json in some format
if (!serviceAccountJson && !serviceAccountJsonRaw) {
Expand All @@ -52,14 +52,9 @@ async function run() {
}

// Validate user fraction as a number, and within [0.0, 1.0]
let userFractionFloat: number | undefined = parseFloat(userFraction);
if (!isNaN(userFractionFloat)) {
if (userFractionFloat <= 0.0 || userFractionFloat >= 1.0) {
core.setFailed('A provided userFraction must be between 0.0 and 1.0, inclusive-inclusive');
return;
}
} else {
userFractionFloat = undefined;
if (userFraction < 0.0 || userFraction > 1.0) {
core.setFailed('A provided userFraction must be between 0.0 and 1.0, inclusive-inclusive');
return;
}

// Validate the inAppUpdatePriority to be a valid number in within [0, 5]
Expand Down Expand Up @@ -97,6 +92,12 @@ async function run() {
validatedReleaseFiles = files;
}

if (status != undefined) {
if (!validateStatus(status, userFraction)) return
} else {
status = inferStatus(userFraction)
}

if (whatsNewDir != undefined && whatsNewDir.length > 0 && !fs.existsSync(whatsNewDir)) {
core.setFailed(`Unable to find 'whatsnew' directory @ ${whatsNewDir}`);
return
Expand All @@ -114,13 +115,13 @@ async function run() {
applicationId: packageName,
track: track,
inAppUpdatePriority: inAppUpdatePriorityInt || 0,
userFraction: userFractionFloat,
status: status,
userFraction: userFraction,
whatsNewDir: whatsNewDir,
mappingFile: mappingFile,
name: releaseName,
changesNotSentForReview: changesNotSentForReview,
existingEditId: existingEditId
existingEditId: existingEditId,
status: status
}, validatedReleaseFiles);

console.log(`Finished uploading to the Play Store: ${result}`)
Expand All @@ -135,4 +136,35 @@ async function run() {
}
}

function inferStatus(userFraction: number): string {
let status: string
if (userFraction >= 1.0) {
status = 'completed'
} else if (userFraction > 0) {
status = 'inProgress'
} else {
status = 'halted'
}
core.info("Inferred status to be " + status)
return status
}

function validateStatus(status: string, userFraction: number): boolean {
switch (status) {
case 'completed':
if (userFraction < 1.0) {
core.setFailed("Status 'completed' requires 'userFraction' 1.0")
return false
}
break
case 'inProgress':
if (userFraction >= 1.0 && userFraction <= 0) {
core.setFailed("Status 'inProgress' requires 'userFraction' between 0.0 and 1.0")
return false
}
break
}
return true
}

run();

0 comments on commit c16321c

Please sign in to comment.