Merge branch 'master' of https://github.com/boswelja/upload-google-play into master
This commit is contained in:
@@ -18,9 +18,9 @@ The service account json in plain text, provided via a secret, etc.
|
|||||||
|
|
||||||
**Required:** The package name, or Application Id, of the app you are uploading
|
**Required:** The package name, or Application Id, of the app you are uploading
|
||||||
|
|
||||||
### `releaseFile`
|
### `releaseFiles`
|
||||||
|
|
||||||
**Required:** The Android release file to upload (.apk or .aab)
|
**Required:** The Android release file(s) to upload (.apk or .aab). Multiple files are separated by ','.
|
||||||
|
|
||||||
### `track`
|
### `track`
|
||||||
|
|
||||||
|
|||||||
131
lib/edits.js
131
lib/edits.js
@@ -37,65 +37,64 @@ const whatsnew_1 = require("./whatsnew");
|
|||||||
const androidPublisher = googleapis_1.google.androidpublisher('v3');
|
const androidPublisher = googleapis_1.google.androidpublisher('v3');
|
||||||
function uploadToPlayStore(options, releaseFiles) {
|
function uploadToPlayStore(options, releaseFiles) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const appEdit = yield androidPublisher.edits.insert({
|
if (options.track === 'internalappsharing') {
|
||||||
auth: options.auth,
|
core.debug("Track is Internal app sharing, switch to special upload api");
|
||||||
packageName: options.applicationId
|
releaseFiles.forEach((releaseFile) => __awaiter(this, void 0, void 0, function* () {
|
||||||
});
|
core.debug(`Uploading ${releaseFile}`);
|
||||||
releaseFiles.forEach((releaseFile) => __awaiter(this, void 0, void 0, function* () {
|
yield uploadInternalSharingRelease(options, releaseFile).catch(reason => {
|
||||||
core.debug(`Uploading ${releaseFile}`);
|
core.setFailed(reason);
|
||||||
yield uploadRelease(appEdit.data, options, releaseFile).catch(reason => {
|
return Promise.reject(reason);
|
||||||
return Promise.reject(reason);
|
});
|
||||||
});
|
}));
|
||||||
}));
|
|
||||||
const res = yield androidPublisher.edits.commit({
|
|
||||||
auth: options.auth,
|
|
||||||
editId: appEdit.data.id,
|
|
||||||
packageName: options.applicationId
|
|
||||||
});
|
|
||||||
if (res.data.id != null) {
|
|
||||||
core.debug(`Successfully committed ${res.data.id}`);
|
|
||||||
return Promise.resolve(res.data.id);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core.setFailed(`Error ${res.status}: ${res.statusText}`);
|
const appEdit = yield androidPublisher.edits.insert({
|
||||||
return Promise.reject(res.status);
|
auth: options.auth,
|
||||||
|
packageName: options.applicationId
|
||||||
|
});
|
||||||
|
yield validateSelectedTrack(appEdit.data, options).catch(reason => {
|
||||||
|
core.setFailed(reason);
|
||||||
|
return Promise.reject(reason);
|
||||||
|
});
|
||||||
|
// Check the 'track' for 'internalsharing', if so switch to a non-track api
|
||||||
|
var versionCodes = new Array();
|
||||||
|
releaseFiles.forEach((releaseFile) => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.debug(`Uploading ${releaseFile}`);
|
||||||
|
const versionCode = yield uploadRelease(appEdit.data, options, releaseFile).catch(reason => {
|
||||||
|
core.setFailed(reason);
|
||||||
|
return Promise.reject(reason);
|
||||||
|
});
|
||||||
|
versionCodes.push(versionCode);
|
||||||
|
}));
|
||||||
|
const track = addReleasesToTrack(appEdit.data, options, versionCodes);
|
||||||
|
const res = yield androidPublisher.edits.commit({
|
||||||
|
auth: options.auth,
|
||||||
|
editId: appEdit.data.id,
|
||||||
|
packageName: options.applicationId
|
||||||
|
});
|
||||||
|
if (res.data.id != null) {
|
||||||
|
core.debug(`Successfully committed ${res.data.id}`);
|
||||||
|
return Promise.resolve(res.data.id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.setFailed(`Error ${res.status}: ${res.statusText}`);
|
||||||
|
return Promise.reject(res.status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.uploadToPlayStore = uploadToPlayStore;
|
exports.uploadToPlayStore = uploadToPlayStore;
|
||||||
function uploadRelease(appEdit, options, releaseFile) {
|
function uploadInternalSharingRelease(options, releaseFile) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// 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");
|
|
||||||
if (releaseFile.endsWith('.apk')) {
|
|
||||||
const res = yield internalSharingUploadApk(options, releaseFile);
|
|
||||||
return Promise.resolve(res.downloadUrl);
|
|
||||||
}
|
|
||||||
else if (releaseFile.endsWith('.aab')) {
|
|
||||||
const res = yield internalSharingUploadBundle(options, releaseFile);
|
|
||||||
return Promise.resolve(res.downloadUrl);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
core.setFailed(`${releaseFile} is invalid`);
|
|
||||||
return Promise.reject(`${releaseFile} is invalid`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const allTracks = yield getAllTracks(appEdit, options);
|
|
||||||
if (allTracks == undefined || allTracks.find(value => value.track == options.track) == undefined) {
|
|
||||||
core.setFailed(`Track "${options.track}" could not be found `);
|
|
||||||
return Promise.reject(`No track found for "${options.track}"`);
|
|
||||||
}
|
|
||||||
let track = undefined;
|
|
||||||
if (releaseFile.endsWith('.apk')) {
|
if (releaseFile.endsWith('.apk')) {
|
||||||
const apk = yield uploadApk(appEdit, options, releaseFile);
|
const res = yield internalSharingUploadApk(options, releaseFile);
|
||||||
yield uploadMappingFile(appEdit, apk.versionCode, options);
|
console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`);
|
||||||
track = yield trackVersionCode(appEdit, options, apk.versionCode);
|
return Promise.resolve(res.downloadUrl);
|
||||||
}
|
}
|
||||||
else if (releaseFile.endsWith('.aab')) {
|
else if (releaseFile.endsWith('.aab')) {
|
||||||
const bundle = yield uploadBundle(appEdit, options, releaseFile);
|
const res = yield internalSharingUploadBundle(options, releaseFile);
|
||||||
yield uploadMappingFile(appEdit, bundle.versionCode, options);
|
console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`);
|
||||||
track = yield trackVersionCode(appEdit, options, bundle.versionCode);
|
return Promise.resolve(res.downloadUrl);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core.setFailed(`${releaseFile} is invalid`);
|
core.setFailed(`${releaseFile} is invalid`);
|
||||||
@@ -103,17 +102,39 @@ function uploadRelease(appEdit, options, releaseFile) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getAllTracks(appEdit, options) {
|
function uploadRelease(appEdit, options, releaseFile) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (releaseFile.endsWith('.apk')) {
|
||||||
|
const apk = yield uploadApk(appEdit, options, releaseFile);
|
||||||
|
yield uploadMappingFile(appEdit, apk.versionCode, options);
|
||||||
|
return Promise.resolve(apk.versionCode);
|
||||||
|
}
|
||||||
|
else if (releaseFile.endsWith('.aab')) {
|
||||||
|
const bundle = yield uploadBundle(appEdit, options, releaseFile);
|
||||||
|
yield uploadMappingFile(appEdit, bundle.versionCode, options);
|
||||||
|
return Promise.resolve(bundle.versionCode);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.setFailed(`${releaseFile} is invalid`);
|
||||||
|
return Promise.reject(`${releaseFile} is invalid`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function validateSelectedTrack(appEdit, options) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const res = yield androidPublisher.edits.tracks.list({
|
const res = yield androidPublisher.edits.tracks.list({
|
||||||
auth: options.auth,
|
auth: options.auth,
|
||||||
editId: appEdit.id,
|
editId: appEdit.id,
|
||||||
packageName: options.applicationId
|
packageName: options.applicationId
|
||||||
});
|
});
|
||||||
return res.data.tracks;
|
const allTracks = res.data.tracks;
|
||||||
|
if (allTracks == undefined || allTracks.find(value => value.track == options.track) == undefined) {
|
||||||
|
core.setFailed(`Track "${options.track}" could not be found `);
|
||||||
|
return Promise.reject(`No track found for "${options.track}"`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function trackVersionCode(appEdit, options, versionCode) {
|
function addReleasesToTrack(appEdit, options, versionCodes) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let status;
|
let status;
|
||||||
if (options.userFraction != undefined) {
|
if (options.userFraction != undefined) {
|
||||||
@@ -122,7 +143,7 @@ function trackVersionCode(appEdit, options, versionCode) {
|
|||||||
else {
|
else {
|
||||||
status = 'completed';
|
status = 'completed';
|
||||||
}
|
}
|
||||||
core.debug(`Creating Track Release for Edit(${appEdit.id}) for Track(${options.track}) with a UserFraction(${options.userFraction}) and VersionCode(${versionCode})`);
|
core.debug(`Creating Track Release for Edit(${appEdit.id}) for Track(${options.track}) with a UserFraction(${options.userFraction}) and VersionCodes(${versionCodes})`);
|
||||||
const res = yield androidPublisher.edits.tracks
|
const res = yield androidPublisher.edits.tracks
|
||||||
.update({
|
.update({
|
||||||
auth: options.auth,
|
auth: options.auth,
|
||||||
@@ -136,9 +157,7 @@ function trackVersionCode(appEdit, options, versionCode) {
|
|||||||
userFraction: options.userFraction,
|
userFraction: options.userFraction,
|
||||||
status: status,
|
status: status,
|
||||||
releaseNotes: yield whatsnew_1.readLocalizedReleaseNotes(options.whatsNewDir),
|
releaseNotes: yield whatsnew_1.readLocalizedReleaseNotes(options.whatsNewDir),
|
||||||
versionCodes: [
|
versionCodes: versionCodes.map(x => x.toString())
|
||||||
versionCode.toString()
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
141
src/edits.ts
141
src/edits.ts
@@ -28,89 +28,106 @@ export interface EditOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function uploadToPlayStore(options: EditOptions, releaseFiles: string[]): Promise<string | undefined> {
|
export async function uploadToPlayStore(options: EditOptions, releaseFiles: string[]): Promise<string | undefined> {
|
||||||
const appEdit = await androidPublisher.edits.insert({
|
if (options.track === 'internalappsharing') {
|
||||||
auth: options.auth,
|
core.debug("Track is Internal app sharing, switch to special upload api")
|
||||||
packageName: options.applicationId
|
releaseFiles.forEach(async releaseFile => {
|
||||||
});
|
core.debug(`Uploading ${releaseFile}`);
|
||||||
|
await uploadInternalSharingRelease(options, releaseFile).catch(reason => {
|
||||||
releaseFiles.forEach(async releaseFile => {
|
core.setFailed(reason);
|
||||||
core.debug(`Uploading ${releaseFile}`)
|
return Promise.reject(reason);
|
||||||
await uploadRelease(appEdit.data, options, releaseFile).catch(reason => {
|
});
|
||||||
return Promise.reject(reason)
|
});
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
const res = await androidPublisher.edits.commit({
|
|
||||||
auth: options.auth,
|
|
||||||
editId: appEdit.data.id!,
|
|
||||||
packageName: options.applicationId
|
|
||||||
});
|
|
||||||
|
|
||||||
if (res.data.id != null) {
|
|
||||||
core.debug(`Successfully committed ${res.data.id}`)
|
|
||||||
return Promise.resolve(res.data.id!)
|
|
||||||
} else {
|
} else {
|
||||||
core.setFailed(`Error ${res.status}: ${res.statusText}`)
|
const appEdit = await androidPublisher.edits.insert({
|
||||||
return Promise.reject(res.status)
|
auth: options.auth,
|
||||||
|
packageName: options.applicationId
|
||||||
|
});
|
||||||
|
|
||||||
|
await validateSelectedTrack(appEdit.data, options).catch(reason => {
|
||||||
|
core.setFailed(reason);
|
||||||
|
return Promise.reject(reason);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check the 'track' for 'internalsharing', if so switch to a non-track api
|
||||||
|
var versionCodes = new Array<number>();
|
||||||
|
releaseFiles.forEach(async releaseFile => {
|
||||||
|
core.debug(`Uploading ${releaseFile}`);
|
||||||
|
const versionCode = await uploadRelease(appEdit.data, options, releaseFile).catch(reason => {
|
||||||
|
core.setFailed(reason);
|
||||||
|
return Promise.reject(reason);
|
||||||
|
});
|
||||||
|
versionCodes.push(versionCode!);
|
||||||
|
});
|
||||||
|
|
||||||
|
const track = addReleasesToTrack(appEdit.data, options, versionCodes);
|
||||||
|
const res = await androidPublisher.edits.commit({
|
||||||
|
auth: options.auth,
|
||||||
|
editId: appEdit.data.id!,
|
||||||
|
packageName: options.applicationId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.data.id != null) {
|
||||||
|
core.debug(`Successfully committed ${res.data.id}`);
|
||||||
|
return Promise.resolve(res.data.id!);
|
||||||
|
} else {
|
||||||
|
core.setFailed(`Error ${res.status}: ${res.statusText}`);
|
||||||
|
return Promise.reject(res.status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadRelease(appEdit: AppEdit, options: EditOptions, releaseFile: string): Promise<string | undefined | null> {
|
async function uploadInternalSharingRelease(options: EditOptions, releaseFile: string): Promise<string | undefined | null> {
|
||||||
// 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")
|
|
||||||
if (releaseFile.endsWith('.apk')) {
|
|
||||||
const res = await internalSharingUploadApk(options, releaseFile)
|
|
||||||
return Promise.resolve(res.downloadUrl)
|
|
||||||
} else if (releaseFile.endsWith('.aab')) {
|
|
||||||
const res = await internalSharingUploadBundle(options, releaseFile)
|
|
||||||
return Promise.resolve(res.downloadUrl)
|
|
||||||
} else {
|
|
||||||
core.setFailed(`${releaseFile} is invalid`)
|
|
||||||
return Promise.reject(`${releaseFile} is invalid`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const allTracks = await getAllTracks(appEdit!, options);
|
|
||||||
if (allTracks == undefined || allTracks.find(value => value.track == options.track) == undefined) {
|
|
||||||
core.setFailed(`Track "${options.track}" could not be found `)
|
|
||||||
return Promise.reject(`No track found for "${options.track}"`)
|
|
||||||
}
|
|
||||||
|
|
||||||
let track: Track | undefined = undefined;
|
|
||||||
if (releaseFile.endsWith('.apk')) {
|
if (releaseFile.endsWith('.apk')) {
|
||||||
const apk = await uploadApk(appEdit, options, releaseFile);
|
const res = await internalSharingUploadApk(options, releaseFile)
|
||||||
await uploadMappingFile(appEdit, apk.versionCode!, options);
|
console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`)
|
||||||
track = await trackVersionCode(appEdit, options, apk.versionCode!)
|
return Promise.resolve(res.downloadUrl)
|
||||||
} else if (releaseFile.endsWith('.aab')) {
|
} else if (releaseFile.endsWith('.aab')) {
|
||||||
const bundle = await uploadBundle(appEdit, options, releaseFile);
|
const res = await internalSharingUploadBundle(options, releaseFile)
|
||||||
await uploadMappingFile(appEdit, bundle.versionCode!, options);
|
console.log(`${releaseFile} uploaded to Internal Sharing, download it with ${res.downloadUrl}`)
|
||||||
track = await trackVersionCode(appEdit, options, bundle.versionCode!)
|
return Promise.resolve(res.downloadUrl)
|
||||||
} else {
|
} else {
|
||||||
core.setFailed(`${releaseFile} is invalid`)
|
core.setFailed(`${releaseFile} is invalid`)
|
||||||
return Promise.reject(`${releaseFile} is invalid`)
|
return Promise.reject(`${releaseFile} is invalid`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAllTracks(appEdit: AppEdit, options: EditOptions): Promise<Track[] | undefined> {
|
async function uploadRelease(appEdit: AppEdit, options: EditOptions, releaseFile: string): Promise<number | undefined | null> {
|
||||||
|
if (releaseFile.endsWith('.apk')) {
|
||||||
|
const apk = await uploadApk(appEdit, options, releaseFile);
|
||||||
|
await uploadMappingFile(appEdit, apk.versionCode!, options);
|
||||||
|
return Promise.resolve(apk.versionCode);
|
||||||
|
} else if (releaseFile.endsWith('.aab')) {
|
||||||
|
const bundle = await uploadBundle(appEdit, options, releaseFile);
|
||||||
|
await uploadMappingFile(appEdit, bundle.versionCode!, options);
|
||||||
|
return Promise.resolve(bundle.versionCode);
|
||||||
|
} else {
|
||||||
|
core.setFailed(`${releaseFile} is invalid`);
|
||||||
|
return Promise.reject(`${releaseFile} is invalid`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function validateSelectedTrack(appEdit: AppEdit, 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: appEdit.id!,
|
editId: appEdit.id!,
|
||||||
packageName: options.applicationId
|
packageName: options.applicationId
|
||||||
});
|
});
|
||||||
|
const allTracks = res.data.tracks;
|
||||||
return res.data.tracks
|
if (allTracks == undefined || allTracks.find(value => value.track == options.track) == undefined) {
|
||||||
|
core.setFailed(`Track "${options.track}" could not be found `);
|
||||||
|
return Promise.reject(`No track found for "${options.track}"`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function trackVersionCode(appEdit: AppEdit, options: EditOptions, versionCode: number): Promise<Track> {
|
async function addReleasesToTrack(appEdit: AppEdit, options: EditOptions, versionCodes: number[]): Promise<Track> {
|
||||||
let status: string;
|
let status: string;
|
||||||
if (options.userFraction != undefined) {
|
if (options.userFraction != undefined) {
|
||||||
status = 'inProgress'
|
status = 'inProgress';
|
||||||
} else {
|
} else {
|
||||||
status = 'completed'
|
status = 'completed';
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(`Creating Track Release for Edit(${appEdit.id}) for Track(${options.track}) with a UserFraction(${options.userFraction}) and VersionCode(${versionCode})`);
|
core.debug(`Creating Track Release for Edit(${appEdit.id}) for Track(${options.track}) with a UserFraction(${options.userFraction}) and VersionCodes(${versionCodes})`);
|
||||||
const res = await androidPublisher.edits.tracks
|
const res = await androidPublisher.edits.tracks
|
||||||
.update({
|
.update({
|
||||||
auth: options.auth,
|
auth: options.auth,
|
||||||
@@ -124,15 +141,13 @@ async function trackVersionCode(appEdit: AppEdit, options: EditOptions, versionC
|
|||||||
userFraction: options.userFraction,
|
userFraction: options.userFraction,
|
||||||
status: status,
|
status: status,
|
||||||
releaseNotes: await readLocalizedReleaseNotes(options.whatsNewDir),
|
releaseNotes: await readLocalizedReleaseNotes(options.whatsNewDir),
|
||||||
versionCodes: [
|
versionCodes: versionCodes.map(x => x.toString())
|
||||||
versionCode.toString()
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.data
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadMappingFile(appEdit: AppEdit, versionCode: number, options: EditOptions) {
|
async function uploadMappingFile(appEdit: AppEdit, versionCode: number, options: EditOptions) {
|
||||||
|
|||||||
Reference in New Issue
Block a user