-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Do actual build uploads
Showing
6 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "module", | ||
"dependencies": { | ||
"jsonwebtoken": "^9.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @ts-check | ||
|
||
export function parseArgs() { | ||
const args = process.argv.slice(2); | ||
const mode = args.shift(); | ||
if (!mode) throw new Error('Missing arguments'); | ||
|
||
if (mode === 'upload') { | ||
if (args.length < 2) throw new Error('Missing arguments'); | ||
const [apiKey, bundlePath] = args; | ||
return { | ||
/** @type {'upload'} */ | ||
mode: 'upload', | ||
apiKey: JSON.parse(Buffer.from(apiKey, 'base64').toString()), | ||
bundlePath | ||
}; | ||
} else { | ||
throw new Error('Invalid mode') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @ts-check | ||
import { parseArgs } from "./cli.js"; | ||
import { PlayStoreApi } from "./play-store-api.js"; | ||
|
||
const PACKAGE_NAME = 'org.eternagame.mob'; | ||
|
||
const args = parseArgs(); | ||
const playStoreApi = await PlayStoreApi.create(args.apiKey); | ||
if (args.mode === 'upload') { | ||
const editId = await playStoreApi.insertEdit(PACKAGE_NAME); | ||
await playStoreApi.uploadBundle(PACKAGE_NAME, editId, args.bundlePath); | ||
await playStoreApi.commitEdit(PACKAGE_NAME, editId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// @ts-check | ||
import { readFile } from 'fs/promises'; | ||
import jwt from 'jsonwebtoken'; | ||
|
||
export class PlayStoreApi { | ||
/** | ||
* @param {string} accessToken | ||
* @access private | ||
*/ | ||
constructor(accessToken) { | ||
this.accessToken = accessToken; | ||
} | ||
|
||
/** | ||
* @param {{ | ||
* type: string; | ||
* project_id: string; | ||
* private_key_id: string; | ||
* private_key: string; | ||
* client_email: string; | ||
* client_id: string; | ||
* auth_uri: string; | ||
* token_uri: string; | ||
* auth_provider_x509_cert_url: string; | ||
* client_x509_cert_url: string; | ||
* universe_domain: string; | ||
* }} apiKey | ||
*/ | ||
static async create(apiKey) { | ||
const authToken = jwt.sign({ | ||
scope: 'https://www.googleapis.com/auth/androidpublisher' | ||
}, apiKey['private_key'], { | ||
algorithm: 'RS256', | ||
keyid: apiKey['private_key_id'], | ||
issuer: apiKey['client_email'], | ||
audience: apiKey['token_uri'], | ||
expiresIn: '5m', | ||
}); | ||
const res = await fetch(apiKey['token_uri'], { | ||
method: 'POST', | ||
body: new URLSearchParams({ | ||
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer', | ||
assertion: authToken | ||
}).toString() | ||
}); | ||
const parsed = await res.json(); | ||
return new PlayStoreApi(parsed['access_token']); | ||
} | ||
|
||
/** | ||
* @param {string} packageName | ||
* @returns {Promise<string>} edit ID | ||
*/ | ||
async insertEdit(packageName) { | ||
const res = await fetch(`https://androidpublisher.googleapis.com/androidpublisher/v3/applications/${packageName}/edits`, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}` | ||
} | ||
}); | ||
const parsed = await res.json(); | ||
return parsed['id']; | ||
} | ||
|
||
/** | ||
* @param {string} packageName | ||
* @param {string} editId | ||
* @param {string} bundlePath | ||
*/ | ||
async uploadBundle(packageName, editId, bundlePath) { | ||
const bundle = await readFile(bundlePath); | ||
await fetch(`https://androidpublisher.googleapis.com/upload/androidpublisher/v3/applications/${packageName}/edits/${editId}/bundles?uploadType=media`, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}`, | ||
'Content-Type': 'application/octet-stream', | ||
'Content-Length': bundle.length.toString(), | ||
}, | ||
body: bundle | ||
}); | ||
} | ||
|
||
async commitEdit(packageName, editId) { | ||
await fetch(`https://androidpublisher.googleapis.com/androidpublisher/v3/applications/${packageName}/edits/${editId}:commit`, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}`, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters