Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
935ef9c68b | ||
|
|
84ffa89623 | ||
|
|
b6837fa35c | ||
|
|
7c9dfbb03e | ||
|
|
9cf8fd30c9 | ||
|
|
101c2cddf9 | ||
|
|
d17e3fc745 | ||
|
|
70c7397e86 | ||
|
|
853233422d | ||
|
|
9a5e7fcdd5 | ||
|
|
02c72d76fe | ||
|
|
cd131e853c | ||
|
|
8a353d6e46 | ||
|
|
d5cf6e9445 | ||
|
|
b9dc4464a6 | ||
|
|
974d2d7566 | ||
|
|
536f822b60 | ||
|
|
d7e6e42414 | ||
|
|
78c9e796b1 | ||
|
|
980a5c4201 | ||
|
|
81a2f1ad1c | ||
|
|
b84eace68d | ||
|
|
4d510d380a | ||
|
|
99b7a1e1d4 | ||
|
|
7cd1379b4f | ||
|
|
b028ed83b3 | ||
|
|
5427bcbe2b | ||
|
|
6a74f079de | ||
|
|
c16321c553 |
15
.eslintrc.cjs
Normal file
15
.eslintrc.cjs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
parserOptions: {
|
||||||
|
tsconfigRootDir: __dirname,
|
||||||
|
project: ['./tsconfig.json'],
|
||||||
|
},
|
||||||
|
plugins: ['@typescript-eslint'],
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
||||||
|
],
|
||||||
|
ignorePatterns: ["lib/*.js", "jest.config.js", "__tests__/**"]
|
||||||
|
};
|
||||||
2
.github/workflows/pr-validation.yml
vendored
2
.github/workflows/pr-validation.yml
vendored
@@ -28,7 +28,7 @@ jobs:
|
|||||||
|
|
||||||
# Check whether the compiled library changed
|
# Check whether the compiled library changed
|
||||||
- name: Check Build Updated
|
- name: Check Build Updated
|
||||||
uses: tj-actions/verify-changed-files@v9.2
|
uses: tj-actions/verify-changed-files@v17
|
||||||
id: verify-built-lib
|
id: verify-built-lib
|
||||||
with:
|
with:
|
||||||
files: lib/index.js
|
files: lib/index.js
|
||||||
|
|||||||
24
.github/workflows/release.yml
vendored
24
.github/workflows/release.yml
vendored
@@ -1,24 +1,16 @@
|
|||||||
name: "Tag & Deploy Action"
|
name: "Update v1 tag"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
release:
|
||||||
branches:
|
types: [released]
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2.5.0
|
||||||
|
|
||||||
- name: Install
|
- uses: rickstaa/action-create-tag@v1
|
||||||
run: npm ci
|
with:
|
||||||
|
tag: v1
|
||||||
- name: Run Tests
|
force_push_tag: true
|
||||||
run: npm run test
|
|
||||||
|
|
||||||
- name: Update v1 Tag
|
|
||||||
uses: hole19/git-tag-action@master
|
|
||||||
env:
|
|
||||||
TAG: v1
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|||||||
28
README.md
28
README.md
@@ -8,14 +8,15 @@ This action will help you upload an Android `.apk` or `.aab` (Android App Bundle
|
|||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| releaseFiles | The Android release file(s) to upload (.apk or .aab) | Comma-separated paths. Supports glob via [fast-glob](https://github.com/mrmlnc/fast-glob) | true |
|
| releaseFiles | The Android release file(s) to upload (.apk or .aab) | Comma-separated paths. Supports glob via [fast-glob](https://github.com/mrmlnc/fast-glob) | true |
|
||||||
| serviceAccountJsonPlainText | The service account json in plain text, provided via a secret, etc | The contents of your `service-account.json` | true (or serviceAccountJson) |
|
| serviceAccountJsonPlainText | The service account json in plain text, provided via a secret, etc | The contents of your `service-account.json` | true (or serviceAccountJson) |
|
||||||
| packageName | The package name, or Application Id, of the app you are uploading | A valid package name, e.g. `com.example.myapp` | true |
|
| packageName | The package name, or Application Id, of the app you are uploading | A valid package name, e.g. `com.example.myapp`. The packageName must already exist in the play console account, so make sure you upload a manual apk or aab first through the console | true |
|
||||||
| 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 |
|
| track | The track in which you want to assign the uploaded app. Defaults to `production` | See [APKs and Tracks](https://developers.google.com/android-publisher/tracks#adding_and_modifying_apks) documentation for calculating your target track name | 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 |
|
| 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 |
|
| 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 |
|
| userFraction | Percentage of users who should get the staged version of the app. | `(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 |
|
| status | Release status. Defaults to `completed`. | One of `completed`, `inProgress`, `halted`, `draft`. Cannot be null. | 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 |
|
| 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 |
|
| mappingFile | The mapping.txt file used to de-obfuscate your stack traces from crash reports | A path to a valid `mapping.txt` file | false |
|
||||||
|
| debugSymbols | The native-debug-symbols.zip file or folder that contains your debug symbols | A path to a valid `native-debug-symbols.zip file` file or a folder | 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` |
|
| 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` |
|
||||||
| serviceAccountJson | The service account json private key file to authorize the upload request. Can be used instead of `serviceAccountJsonPlainText` to specify a file rather than provide a secret | A path to a valid `service-account.json` file | true (or serviceAccountJsonPlainText) |
|
| serviceAccountJson | The service account json private key file to authorize the upload request. Can be used instead of `serviceAccountJsonPlainText` to specify a file rather than provide a secret | A path to a valid `service-account.json` file | true (or serviceAccountJsonPlainText) |
|
||||||
| existingEditId | The ID of an existing edit that has not been completed. If this is supplied, the action will append information to that rather than creating an edit | A valid, unpublished Edit ID | false |
|
| existingEditId | The ID of an existing edit that has not been completed. If this is supplied, the action will append information to that rather than creating an edit | A valid, unpublished Edit ID | false |
|
||||||
@@ -44,8 +45,27 @@ with:
|
|||||||
userFraction: 0.33
|
userFraction: 0.33
|
||||||
whatsNewDirectory: distribution/whatsnew
|
whatsNewDirectory: distribution/whatsnew
|
||||||
mappingFile: app/build/outputs/mapping/release/mapping.txt
|
mappingFile: app/build/outputs/mapping/release/mapping.txt
|
||||||
|
debugSymbols: app/intermediates/merged_native_libs/release/out/lib
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Configure service account
|
||||||
|
1. Configure service account in Google Cloud Platform
|
||||||
|
1. Navigate to https://cloud.google.com/gcp
|
||||||
|
1. Open IAM and admin > Service accounts > Create service account
|
||||||
|
1. Pick a name and add appropriate permissions (e.g. 'owner)
|
||||||
|
1. Open the newly created service account, click on `keys` tab and add a new key, JSON type
|
||||||
|
1. When successful, a JSON file will be automatically downloaded on your machine
|
||||||
|
1. Store the content of this file to your GitHub secrets, e.g. SERVICE_ACCOUNT_JSON.
|
||||||
|
1. Add user to Google Play Console
|
||||||
|
1. Open https://play.google.com/console and pick your developer account
|
||||||
|
1. Open Users and permissions
|
||||||
|
1. Click invite new user and add the email of the service account created in the previous step
|
||||||
|
1. Grant permissions to the app that you want the service account to deploy in `app permissions`
|
||||||
|
|
||||||
|
## FAQ
|
||||||
|
### I get the error "Package not found"
|
||||||
|
Make sure you upload an apk or aab manually first by creating a release through the play console.
|
||||||
|
|
||||||
The `whatsNewDirectory` in this example supplies changelogs for English, German and Japanese
|
The `whatsNewDirectory` in this example supplies changelogs for English, German and Japanese
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
74
__tests__/input-validation.test.ts
Normal file
74
__tests__/input-validation.test.ts
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import { validateInAppUpdatePriority, validateReleaseFiles, validateStatus, validateUserFraction } from "../src/input-validation"
|
||||||
|
|
||||||
|
test("invalid in-app update priority fails validation", async () => {
|
||||||
|
const testValues = [-1, 6, -1000, 1000]
|
||||||
|
for (const value of testValues) {
|
||||||
|
await expect(validateInAppUpdatePriority(value)).rejects.toThrowError()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("valid in-app update priority passes validation", async () => {
|
||||||
|
const testValues = [0, 1, 2, 3, 4, 5, undefined]
|
||||||
|
for (const value of testValues) {
|
||||||
|
await validateInAppUpdatePriority(value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("invalid releaseFiles glob fails validation", async () => {
|
||||||
|
const testValues = ['./__tests__/releasefiles/*.null', `./__tests__/releasefiles/nonexistent-release.aab`]
|
||||||
|
await expect(validateReleaseFiles(testValues)).rejects.toThrowError()
|
||||||
|
})
|
||||||
|
|
||||||
|
test("valid releaseFiles glob passes validation", async () => {
|
||||||
|
const testValues = ['./__tests__/releasefiles/*.aab', `./__tests__/releasefiles/release.aab`]
|
||||||
|
await validateReleaseFiles(testValues)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("fractionless status without fraction passes validation", async () => {
|
||||||
|
const testValues = ['completed', 'draft']
|
||||||
|
for (const value of testValues) {
|
||||||
|
await validateStatus(value, false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("fractionless status with fraction fails validation", async () => {
|
||||||
|
const testValues = ['completed', 'draft']
|
||||||
|
for (const value of testValues) {
|
||||||
|
await expect(validateStatus(value, true)).rejects.toThrowError()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("fractioned status without fraction fails validation", async () => {
|
||||||
|
const testValues = ['inProgress', 'halted']
|
||||||
|
for (const value of testValues) {
|
||||||
|
await expect(validateStatus(value, false)).rejects.toThrowError()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("fractioned status with fraction passes validation", async () => {
|
||||||
|
const testValues = ['inProgress', 'halted']
|
||||||
|
for (const value of testValues) {
|
||||||
|
await validateStatus(value, true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("invalid status fails validation", async () => {
|
||||||
|
const testValues = ['statusGoBrrr', undefined]
|
||||||
|
for (const value of testValues) {
|
||||||
|
await expect(validateStatus(value, true)).rejects.toThrowError()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("invalid user fraction fails validation", async () => {
|
||||||
|
const testValues = [0, 1, -1, 2, NaN]
|
||||||
|
for (const value of testValues) {
|
||||||
|
await expect(validateUserFraction(value)).rejects.toThrowError()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("valid user fraction passes validation", async () => {
|
||||||
|
const testValues = [0.1, 0.9, 0.5, undefined]
|
||||||
|
for (const value of testValues) {
|
||||||
|
await validateUserFraction(value)
|
||||||
|
}
|
||||||
|
})
|
||||||
109
__tests__/main.test.ts
Normal file
109
__tests__/main.test.ts
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
import {RunOptions, RunTarget} from 'github-action-ts-run-api';
|
||||||
|
|
||||||
|
const target = RunTarget.mainJs('action.yml');
|
||||||
|
|
||||||
|
async function expectRunInitiatesUpload(options: RunOptions) {
|
||||||
|
const result = await target.run(options)
|
||||||
|
expect(result.commands.errors.length).toBe(1)
|
||||||
|
expect(result.commands.errors).toContainEqual("The incoming JSON object does not contain a client_email field")
|
||||||
|
}
|
||||||
|
|
||||||
|
test("correct bare minimum inputs", async () => {
|
||||||
|
const minimumOptions = RunOptions.create()
|
||||||
|
.setInputs({
|
||||||
|
serviceAccountJsonPlainText: "{}",
|
||||||
|
packageName: "com.package.name",
|
||||||
|
releaseFiles: "./__tests__/releasefiles/*.aab",
|
||||||
|
track: "production",
|
||||||
|
})
|
||||||
|
await expectRunInitiatesUpload(minimumOptions)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("correct inputs for complete rollout", async () => {
|
||||||
|
// Run with the bare minimum
|
||||||
|
const minimumOptions = RunOptions.create()
|
||||||
|
.setInputs({
|
||||||
|
serviceAccountJsonPlainText: "{}",
|
||||||
|
packageName: "com.package.name",
|
||||||
|
releaseFiles: "./__tests__/releasefiles/*.aab",
|
||||||
|
track: "production",
|
||||||
|
status: "completed",
|
||||||
|
})
|
||||||
|
await expectRunInitiatesUpload(minimumOptions)
|
||||||
|
|
||||||
|
// Test with optional extras
|
||||||
|
const extraOptions = RunOptions.create()
|
||||||
|
.setInputs({
|
||||||
|
serviceAccountJsonPlainText: "{}",
|
||||||
|
packageName: "com.package.name",
|
||||||
|
releaseFiles: "./__tests__/releasefiles/*.aab",
|
||||||
|
releaseName: "Release name",
|
||||||
|
track: "production",
|
||||||
|
inAppUpdatePriority: "3",
|
||||||
|
status: "completed",
|
||||||
|
whatsNewDir: "./__tests__/whatsnew",
|
||||||
|
changesNotSentForReview: "true",
|
||||||
|
existingEditId: "123"
|
||||||
|
})
|
||||||
|
await expectRunInitiatesUpload(extraOptions)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("correct inputs for inProgress rollout", async () => {
|
||||||
|
// Run with the bare minimum
|
||||||
|
const minimumOptions = RunOptions.create()
|
||||||
|
.setInputs({
|
||||||
|
serviceAccountJsonPlainText: "{}",
|
||||||
|
packageName: "com.package.name",
|
||||||
|
releaseFiles: "./__tests__/releasefiles/*.aab",
|
||||||
|
track: "production",
|
||||||
|
userFraction: "0.99",
|
||||||
|
status: "inProgress",
|
||||||
|
})
|
||||||
|
await expectRunInitiatesUpload(minimumOptions)
|
||||||
|
|
||||||
|
// Test with optional extras
|
||||||
|
const extraOptions = RunOptions.create()
|
||||||
|
.setInputs({
|
||||||
|
serviceAccountJsonPlainText: "{}",
|
||||||
|
packageName: "com.package.name",
|
||||||
|
releaseFiles: "./__tests__/releasefiles/*.aab",
|
||||||
|
releaseName: "Release name",
|
||||||
|
track: "production",
|
||||||
|
inAppUpdatePriority: "3",
|
||||||
|
userFraction: "0.5",
|
||||||
|
status: "inProgress",
|
||||||
|
whatsNewDir: "./__tests__/whatsnew",
|
||||||
|
changesNotSentForReview: "true",
|
||||||
|
existingEditId: "123"
|
||||||
|
})
|
||||||
|
await expectRunInitiatesUpload(extraOptions)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("correct inputs for draft rollout", async () => {
|
||||||
|
// Run with the bare minimum
|
||||||
|
const minimumOptions = RunOptions.create()
|
||||||
|
.setInputs({
|
||||||
|
serviceAccountJsonPlainText: "{}",
|
||||||
|
packageName: "com.package.name",
|
||||||
|
releaseFiles: "./__tests__/releasefiles/*.aab",
|
||||||
|
track: "production",
|
||||||
|
status: "draft",
|
||||||
|
})
|
||||||
|
await expectRunInitiatesUpload(minimumOptions)
|
||||||
|
|
||||||
|
// Test with optional extras
|
||||||
|
const extraOptions = RunOptions.create()
|
||||||
|
.setInputs({
|
||||||
|
serviceAccountJsonPlainText: "{}",
|
||||||
|
packageName: "com.package.name",
|
||||||
|
releaseFiles: "./__tests__/releasefiles/*.aab",
|
||||||
|
releaseName: "Release name",
|
||||||
|
track: "production",
|
||||||
|
inAppUpdatePriority: "3",
|
||||||
|
status: "draft",
|
||||||
|
whatsNewDir: "./__tests__/whatsnew",
|
||||||
|
changesNotSentForReview: "true",
|
||||||
|
existingEditId: "123"
|
||||||
|
})
|
||||||
|
await expectRunInitiatesUpload(extraOptions)
|
||||||
|
})
|
||||||
0
__tests__/releasefiles/release.aab
Normal file
0
__tests__/releasefiles/release.aab
Normal file
@@ -1,12 +1,7 @@
|
|||||||
import * as process from 'process'
|
|
||||||
import * as cp from 'child_process'
|
|
||||||
import * as path from 'path'
|
|
||||||
import {readLocalizedReleaseNotes} from "../src/whatsnew";
|
import {readLocalizedReleaseNotes} from "../src/whatsnew";
|
||||||
import {androidpublisher_v3} from "@googleapis/androidpublisher";
|
|
||||||
import LocalizedText = androidpublisher_v3.Schema$LocalizedText;
|
|
||||||
|
|
||||||
test("read localized whatsnew files", async () => {
|
test("read localized whatsnew files", async () => {
|
||||||
let texts = await readLocalizedReleaseNotes("./__tests__");
|
let texts = await readLocalizedReleaseNotes("./__tests__/whatsnew");
|
||||||
expect(texts).toHaveLength(6);
|
expect(texts).toHaveLength(6);
|
||||||
expect(texts).toContainEqual({
|
expect(texts).toContainEqual({
|
||||||
language: "en-US",
|
language: "en-US",
|
||||||
@@ -32,4 +27,4 @@ test("read localized whatsnew files", async () => {
|
|||||||
language: "et",
|
language: "et",
|
||||||
text: "test_changelog_file_estonian"
|
text: "test_changelog_file_estonian"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
10
action.yml
10
action.yml
@@ -36,16 +36,20 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
status:
|
status:
|
||||||
description: "Release status. This can be set to 'draft' to complete the release at some other time."
|
description: "Release status. This can be set to 'draft' to complete the release at some other time."
|
||||||
required: false
|
required: true
|
||||||
|
default: "completed"
|
||||||
whatsNewDirectory:
|
whatsNewDirectory:
|
||||||
description: "The directory of localized whats new files"
|
description: "The directory of localized whats new files"
|
||||||
required: false
|
required: false
|
||||||
mappingFile:
|
mappingFile:
|
||||||
description: "The mapping.txt file used to de-obfuscate your stack traces from crash reports"
|
description: "The mapping.txt file used to de-obfuscate your stack traces from crash reports"
|
||||||
required: false
|
required: false
|
||||||
|
debugSymbols:
|
||||||
|
description: "The native-debug-symbols.zip file or folder that contains your debug symbols"
|
||||||
|
required: false
|
||||||
changesNotSentForReview:
|
changesNotSentForReview:
|
||||||
description: "Indicates that the changes in this edit will not be reviewed until they are explicitly sent for review from the Google Play Console"
|
description: "Indicates that the changes in this edit will not be reviewed until they are explicitly sent for review from the Google Play Console"
|
||||||
default: false
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
existingEditId:
|
existingEditId:
|
||||||
description: "The ID of an existing edit that has not been completed. If this is supplied, the action will append information to that rather than creating an edit"
|
description: "The ID of an existing edit that has not been completed. If this is supplied, the action will append information to that rather than creating an edit"
|
||||||
@@ -54,5 +58,5 @@ outputs:
|
|||||||
internalSharingDownloadUrl:
|
internalSharingDownloadUrl:
|
||||||
description: "The internal app sharing download url if track was 'internalsharing'"
|
description: "The internal app sharing download url if track was 'internalsharing'"
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node20'
|
||||||
main: 'lib/index.js'
|
main: 'lib/index.js'
|
||||||
|
|||||||
20
lib/index.js
20
lib/index.js
File diff suppressed because one or more lines are too long
6040
package-lock.json
generated
6040
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
26
package.json
26
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "upload-google-play",
|
"name": "upload-google-play",
|
||||||
"version": "1.0.17",
|
"version": "1.1.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Upload an Android release (.apk or .aab) to Google Play Console",
|
"description": "Upload an Android release (.apk or .aab) to Google Play Console",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
@@ -20,16 +20,22 @@
|
|||||||
"author": "r0adkll",
|
"author": "r0adkll",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.9.1",
|
"@actions/core": "^1.10.1",
|
||||||
"@googleapis/androidpublisher": "^3.0.0",
|
"@googleapis/androidpublisher": "^12.1.0",
|
||||||
"fast-glob": "^3.2.12"
|
"fast-glob": "^3.3.2",
|
||||||
|
"jszip": "^3.10.1",
|
||||||
|
"p-timeout": "^6.1.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^29.0.0",
|
"@types/jest": "^29.5.12",
|
||||||
"@types/node": "^18.7.16",
|
"@types/node": "^20.11.17",
|
||||||
"@vercel/ncc": "^0.34.0",
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
||||||
"jest": "^29.0.3",
|
"@typescript-eslint/parser": "^6.21.0",
|
||||||
"ts-jest": "^29.0.0",
|
"@vercel/ncc": "^0.38.1",
|
||||||
"typescript": "^4.8.3"
|
"eslint": "^8.56.0",
|
||||||
|
"github-action-ts-run-api": "^3.0.4",
|
||||||
|
"jest": "^29.7.0",
|
||||||
|
"ts-jest": "^29.1.2",
|
||||||
|
"typescript": "^5.3.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
313
src/edits.ts
313
src/edits.ts
@@ -1,6 +1,9 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync, lstatSync } from "fs";
|
||||||
|
import JSZip from 'jszip';
|
||||||
|
import path = require('path');
|
||||||
|
import { Readable } from 'stream';
|
||||||
|
|
||||||
import * as google from '@googleapis/androidpublisher';
|
import * as google from '@googleapis/androidpublisher';
|
||||||
import { androidpublisher_v3 } from "@googleapis/androidpublisher";
|
import { androidpublisher_v3 } from "@googleapis/androidpublisher";
|
||||||
@@ -10,151 +13,175 @@ import Apk = androidpublisher_v3.Schema$Apk;
|
|||||||
import Bundle = androidpublisher_v3.Schema$Bundle;
|
import Bundle = androidpublisher_v3.Schema$Bundle;
|
||||||
import Track = androidpublisher_v3.Schema$Track;
|
import Track = androidpublisher_v3.Schema$Track;
|
||||||
import InternalAppSharingArtifact = androidpublisher_v3.Schema$InternalAppSharingArtifact;
|
import InternalAppSharingArtifact = androidpublisher_v3.Schema$InternalAppSharingArtifact;
|
||||||
import { Compute } from "google-auth-library/build/src/auth/computeclient";
|
import { GoogleAuth } from "google-auth-library/build/src/auth/googleauth"
|
||||||
import { JSONClient } from "google-auth-library/build/src/auth/googleauth"
|
|
||||||
import { readLocalizedReleaseNotes } from "./whatsnew";
|
import { readLocalizedReleaseNotes } from "./whatsnew";
|
||||||
|
|
||||||
const androidPublisher: AndroidPublisher = google.androidpublisher('v3');
|
const androidPublisher: AndroidPublisher = google.androidpublisher('v3');
|
||||||
|
|
||||||
export interface EditOptions {
|
export interface EditOptions {
|
||||||
auth: Compute | JSONClient;
|
auth: GoogleAuth;
|
||||||
applicationId: string;
|
applicationId: string;
|
||||||
track: string;
|
track: string;
|
||||||
inAppUpdatePriority: number;
|
inAppUpdatePriority: number;
|
||||||
userFraction?: number;
|
userFraction?: number;
|
||||||
whatsNewDir?: string;
|
whatsNewDir?: string;
|
||||||
mappingFile?: string;
|
mappingFile?: string;
|
||||||
|
debugSymbols?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
status?: string;
|
status: string;
|
||||||
changesNotSentForReview?: boolean;
|
changesNotSentForReview?: boolean;
|
||||||
existingEditId?: string;
|
existingEditId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function uploadToPlayStore(options: EditOptions, releaseFiles: string[]): Promise<string | undefined> {
|
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 result = await uploadToPlayStore({
|
||||||
|
auth: auth,
|
||||||
|
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> {
|
||||||
|
const internalSharingDownloadUrls: string[] = []
|
||||||
|
|
||||||
// Check the 'track' for 'internalsharing', if so switch to a non-track api
|
// Check the 'track' for 'internalsharing', if so switch to a non-track api
|
||||||
if (options.track === 'internalsharing') {
|
if (options.track === 'internalsharing') {
|
||||||
core.debug("Track is Internal app sharing, switch to special upload api")
|
core.debug("Track is Internal app sharing, switch to special upload api")
|
||||||
let downloadUrls: string[] = []
|
|
||||||
for (const releaseFile of releaseFiles) {
|
for (const releaseFile of releaseFiles) {
|
||||||
core.debug(`Uploading ${releaseFile}`);
|
core.debug(`Uploading ${releaseFile}`);
|
||||||
await uploadInternalSharingRelease(options, releaseFile)
|
const url = await uploadInternalSharingRelease(options, releaseFile)
|
||||||
.then(downloadUrl => {
|
internalSharingDownloadUrls.push(url)
|
||||||
downloadUrls.push(downloadUrl as string)
|
|
||||||
})
|
|
||||||
.catch(reason => {
|
|
||||||
core.setFailed(reason);
|
|
||||||
return Promise.reject(reason);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
core.setOutput("internalSharingDownloadUrls", downloadUrls);
|
|
||||||
core.exportVariable("INTERNAL_SHARING_DOWNLOAD_URLS", downloadUrls);
|
|
||||||
} else {
|
} else {
|
||||||
// Create a new Edit
|
// Create a new Edit
|
||||||
core.info(`Creating a new Edit for this release`)
|
const appEditId = await getOrCreateEdit(options)
|
||||||
const appEditId = options.existingEditId || (await androidPublisher.edits.insert({
|
|
||||||
auth: options.auth,
|
|
||||||
packageName: options.applicationId
|
|
||||||
})).data.id
|
|
||||||
|
|
||||||
// Validate the given track
|
// Validate the given track
|
||||||
core.info(`Validating track '${options.track}'`)
|
await validateSelectedTrack(appEditId, options)
|
||||||
await validateSelectedTrack(appEditId!, options).catch(reason => {
|
|
||||||
core.setFailed(reason);
|
|
||||||
return Promise.reject(reason);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Upload artifacts to Google Play, and store their version codes
|
// Upload artifacts to Google Play, and store their version codes
|
||||||
const versionCodes = new Array<number>();
|
const versionCodes = await uploadReleaseFiles(appEditId, options, releaseFiles)
|
||||||
for (const releaseFile of releaseFiles) {
|
|
||||||
core.info(`Uploading ${releaseFile}`);
|
// Infer the download URL from the version codes
|
||||||
const versionCode = await uploadRelease(appEditId!, options, releaseFile).catch(reason => {
|
for (const versionCode of versionCodes) {
|
||||||
core.setFailed(reason);
|
const url = inferInternalSharingDownloadUrl(options.applicationId, versionCode);
|
||||||
return Promise.reject(reason);
|
core.setOutput("internalSharingDownloadUrl", url);
|
||||||
});
|
core.exportVariable("INTERNAL_SHARING_DOWNLOAD_URL", url);
|
||||||
versionCodes.push(versionCode!);
|
internalSharingDownloadUrls.push(url);
|
||||||
}
|
}
|
||||||
core.info(`Successfully uploaded ${versionCodes.length} artifacts`)
|
|
||||||
|
|
||||||
// Add the uploaded artifacts to the Edit track
|
// Add the uploaded artifacts to the Edit track
|
||||||
core.info(`Adding ${versionCodes.length} artifacts to release on '${options.track}' track`)
|
await addReleasesToTrack(appEditId, options, versionCodes);
|
||||||
const track = await addReleasesToTrack(appEditId!, options, versionCodes);
|
|
||||||
core.debug(`Track: ${track}`);
|
|
||||||
|
|
||||||
// Commit the pending Edit
|
// Commit the pending Edit
|
||||||
core.info(`Committing the Edit`)
|
core.info(`Committing the Edit`)
|
||||||
const res = await androidPublisher.edits.commit({
|
const res = await androidPublisher.edits.commit({
|
||||||
auth: options.auth,
|
auth: options.auth,
|
||||||
editId: appEditId!,
|
editId: appEditId,
|
||||||
packageName: options.applicationId,
|
packageName: options.applicationId,
|
||||||
changesNotSentForReview: options.changesNotSentForReview
|
changesNotSentForReview: options.changesNotSentForReview
|
||||||
});
|
});
|
||||||
|
|
||||||
// Simple check to see whether commit was successful
|
// Simple check to see whether commit was successful
|
||||||
if (res.data.id != null) {
|
if (res.data.id) {
|
||||||
core.info(`Successfully committed ${res.data.id}`);
|
core.info(`Successfully committed ${res.data.id}`);
|
||||||
return Promise.resolve(res.data.id!);
|
return res.data.id
|
||||||
} else {
|
} else {
|
||||||
core.setFailed(`Error ${res.status}: ${res.statusText}`);
|
core.setFailed(`Error ${res.status}: ${res.statusText}`);
|
||||||
return Promise.reject(res.status);
|
return Promise.reject(res.status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.setOutput("internalSharingDownloadUrls", internalSharingDownloadUrls);
|
||||||
|
core.exportVariable("INTERNAL_SHARING_DOWNLOAD_URLS", internalSharingDownloadUrls);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadInternalSharingRelease(options: EditOptions, releaseFile: string): Promise<string | undefined | null> {
|
async function uploadInternalSharingRelease(options: EditOptions, releaseFile: string): Promise<string> {
|
||||||
|
let res: google.androidpublisher_v3.Schema$InternalAppSharingArtifact
|
||||||
if (releaseFile.endsWith('.apk')) {
|
if (releaseFile.endsWith('.apk')) {
|
||||||
const res = await internalSharingUploadApk(options, releaseFile)
|
res = await internalSharingUploadApk(options, releaseFile)
|
||||||
core.setOutput("internalSharingDownloadUrl", res.downloadUrl);
|
|
||||||
core.exportVariable("INTERNAL_SHARING_DOWNLOAD_URL", res.downloadUrl);
|
|
||||||
console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`)
|
|
||||||
return Promise.resolve(res.downloadUrl)
|
|
||||||
} else if (releaseFile.endsWith('.aab')) {
|
} else if (releaseFile.endsWith('.aab')) {
|
||||||
const res = await internalSharingUploadBundle(options, releaseFile)
|
res = await internalSharingUploadBundle(options, releaseFile)
|
||||||
core.setOutput("internalSharingDownloadUrl", res.downloadUrl);
|
|
||||||
core.exportVariable("INTERNAL_SHARING_DOWNLOAD_URL", res.downloadUrl);
|
|
||||||
console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`)
|
|
||||||
return Promise.resolve(res.downloadUrl)
|
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(`${releaseFile} is invalid`)
|
throw Error(`${releaseFile} is invalid (missing or invalid file extension).`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!res.downloadUrl) throw Error('Uploaded file has no download URL.')
|
||||||
|
core.setOutput("internalSharingDownloadUrl", res.downloadUrl);
|
||||||
|
core.exportVariable("INTERNAL_SHARING_DOWNLOAD_URL", res.downloadUrl);
|
||||||
|
console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`)
|
||||||
|
|
||||||
|
return res.downloadUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadRelease(appEditId: string, options: EditOptions, releaseFile: string): Promise<number | undefined | null> {
|
async function validateSelectedTrack(appEditId: string, options: EditOptions): Promise<void> {
|
||||||
if (releaseFile.endsWith('.apk')) {
|
core.info(`Validating track '${options.track}'`)
|
||||||
const apk = await uploadApk(appEditId, options, releaseFile);
|
|
||||||
await uploadMappingFile(appEditId, apk.versionCode!, options);
|
|
||||||
return Promise.resolve(apk.versionCode);
|
|
||||||
} else if (releaseFile.endsWith('.aab')) {
|
|
||||||
const bundle = await uploadBundle(appEditId, options, releaseFile);
|
|
||||||
await uploadMappingFile(appEditId, bundle.versionCode!, options);
|
|
||||||
return Promise.resolve(bundle.versionCode);
|
|
||||||
} else {
|
|
||||||
return Promise.reject(`${releaseFile} is invalid`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function validateSelectedTrack(appEditId: string, options: EditOptions): Promise<undefined> {
|
|
||||||
const res = await androidPublisher.edits.tracks.list({
|
const res = await androidPublisher.edits.tracks.list({
|
||||||
auth: options.auth,
|
auth: options.auth,
|
||||||
editId: appEditId,
|
editId: appEditId,
|
||||||
packageName: options.applicationId
|
packageName: options.applicationId
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If we didn't get status 200, i.e. success, propagate the error with valid text
|
||||||
|
if (res.status != 200) {
|
||||||
|
throw Error(res.statusText)
|
||||||
|
}
|
||||||
|
|
||||||
const allTracks = res.data.tracks;
|
const allTracks = res.data.tracks;
|
||||||
if (allTracks == undefined || allTracks.find(value => value.track == options.track) == undefined) {
|
// Check whether we actually have any tracks
|
||||||
return Promise.reject(`Track "${options.track}" could not be found `);
|
if (!allTracks) {
|
||||||
|
throw Error('No tracks found, unable to validate track.')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check whether the track is valid
|
||||||
|
if (allTracks.find(value => value.track == options.track) == undefined) {
|
||||||
|
const allTrackNames = allTracks.map((track) => { return track.track });
|
||||||
|
throw Error(`Track "${options.track}" could not be found. Available tracks are: ${allTrackNames.toString()}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addReleasesToTrack(appEditId: string, options: EditOptions, versionCodes: number[]): Promise<Track> {
|
async function addReleasesToTrack(appEditId: string, options: EditOptions, versionCodes: number[]): Promise<Track> {
|
||||||
let status: string | undefined = options.status;
|
const status = options.status
|
||||||
if (!status) {
|
|
||||||
if (options.userFraction != undefined) {
|
core.debug(`Creating release for:`);
|
||||||
status = 'inProgress';
|
core.debug(`edit=${appEditId}`)
|
||||||
} else {
|
core.debug(`track=${options.track}`)
|
||||||
status = 'completed';
|
if (options.userFraction) {
|
||||||
}
|
core.debug(`userFraction=${options.userFraction}`)
|
||||||
}
|
}
|
||||||
|
core.debug(`status=${status}`)
|
||||||
|
core.debug(`versionCodes=${versionCodes.toString()}`)
|
||||||
|
|
||||||
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
|
const res = await androidPublisher.edits.tracks
|
||||||
.update({
|
.update({
|
||||||
auth: options.auth,
|
auth: options.auth,
|
||||||
@@ -199,6 +226,65 @@ async function uploadMappingFile(appEditId: string, versionCode: number, options
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function uploadDebugSymbolsFile(appEditId: string, versionCode: number, options: EditOptions) {
|
||||||
|
if (options.debugSymbols != undefined && options.debugSymbols.length > 0) {
|
||||||
|
const fileStat = lstatSync(options.debugSymbols);
|
||||||
|
|
||||||
|
let data: Buffer | null = null;
|
||||||
|
if (fileStat.isDirectory()) {
|
||||||
|
data = await createDebugSymbolZipFile(options.debugSymbols);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data == null) {
|
||||||
|
data = readFileSync(options.debugSymbols);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data != null) {
|
||||||
|
core.debug(`[${appEditId}, versionCode=${versionCode}, packageName=${options.applicationId}]: Uploading Debug Symbols file @ ${options.debugSymbols}`);
|
||||||
|
await androidPublisher.edits.deobfuscationfiles.upload({
|
||||||
|
auth: options.auth,
|
||||||
|
packageName: options.applicationId,
|
||||||
|
editId: appEditId,
|
||||||
|
apkVersionCode: versionCode,
|
||||||
|
deobfuscationFileType: 'nativeCode',
|
||||||
|
media: {
|
||||||
|
mimeType: 'application/octet-stream',
|
||||||
|
body: Readable.from(data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function zipFileAddDirectory(root: JSZip | null, dirPath: string, rootPath: string, isRootRoot: boolean) {
|
||||||
|
if (root == null) return root;
|
||||||
|
|
||||||
|
const newRootPath = path.join(rootPath, dirPath);
|
||||||
|
const fileStat = lstatSync(newRootPath);
|
||||||
|
|
||||||
|
if (!fileStat.isDirectory()) {
|
||||||
|
const data = readFileSync(newRootPath);
|
||||||
|
root.file(dirPath, data);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dir = fs.readdirSync(newRootPath);
|
||||||
|
const zipFolder = isRootRoot ? root : root.folder(dirPath);
|
||||||
|
for (let pathIndex = 0; pathIndex < dir.length; pathIndex++) {
|
||||||
|
const underPath = dir[pathIndex];
|
||||||
|
await zipFileAddDirectory(zipFolder, underPath, newRootPath, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createDebugSymbolZipFile(debugSymbolsPath: string) {
|
||||||
|
const zipFile = JSZip();
|
||||||
|
await zipFileAddDirectory(zipFile, ".", debugSymbolsPath, true);
|
||||||
|
|
||||||
|
return zipFile.generateAsync({ type: "nodebuffer" });
|
||||||
|
}
|
||||||
|
|
||||||
async function internalSharingUploadApk(options: EditOptions, apkReleaseFile: string): Promise<InternalAppSharingArtifact> {
|
async function internalSharingUploadApk(options: EditOptions, apkReleaseFile: string): Promise<InternalAppSharingArtifact> {
|
||||||
core.debug(`[packageName=${options.applicationId}]: Uploading Internal Sharing APK @ ${apkReleaseFile}`);
|
core.debug(`[packageName=${options.applicationId}]: Uploading Internal Sharing APK @ ${apkReleaseFile}`);
|
||||||
|
|
||||||
@@ -259,3 +345,70 @@ async function uploadBundle(appEditId: string, options: EditOptions, bundleRelea
|
|||||||
|
|
||||||
return res.data
|
return res.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getOrCreateEdit(options: EditOptions): Promise<string> {
|
||||||
|
// If we already have an ID, just return that
|
||||||
|
if (options.existingEditId) {
|
||||||
|
return options.existingEditId
|
||||||
|
}
|
||||||
|
|
||||||
|
// Else attempt to create a new edit. This will throw if there is an issue
|
||||||
|
core.info(`Creating a new Edit for this release`)
|
||||||
|
const insertResult = await androidPublisher.edits.insert({
|
||||||
|
auth: options.auth,
|
||||||
|
packageName: options.applicationId
|
||||||
|
})
|
||||||
|
|
||||||
|
// If we didn't get status 200, i.e. success, propagate the error with valid text
|
||||||
|
if (insertResult.status != 200) {
|
||||||
|
throw Error(insertResult.statusText)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the result was successful but we have no ID, somethign went horribly wrong
|
||||||
|
if (!insertResult.data.id) {
|
||||||
|
throw Error('New edit has no ID, cannot continue.')
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(`This new edit expires at ${String(insertResult.data.expiryTimeSeconds)}`)
|
||||||
|
// Return the new edit ID
|
||||||
|
return insertResult.data.id
|
||||||
|
}
|
||||||
|
|
||||||
|
async function uploadReleaseFiles(appEditId: string, options: EditOptions, releaseFiles: string[]): Promise<number[]> {
|
||||||
|
const versionCodes: number[] = []
|
||||||
|
// Upload all release files
|
||||||
|
for (const releaseFile of releaseFiles) {
|
||||||
|
core.info(`Uploading ${releaseFile}`)
|
||||||
|
let versionCode: number
|
||||||
|
if (releaseFile.endsWith('.apk')) {
|
||||||
|
// Upload APK, or throw when something goes wrong
|
||||||
|
const apk = await uploadApk(appEditId, options, releaseFile);
|
||||||
|
if (!apk.versionCode) throw Error('Failed to upload APK.')
|
||||||
|
versionCode = apk.versionCode
|
||||||
|
} else if (releaseFile.endsWith('.aab')) {
|
||||||
|
// Upload AAB, or throw when something goes wrong
|
||||||
|
const bundle = await uploadBundle(appEditId, options, releaseFile);
|
||||||
|
if (!bundle.versionCode) throw Error('Failed to upload bundle.')
|
||||||
|
versionCode = bundle.versionCode
|
||||||
|
} else {
|
||||||
|
// Throw if file extension is not right
|
||||||
|
throw Error(`${releaseFile} is invalid.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload version code
|
||||||
|
await uploadMappingFile(appEditId, versionCode, options)
|
||||||
|
await uploadDebugSymbolsFile(appEditId, versionCode, options)
|
||||||
|
versionCodes.push(versionCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
core.info(`Successfully uploaded ${versionCodes.length} artifacts`)
|
||||||
|
|
||||||
|
return versionCodes
|
||||||
|
}
|
||||||
|
|
||||||
|
function inferInternalSharingDownloadUrl(
|
||||||
|
applicationId: string,
|
||||||
|
versionCode: number
|
||||||
|
) {
|
||||||
|
return `https://play.google.com/apps/test/${applicationId}/${versionCode}`;
|
||||||
|
}
|
||||||
56
src/input-validation.ts
Normal file
56
src/input-validation.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import fg from "fast-glob";
|
||||||
|
|
||||||
|
export async function validateUserFraction(userFraction: number | undefined): Promise<void> {
|
||||||
|
if (userFraction != undefined) {
|
||||||
|
// If userFraction was set, perform basic validation
|
||||||
|
if (isNaN(userFraction)) {
|
||||||
|
return Promise.reject(new Error(`'userFraction' must be a number! Got ${userFraction}`))
|
||||||
|
}
|
||||||
|
if (userFraction >= 1 || userFraction <= 0) {
|
||||||
|
return Promise.reject(new Error(`'userFraction' must be between 0 and 1! Got ${userFraction}`))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function validateStatus(status: string | undefined, hasUserFraction: boolean): Promise<void> {
|
||||||
|
// If status was set, perform basic validation
|
||||||
|
if (status != 'completed' && status != 'inProgress' && status != 'halted' && status != 'draft') {
|
||||||
|
return Promise.reject(new Error(`Invalid status provided! Must be one of 'completed', 'inProgress', 'halted', 'draft'. Got ${status ?? "undefined"}`))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate userFraction is correct for the given status
|
||||||
|
switch (status) {
|
||||||
|
case 'completed':
|
||||||
|
case 'draft':
|
||||||
|
if (hasUserFraction) {
|
||||||
|
return Promise.reject(new Error(`Status '${status}' does not support 'userFraction'`))
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'halted':
|
||||||
|
case 'inProgress':
|
||||||
|
if (!hasUserFraction) {
|
||||||
|
return Promise.reject(new Error(`Status '${status}' requires a 'userFraction' to be set`))
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function validateInAppUpdatePriority(inAppUpdatePriority: number | undefined): Promise<void> {
|
||||||
|
if (inAppUpdatePriority) {
|
||||||
|
if (inAppUpdatePriority < 0 || inAppUpdatePriority > 5) {
|
||||||
|
return Promise.reject(new Error('inAppUpdatePriority must be between 0 and 5, inclusive-inclusive'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function validateReleaseFiles(releaseFiles: string[] | undefined): Promise<string[]> {
|
||||||
|
if (!releaseFiles) {
|
||||||
|
return Promise.reject(new Error(`You must provide 'releaseFiles' in your configuration`))
|
||||||
|
} else {
|
||||||
|
const files = await fg(releaseFiles)
|
||||||
|
if (!files.length) {
|
||||||
|
return Promise.reject(new Error(`Unable to find any release file matching ${releaseFiles.join(',')}`))
|
||||||
|
}
|
||||||
|
return files
|
||||||
|
}
|
||||||
|
}
|
||||||
179
src/main.ts
179
src/main.ts
@@ -1,14 +1,11 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core'
|
||||||
import * as fs from "fs";
|
import * as fs from "fs"
|
||||||
import fg from "fast-glob";
|
import { runUpload } from "./edits"
|
||||||
import {uploadToPlayStore} from "./edits";
|
import { validateInAppUpdatePriority, validateReleaseFiles, validateStatus, validateUserFraction } from "./input-validation"
|
||||||
import * as google from '@googleapis/androidpublisher';
|
import { unlink, writeFile } from 'fs/promises'
|
||||||
|
import pTimeout from 'p-timeout'
|
||||||
|
|
||||||
const auth = new google.auth.GoogleAuth({
|
export async function run() {
|
||||||
scopes: ['https://www.googleapis.com/auth/androidpublisher']
|
|
||||||
});
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
try {
|
try {
|
||||||
const serviceAccountJson = core.getInput('serviceAccountJson', { required: false });
|
const serviceAccountJson = core.getInput('serviceAccountJson', { required: false });
|
||||||
const serviceAccountJsonRaw = core.getInput('serviceAccountJsonPlainText', { required: false});
|
const serviceAccountJsonRaw = core.getInput('serviceAccountJsonPlainText', { required: false});
|
||||||
@@ -16,123 +13,113 @@ async function run() {
|
|||||||
const releaseFile = core.getInput('releaseFile', { required: false });
|
const releaseFile = core.getInput('releaseFile', { required: false });
|
||||||
const releaseFiles = core.getInput('releaseFiles', { required: false })
|
const releaseFiles = core.getInput('releaseFiles', { required: false })
|
||||||
?.split(',')
|
?.split(',')
|
||||||
?.filter(x => x !== '') || [];
|
?.filter(x => x !== '');
|
||||||
const releaseName = core.getInput('releaseName', { required: false });
|
const releaseName = core.getInput('releaseName', { required: false });
|
||||||
const track = core.getInput('track', { required: true });
|
const track = core.getInput('track', { required: true });
|
||||||
const inAppUpdatePriority = core.getInput('inAppUpdatePriority', { required: false });
|
const inAppUpdatePriority = core.getInput('inAppUpdatePriority', { required: false });
|
||||||
const userFraction = core.getInput('userFraction', { required: false });
|
const userFraction = core.getInput('userFraction', { required: false })
|
||||||
const status = core.getInput('status', { required: false });
|
const status = core.getInput('status', { required: false });
|
||||||
const whatsNewDir = core.getInput('whatsNewDirectory', { required: false });
|
const whatsNewDir = core.getInput('whatsNewDirectory', { required: false });
|
||||||
const mappingFile = core.getInput('mappingFile', { required: false });
|
const mappingFile = core.getInput('mappingFile', { required: false });
|
||||||
|
const debugSymbols = core.getInput('debugSymbols', { required: false });
|
||||||
const changesNotSentForReview = core.getInput('changesNotSentForReview', { required: false }) == 'true';
|
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
|
await validateServiceAccountJson(serviceAccountJsonRaw, serviceAccountJson)
|
||||||
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");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the user has provided the raw plain text via secrets, or w/e, then write to file and
|
// Validate user fraction
|
||||||
// set appropriate env variable for the auth
|
let userFractionFloat: number | undefined
|
||||||
if (serviceAccountJsonRaw) {
|
if (userFraction) {
|
||||||
const serviceAccountFile = "./serviceAccountJson.json";
|
userFractionFloat = parseFloat(userFraction)
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 {
|
} else {
|
||||||
userFractionFloat = undefined;
|
userFractionFloat = undefined
|
||||||
}
|
}
|
||||||
|
await validateUserFraction(userFractionFloat)
|
||||||
|
|
||||||
|
// Validate release status
|
||||||
|
await validateStatus(status, userFractionFloat != undefined && !isNaN(userFractionFloat))
|
||||||
|
|
||||||
// Validate the inAppUpdatePriority to be a valid number in within [0, 5]
|
// Validate the inAppUpdatePriority to be a valid number in within [0, 5]
|
||||||
let inAppUpdatePriorityInt: number | undefined = parseInt(inAppUpdatePriority);
|
let inAppUpdatePriorityInt: number | undefined
|
||||||
if (!isNaN(inAppUpdatePriorityInt)) {
|
if (inAppUpdatePriority) {
|
||||||
if (inAppUpdatePriorityInt < 0 || inAppUpdatePriorityInt > 5) {
|
inAppUpdatePriorityInt = parseInt(inAppUpdatePriority)
|
||||||
core.setFailed('inAppUpdatePriority must be between 0 and 5, inclusive-inclusive');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
inAppUpdatePriorityInt = undefined;
|
inAppUpdatePriorityInt = undefined
|
||||||
}
|
}
|
||||||
|
await validateInAppUpdatePriority(inAppUpdatePriorityInt)
|
||||||
|
|
||||||
// Check release files while maintaining backward compatibility
|
// Check release files while maintaining backward compatibility
|
||||||
let validatedReleaseFiles: string[] = [];
|
if (releaseFile) {
|
||||||
if (releaseFiles.length == 0 && !releaseFile) {
|
core.warning(`WARNING!! 'releaseFile' is deprecated and will be removed in a future release. Please migrate to 'releaseFiles'`)
|
||||||
core.setFailed(`You must provide either 'releaseFile' or 'releaseFiles' in your configuration.`);
|
|
||||||
return;
|
|
||||||
} else if (releaseFiles.length == 0 && releaseFile) {
|
|
||||||
core.warning(`WARNING!! 'releaseFile' is deprecated and will be removed in a future release. Please migrate to 'releaseFiles'.`);
|
|
||||||
core.debug(`Validating ${releaseFile} exists`)
|
|
||||||
if (!fs.existsSync(releaseFile)) {
|
|
||||||
core.setFailed(`Unable to find release file @ ${releaseFile}`);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
validatedReleaseFiles = [releaseFile];
|
|
||||||
}
|
|
||||||
} else if (releaseFiles.length > 0) {
|
|
||||||
core.debug(`Finding files ${releaseFiles.join(',')}`)
|
|
||||||
const files = await fg(releaseFiles);
|
|
||||||
if (!files.length) {
|
|
||||||
core.setFailed(`Unable to find any release file @ ${releaseFiles.join(',')}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
validatedReleaseFiles = files;
|
|
||||||
}
|
}
|
||||||
|
const validatedReleaseFiles: string[] = await validateReleaseFiles(releaseFiles ?? [releaseFile])
|
||||||
|
|
||||||
if (whatsNewDir != undefined && whatsNewDir.length > 0 && !fs.existsSync(whatsNewDir)) {
|
if (whatsNewDir != undefined && whatsNewDir.length > 0 && !fs.existsSync(whatsNewDir)) {
|
||||||
core.setFailed(`Unable to find 'whatsnew' directory @ ${whatsNewDir}`);
|
core.warning(`Unable to find 'whatsnew' directory @ ${whatsNewDir}`);
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mappingFile != undefined && mappingFile.length > 0 && !fs.existsSync(mappingFile)) {
|
if (mappingFile != undefined && mappingFile.length > 0 && !fs.existsSync(mappingFile)) {
|
||||||
core.setFailed(`Unable to find 'mappingFile' @ ${mappingFile}`);
|
core.warning(`Unable to find 'mappingFile' @ ${mappingFile}`);
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const authClient = await auth.getClient();
|
if (debugSymbols != undefined && debugSymbols.length > 0 && !fs.existsSync(debugSymbols)) {
|
||||||
|
core.warning(`Unable to find 'debugSymbols' @ ${debugSymbols}`);
|
||||||
|
}
|
||||||
|
|
||||||
const result = await uploadToPlayStore({
|
await pTimeout(
|
||||||
auth: authClient,
|
runUpload(
|
||||||
applicationId: packageName,
|
packageName,
|
||||||
track: track,
|
track,
|
||||||
inAppUpdatePriority: inAppUpdatePriorityInt || 0,
|
inAppUpdatePriorityInt,
|
||||||
userFraction: userFractionFloat,
|
userFractionFloat,
|
||||||
status: status,
|
whatsNewDir,
|
||||||
whatsNewDir: whatsNewDir,
|
mappingFile,
|
||||||
mappingFile: mappingFile,
|
debugSymbols,
|
||||||
name: releaseName,
|
releaseName,
|
||||||
changesNotSentForReview: changesNotSentForReview,
|
changesNotSentForReview,
|
||||||
existingEditId: existingEditId
|
existingEditId,
|
||||||
}, validatedReleaseFiles);
|
status,
|
||||||
|
validatedReleaseFiles
|
||||||
console.log(`Finished uploading to the Play Store: ${result}`)
|
),
|
||||||
} catch (error: any) {
|
{
|
||||||
core.setFailed(error.message)
|
milliseconds: 3.6e+6
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
core.setFailed(error.message)
|
||||||
|
} else {
|
||||||
|
core.setFailed('Unknown error occurred.')
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (core.getInput('serviceAccountJsonPlainText', { required: false})) {
|
if (core.getInput('serviceAccountJsonPlainText', { required: false})) {
|
||||||
// Cleanup our auth file that we created.
|
// Cleanup our auth file that we created.
|
||||||
core.debug('Cleaning up service account json file');
|
core.debug('Cleaning up service account json file');
|
||||||
fs.unlinkSync('./serviceAccountJson.json');
|
await unlink('./serviceAccountJson.json');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run();
|
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.')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serviceAccountJsonRaw) {
|
||||||
|
// If the user has provided the raw plain text, then write to file and set appropriate env variable
|
||||||
|
const serviceAccountFile = "./serviceAccountJson.json";
|
||||||
|
await writeFile(serviceAccountFile, serviceAccountJsonRaw, {
|
||||||
|
encoding: 'utf8'
|
||||||
|
});
|
||||||
|
core.exportVariable("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountFile)
|
||||||
|
} else if (serviceAccountJson) {
|
||||||
|
// If the user has provided the json path, then set appropriate env variable
|
||||||
|
core.exportVariable("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountJson)
|
||||||
|
} else {
|
||||||
|
// If the user provided neither, fail and exit
|
||||||
|
return Promise.reject("You must provide one of 'serviceAccountJsonPlainText' or 'serviceAccountJson' to use this action")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void run();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import {readFileSync} from "fs";
|
|
||||||
import {androidpublisher_v3} from "@googleapis/androidpublisher";
|
import {androidpublisher_v3} from "@googleapis/androidpublisher";
|
||||||
import LocalizedText = androidpublisher_v3.Schema$LocalizedText;
|
import LocalizedText = androidpublisher_v3.Schema$LocalizedText;
|
||||||
|
import { readFile } from 'fs/promises';
|
||||||
|
|
||||||
export async function readLocalizedReleaseNotes(whatsNewDir: string | undefined): Promise<LocalizedText[] | undefined> {
|
export async function readLocalizedReleaseNotes(whatsNewDir: string | undefined): Promise<LocalizedText[] | undefined> {
|
||||||
core.debug(`Executing readLocalizedReleaseNotes`);
|
core.debug(`Executing readLocalizedReleaseNotes`);
|
||||||
@@ -12,16 +12,16 @@ export async function readLocalizedReleaseNotes(whatsNewDir: string | undefined)
|
|||||||
.filter(value => /whatsnew-((.*-.*)|(.*))\b/.test(value));
|
.filter(value => /whatsnew-((.*-.*)|(.*))\b/.test(value));
|
||||||
const pattern = /whatsnew-(?<local>(.*-.*)|(.*))/;
|
const pattern = /whatsnew-(?<local>(.*-.*)|(.*))/;
|
||||||
|
|
||||||
let localizedReleaseNotes: LocalizedText[] = [];
|
const localizedReleaseNotes: LocalizedText[] = [];
|
||||||
|
|
||||||
core.debug(`Found files: ${releaseNotes}`);
|
core.debug(`Found files: ${releaseNotes.toString()}`);
|
||||||
releaseNotes.forEach(value => {
|
for (const value of releaseNotes) {
|
||||||
const matches = value.match(pattern);
|
const matches = value.match(pattern);
|
||||||
core.debug(`Matches for ${value} = ${matches}`);
|
if (matches != null && matches.length == 4) {
|
||||||
if (matches != undefined && matches.length == 4) {
|
core.debug(`Matches for ${value} = ${matches.toString()}`);
|
||||||
const lang = matches[1];
|
const lang = matches[1];
|
||||||
const filePath = path.join(whatsNewDir, value);
|
const filePath = path.join(whatsNewDir, value);
|
||||||
const content = readFileSync(filePath, 'utf-8');
|
const content = await readFile(filePath, 'utf-8');
|
||||||
|
|
||||||
if (content != undefined) {
|
if (content != undefined) {
|
||||||
core.debug(`Found localized 'whatsnew-*-*' for Lang(${lang})`);
|
core.debug(`Found localized 'whatsnew-*-*' for Lang(${lang})`);
|
||||||
@@ -33,7 +33,7 @@ export async function readLocalizedReleaseNotes(whatsNewDir: string | undefined)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return localizedReleaseNotes
|
return localizedReleaseNotes
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user