Rewrite a portion of edits.ts
uploadRelease now specifically only uploads to an edit. uploadToPlayStore is designed to handle multiple inputs, and commit them at the right time. Error catching should be improved now.
This commit is contained in:
97
lib/edits.js
97
lib/edits.js
@@ -28,66 +28,81 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.uploadRelease = void 0;
|
exports.uploadToPlayStore = void 0;
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
const fs_1 = require("fs");
|
const fs_1 = require("fs");
|
||||||
const googleapis_1 = require("googleapis");
|
const googleapis_1 = require("googleapis");
|
||||||
const whatsnew_1 = require("./whatsnew");
|
const whatsnew_1 = require("./whatsnew");
|
||||||
const androidPublisher = googleapis_1.google.androidpublisher('v3');
|
const androidPublisher = googleapis_1.google.androidpublisher('v3');
|
||||||
function uploadRelease(options, releaseFiles) {
|
function uploadToPlayStore(options, releaseFiles) {
|
||||||
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");
|
|
||||||
releaseFiles.forEach((releaseFile) => __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// 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 {
|
|
||||||
// return Promise.reject(`Unrecognized Release File`)
|
|
||||||
// }
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
const appEdit = yield androidPublisher.edits.insert({
|
const appEdit = yield androidPublisher.edits.insert({
|
||||||
auth: options.auth,
|
auth: options.auth,
|
||||||
packageName: options.applicationId
|
packageName: options.applicationId
|
||||||
});
|
});
|
||||||
const allTracks = yield getAllTracks(appEdit.data, options);
|
releaseFiles.forEach((releaseFile) => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.debug(`Uploading ${releaseFile}`);
|
||||||
|
yield uploadRelease(appEdit.data, options, releaseFile).catch(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 {
|
||||||
|
core.setFailed(`Error ${res.status}: ${res.statusText}`);
|
||||||
|
return Promise.reject(res.status);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.uploadToPlayStore = uploadToPlayStore;
|
||||||
|
function uploadRelease(appEdit, options, releaseFile) {
|
||||||
|
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) {
|
if (allTracks == undefined || allTracks.find(value => value.track == options.track) == undefined) {
|
||||||
core.setFailed(`Track "${options.track}" could not be found `);
|
core.setFailed(`Track "${options.track}" could not be found `);
|
||||||
return Promise.reject(`No track found for "${options.track}"`);
|
return Promise.reject(`No track found for "${options.track}"`);
|
||||||
}
|
}
|
||||||
let track = undefined;
|
let track = undefined;
|
||||||
releaseFiles.forEach((releaseFile) => __awaiter(this, void 0, void 0, function* () {
|
if (releaseFile.endsWith('.apk')) {
|
||||||
if (releaseFile.endsWith('.apk')) {
|
const apk = yield uploadApk(appEdit, options, releaseFile);
|
||||||
const apk = yield uploadApk(appEdit.data, options, releaseFile);
|
yield uploadMappingFile(appEdit, apk.versionCode, options);
|
||||||
yield uploadMappingFile(appEdit.data, apk.versionCode, options);
|
track = yield trackVersionCode(appEdit, options, apk.versionCode);
|
||||||
track = yield trackVersionCode(appEdit.data, options, apk.versionCode);
|
}
|
||||||
}
|
else if (releaseFile.endsWith('.aab')) {
|
||||||
else if (releaseFile.endsWith('.aab')) {
|
const bundle = yield uploadBundle(appEdit, options, releaseFile);
|
||||||
const bundle = yield uploadBundle(appEdit.data, options, releaseFile);
|
yield uploadMappingFile(appEdit, bundle.versionCode, options);
|
||||||
yield uploadMappingFile(appEdit.data, bundle.versionCode, options);
|
track = yield trackVersionCode(appEdit, options, bundle.versionCode);
|
||||||
track = yield trackVersionCode(appEdit.data, options, bundle.versionCode);
|
}
|
||||||
}
|
else {
|
||||||
else {
|
core.setFailed(`${releaseFile} is invalid`);
|
||||||
return Promise.reject("Invalid release file");
|
return Promise.reject(`${releaseFile} is invalid`);
|
||||||
}
|
|
||||||
}));
|
|
||||||
if (track != undefined) {
|
|
||||||
const res = yield androidPublisher.edits.commit({
|
|
||||||
auth: options.auth,
|
|
||||||
editId: appEdit.data.id,
|
|
||||||
packageName: options.applicationId
|
|
||||||
});
|
|
||||||
core.debug(`Committed release with Id(${res.data.id}) and Track: ${track}`);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.uploadRelease = uploadRelease;
|
|
||||||
function getAllTracks(appEdit, options) {
|
function getAllTracks(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({
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ function run() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const authClient = yield auth.getClient();
|
const authClient = yield auth.getClient();
|
||||||
const downloadUrl = yield edits_1.uploadRelease({
|
const downloadUrl = yield edits_1.uploadToPlayStore({
|
||||||
auth: authClient,
|
auth: authClient,
|
||||||
applicationId: packageName,
|
applicationId: packageName,
|
||||||
track: track,
|
track: track,
|
||||||
|
|||||||
91
src/edits.ts
91
src/edits.ts
@@ -27,57 +27,68 @@ export interface EditOptions {
|
|||||||
mappingFile?: string;
|
mappingFile?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function uploadRelease(options: EditOptions, releaseFiles: string[]): Promise<string | undefined | null> {
|
export async function uploadToPlayStore(options: EditOptions, releaseFiles: string[]): Promise<string | undefined> {
|
||||||
// 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")
|
|
||||||
releaseFiles.forEach(async releaseFile => {
|
|
||||||
// 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 {
|
|
||||||
// return Promise.reject(`Unrecognized Release File`)
|
|
||||||
// }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const appEdit = await androidPublisher.edits.insert({
|
const appEdit = await androidPublisher.edits.insert({
|
||||||
auth: options.auth,
|
auth: options.auth,
|
||||||
packageName: options.applicationId
|
packageName: options.applicationId
|
||||||
});
|
});
|
||||||
|
|
||||||
|
releaseFiles.forEach(async releaseFile => {
|
||||||
|
core.debug(`Uploading ${releaseFile}`)
|
||||||
|
await uploadRelease(appEdit.data, options, releaseFile).catch(reason => {
|
||||||
|
return Promise.reject(reason)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const allTracks = await getAllTracks(appEdit.data!, options);
|
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> {
|
||||||
|
// 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) {
|
if (allTracks == undefined || allTracks.find(value => value.track == options.track) == undefined) {
|
||||||
core.setFailed(`Track "${options.track}" could not be found `)
|
core.setFailed(`Track "${options.track}" could not be found `)
|
||||||
return Promise.reject(`No track found for "${options.track}"`)
|
return Promise.reject(`No track found for "${options.track}"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
let track: Track | undefined = undefined;
|
let track: Track | undefined = undefined;
|
||||||
releaseFiles.forEach(async releaseFile => {
|
if (releaseFile.endsWith('.apk')) {
|
||||||
if (releaseFile.endsWith('.apk')) {
|
const apk = await uploadApk(appEdit, options, releaseFile);
|
||||||
const apk = await uploadApk(appEdit.data, options, releaseFile);
|
await uploadMappingFile(appEdit, apk.versionCode!, options);
|
||||||
await uploadMappingFile(appEdit.data, apk.versionCode!, options);
|
track = await trackVersionCode(appEdit, options, apk.versionCode!)
|
||||||
track = await trackVersionCode(appEdit.data, options, apk.versionCode!)
|
} else if (releaseFile.endsWith('.aab')) {
|
||||||
} else if (releaseFile.endsWith('.aab')) {
|
const bundle = await uploadBundle(appEdit, options, releaseFile);
|
||||||
const bundle = await uploadBundle(appEdit.data, options, releaseFile);
|
await uploadMappingFile(appEdit, bundle.versionCode!, options);
|
||||||
await uploadMappingFile(appEdit.data, bundle.versionCode!, options);
|
track = await trackVersionCode(appEdit, options, bundle.versionCode!)
|
||||||
track = await trackVersionCode(appEdit.data, options, bundle.versionCode!)
|
} else {
|
||||||
} else {
|
core.setFailed(`${releaseFile} is invalid`)
|
||||||
return Promise.reject("Invalid release file")
|
return Promise.reject(`${releaseFile} is invalid`)
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (track != undefined) {
|
|
||||||
const res = await androidPublisher.edits.commit({
|
|
||||||
auth: options.auth,
|
|
||||||
editId: appEdit.data.id!,
|
|
||||||
packageName: options.applicationId
|
|
||||||
});
|
|
||||||
|
|
||||||
core.debug(`Committed release with Id(${res.data.id}) and Track: ${track}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import {uploadRelease} from "./edits";
|
import { uploadToPlayStore } from "./edits";
|
||||||
const {google} = require('googleapis');
|
const {google} = require('googleapis');
|
||||||
|
|
||||||
const auth = new google.auth.GoogleAuth({
|
const auth = new google.auth.GoogleAuth({
|
||||||
@@ -71,7 +71,7 @@ async function run() {
|
|||||||
|
|
||||||
const authClient = await auth.getClient();
|
const authClient = await auth.getClient();
|
||||||
|
|
||||||
const downloadUrl = await uploadRelease({
|
const downloadUrl = await uploadToPlayStore({
|
||||||
auth: authClient,
|
auth: authClient,
|
||||||
applicationId: packageName,
|
applicationId: packageName,
|
||||||
track: track,
|
track: track,
|
||||||
|
|||||||
Reference in New Issue
Block a user