Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OBBs on multiple APKs #38

Merged
merged 7 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "none"
}
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,21 @@ Then use the CLI:
```bash
apkup \
--key api.json \
--apk /path/to/Package.apk \
--deobfuscation /path/to/mapping.txt \ # optional
--release-notes "en-US=lorem ipsum dolor" \
--obbs /path/to/Expansion.obb \ # optional
--obbs /path/to/Expansion2.obb # optional
--file /path/to/Package-arm64.apk
--file /path/to/Package-armv7.apk
--release-notes "en-US=lorem ipsum dolor"
```

You can also specify each parameter via environment variables prefixed with `APKUP_` (e.g. `APKUP_KEY` or `APKUP_APK`).
You can also specify each parameter via environment variables prefixed with `APKUP_` (e.g. `APKUP_KEY` or `APKUP_FILE`).

If you want to specify additional expansion files or deobfuscation mappings, you can add them in a comma separated list after the APK/AAB file like so. The APK/AAB must always be the first file in the list.

```bash
apkup \
--key api.json \
--file /path/to/Package.apk,/path/to/mapping.txt,/path/to/Expansion.obb,/path/to/Expansion2.obb
--release-notes "en-US=lorem ipsum dolor"
```

### Library

Expand All @@ -78,10 +85,15 @@ const apkup = new Apkup({
});

