Move track validation to a separate function

This commit is contained in:
Jack Boswell (boswelja)
2020-10-23 16:12:01 +13:00
parent 87accbcd41
commit fc19501036
2 changed files with 35 additions and 30 deletions

View File

@@ -41,6 +41,10 @@ function uploadToPlayStore(options, releaseFiles) {
auth: options.auth,
packageName: options.applicationId
});
yield validateSelectedTrack(appEdit.data, options).catch(reason => {
core.setFailed(reason);
return Promise.reject(reason);
});
var versionCodes = new Array();
releaseFiles.forEach((releaseFile) => __awaiter(this, void 0, void 0, function* () {
core.debug(`Uploading ${releaseFile}`);
@@ -87,11 +91,6 @@ function uploadRelease(appEdit, options, releaseFile) {
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}"`);
}
if (releaseFile.endsWith('.apk')) {
const apk = yield uploadApk(appEdit, options, releaseFile);
yield uploadMappingFile(appEdit, apk.versionCode, options);
@@ -108,14 +107,18 @@ function uploadRelease(appEdit, options, releaseFile) {
}
});
}
function getAllTracks(appEdit, options) {
function validateSelectedTrack(appEdit, options) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield androidPublisher.edits.tracks.list({
auth: options.auth,
editId: appEdit.id,
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, versionCodes) {