apkup
.upload('/path/to/apk', {
obbs: [
.upload({
files: [
file: '/path/to/Package.apk',
// optional expansion files (max 2)
'/path/to/somefile.obb'
obbs: [
'/path/to/Expansion.obb'
],
// optional mappings file
mappings: '/path/to/mapping.txt'
],
releaseNotes: [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"prepublishOnly": "npm run build && npm prune",
"build": "tsc",
"docs": "typedoc --mode file --excludeExternals --excludeNotExported --exclude 'src/cli.ts' --out docs src",
"docs": "typedoc --mode file --excludeExternals --excludeNotExported --exclude 'src/cli/*.ts' --out docs src",
"test": "tslint -c tslint.json 'src/**/*.ts'",
"test:audit": "npm audit --json | npm-audit-html --output reports/audit.html && npm audit",
"semantic-release": "semantic-release"
Expand Down
3 changes: 3 additions & 0 deletions src/Edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Debug from 'debug'
import { JWT } from 'google-auth-library'
import { androidpublisher_v3, google } from 'googleapis'

/**
* @ignore
*/
const debug = Debug('apkup:Edit')

export interface IEditParams {
Expand Down
11 changes: 5 additions & 6 deletions src/actions/Promote.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import assert from 'assert'
import Debug from 'debug'
import { JWT } from 'google-auth-library'
import { androidpublisher_v3 } from 'googleapis'
import { checkTrack } from './../helpers'

import { Edit, IEditParams, IEditResponse } from './../Edit'
import { Edit, IEditParams } from './../Edit'

/**
* @ignore
*/
const debug = Debug('apkup:Promote')

export interface IPromoteParams {
/** Specify track for this release. Can be one of the [[tracks]]. */
/** Specify a new track for this release. */
track: string
}

Expand All @@ -28,8 +29,6 @@ export class Promote extends Edit {

if (promoteParams.track) {
promoteParams.track = promoteParams.track.toLowerCase()

assert(checkTrack(promoteParams.track), 'Unknown track')
}

this.promoteParams = promoteParams
Expand Down
112 changes: 55 additions & 57 deletions src/actions/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ import { createReadStream } from 'fs'
import { JWT } from 'google-auth-library'
import { extname } from 'path'
import { Edit, IEditParams } from '../Edit'
import { checkTrack } from '../helpers'

/**
* @ignore
*/
const debug = Debug('apkup:Upload')

export interface IUploadFile {
/** The APK or AAB file to upload. */
file: string
/** A path to the deobfuscation mappings file for this APK/AAB. */
mappings?: string
/** An array that specifies the paths to the expansion files (OBBs) for this APK/AAB. */
obbs?: string[]
}

export interface IUploadParams {
// tslint:disable-next-line: max-line-length
/** Specify track for this release. Can be one of the [[tracks]]. Default: `internal` */
/** An array of objects that specify the files to upload for this release. */
files: IUploadFile[]
/** Specify track for this release. Default: `internal` */
track?: string
/** An array of objects that specifies changes in this version. Each object has a `language` and `text`. */
releaseNotes?: IReleaseNotes[]
/** An array that specifies the paths to the expansion files (OBBs) for this release. */
obbs?: string[]
/** A paths to the deobfuscation file for this release. */
deobfuscation?: string
}

export interface IReleaseNotes {
Expand All @@ -32,125 +40,115 @@ export interface IReleaseNotes {
*/
export class Upload extends Edit {
private uploadParams: IUploadParams
private apk: string[]

private versionCodes: any[] = []

constructor (
client: JWT,
apk: string | string[],
uploadParams: IUploadParams = {},
uploadParams: IUploadParams,
nprail marked this conversation as resolved.
Show resolved Hide resolved
editParams: IEditParams
) {
super(client, editParams)

assert(apk, 'I require an APK file')
if (uploadParams.track) {
uploadParams.track = uploadParams.track.toLowerCase()

assert(checkTrack(uploadParams.track), 'Unknown track')
}

this.apk = typeof apk === 'string' ? [apk] : apk
assert(uploadParams?.files[0]?.file, 'At least one file is required')

this.uploadParams = uploadParams
this.uploadParams.track = uploadParams.track || 'internal'
this.uploadParams.obbs = uploadParams.obbs || []
this.uploadParams.track = uploadParams?.track?.toLowerCase() || 'internal'
this.uploadParams.releaseNotes = uploadParams.releaseNotes || []
this.uploadParams.deobfuscation = uploadParams.deobfuscation
}

public async makeEdits () {
await this.uploadFiles()
await this.uploadOBBs()
await this.assignTrack()
await this.uploadDeobfuscation()
}

private async uploadFiles () {
debug('> Uploading release')
const uploads = this.apk.map(async (file) => {
const uploads = this.uploadParams.files.map(async (fileObject) => {
let uploadJob: any

const ext = extname(file)
const ext = extname(fileObject.file)
if (ext === '.apk') {
uploadJob = await this.publisher.edits.apks.upload({
editId: this.editId,
media: {
body: createReadStream(file),
body: createReadStream(fileObject.file),
mimeType: 'application/octet-stream'
},
packageName: this.editParams.packageName
})

debug(
`> Uploaded ${file} with version code ${
`> Uploaded ${fileObject.file} with version code ${
uploadJob.data.versionCode
} and SHA1 ${uploadJob.data.binary && uploadJob.data.binary.sha1}`
)
} else if (ext === '.aab') {
uploadJob = await this.publisher.edits.bundles.upload({
editId: this.editId,
media: {
body: createReadStream(file),
body: createReadStream(fileObject.file),
mimeType: 'application/octet-stream'
},
packageName: this.editParams.packageName
})

debug(
`> Uploaded ${file} with version code ${uploadJob.data.versionCode} and SHA1 ${uploadJob.data.sha1}`
`> Uploaded ${fileObject.file} with version code ${uploadJob.data.versionCode} and SHA1 ${uploadJob.data.sha1}`
)
}

this.versionCodes.push(uploadJob.data.versionCode)
const versionCode: number = uploadJob.data.versionCode
this.versionCodes.push(versionCode)

if (fileObject.obbs) {
await this.uploadOBBs(fileObject.obbs, versionCode)
}

if (fileObject.mappings) {
await this.uploadMappings(fileObject.mappings, versionCode)
}

return uploadJob
})
return Promise.all(uploads)
}

private async uploadDeobfuscation () {
debug('> Uploading deobfuscation')
if (this.uploadParams.deobfuscation) {
return this.publisher.edits.deobfuscationfiles.upload(
{
apkVersionCode: this.editParams.versionCode,
deobfuscationFileType: 'proguard',
editId: this.editId,
media: {
body: createReadStream(this.uploadParams.deobfuscation),
mimeType: 'application/octet-stream'
},
packageName: this.editParams.packageName
private async uploadMappings (mappings: string, versionCode: number) {
debug(`> Uploading mappings ${mappings} for ${versionCode}`)
return this.publisher.edits.deobfuscationfiles.upload(
{
apkVersionCode: versionCode,
deobfuscationFileType: 'proguard',
editId: this.editId,
media: {
body: createReadStream(mappings),
mimeType: 'application/octet-stream'
},
{}
)
}
packageName: this.editParams.packageName
},
{}
)
}

private async uploadOBBs () {
if (
!this.uploadParams.obbs ||
!Array.isArray(this.uploadParams.obbs) ||
!this.uploadParams.obbs.length
) {
private async uploadOBBs (obbs: string[], versionCode: number) {
if (!obbs || !Array.isArray(obbs) || !obbs.length) {
return
}

debug(`> Uploading ${this.uploadParams.obbs.length} expansion file(s)`)
debug(`> Uploading ${obbs.length} expansion file(s) for ${versionCode}`)

return Promise.all(
this.uploadParams.obbs.map(async (obb) => this.uploadOBB(obb))
obbs.map(async (obb) => this.uploadOBB(obb, versionCode))
)
}

private async uploadOBB (obb: string) {
debug(`> Uploading expansion file ${obb}`)
private async uploadOBB (obb: string, versionCode: number) {
debug(`> Uploading expansion file ${obb} for ${versionCode}`)

return this.publisher.edits.expansionfiles.upload(
{
apkVersionCode: this.editParams.versionCode,
apkVersionCode: versionCode,
editId: this.editId,
expansionFileType: 'main',
media: {
Expand Down
7 changes: 4 additions & 3 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ const argv = yargs
config: true,
demandOption: true
})
.option('apk', {
alias: 'a',
describe: 'Path to the APK file',
.option('file', {
alias: 'f',
describe:
'Paths to an APK or AAB. OBBs and a deobfuscation mappings file for the package can be included by adding a comma separated list after the main file.',
type: 'array'
})
.config(
Expand Down
Loading