Finished action

Adding the monolith node_modules dir for deployment
This commit is contained in:
Drew Heavner
2019-12-04 09:58:34 -05:00
parent d665ce5758
commit a29f8cd536
8629 changed files with 2587149 additions and 190 deletions

161
lib/edits.js Normal file
View File

@@ -0,0 +1,161 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const fs = __importStar(require("fs"));
const fs_1 = require("fs");
const googleapis_1 = require("googleapis");
const androidPublisher = googleapis_1.google.androidpublisher('v3');
function uploadRelease(options, releaseFile) {
return __awaiter(this, void 0, void 0, function* () {
const appEdit = yield androidPublisher.edits.insert({
auth: options.auth,
packageName: options.applicationId
});
let track = undefined;
if (releaseFile.endsWith('.apk')) {
const apk = yield uploadApk(appEdit.data, options, releaseFile);
yield uploadMappingFile(appEdit.data, apk.versionCode, options);
track = yield trackVersionCode(appEdit.data, options, apk.versionCode);
}
else if (releaseFile.endsWith('.aab')) {
const bundle = yield uploadBundle(appEdit.data, options, releaseFile);
yield uploadMappingFile(appEdit.data, bundle.versionCode, options);
track = yield trackVersionCode(appEdit.data, options, bundle.versionCode);
}
else {
return Promise.reject("Invalid release file");
}
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 trackVersionCode(appEdit, options, versionCode) {
return __awaiter(this, void 0, void 0, function* () {
let status;
if (options.userFraction != undefined) {
status = 'inProgress';
}
else {
status = 'completed';
}
core.debug(`Creating Track Release for Edit(${appEdit.id}) for Track(${options.track}) with a UserFraction(${options.userFraction}) and VersionCode(${versionCode})`);
const res = yield androidPublisher.edits.tracks
.update({
auth: options.auth,
editId: appEdit.id,
packageName: options.applicationId,
track: options.track,
requestBody: {
releases: [
{
userFraction: options.userFraction,
status: status,
releaseNotes: yield readLocalizedReleaseNotes(options.whatsNewDir),
versionCodes: [
versionCode.toString()
]
}
]
}
});
return res.data;
});
}
function readLocalizedReleaseNotes(whatsNewDir) {
return __awaiter(this, void 0, void 0, function* () {
if (whatsNewDir != undefined) {
const releaseNotes = fs.readdirSync(whatsNewDir).filter(value => /whatsnew-*-*/.test(value));
const pattern = /whatsnew-(?<local>.*-.*)/.compile();
let localizedReleaseNotes = [];
releaseNotes.forEach(value => {
const matches = value.match(pattern);
if (matches != undefined && matches.length == 2) {
const lang = matches[1];
const content = fs_1.readFileSync(value, 'utf-8');
if (content != undefined) {
core.debug(`Found localized 'whatsnew-*-*' for Lang(${lang})`);
localizedReleaseNotes.push({
language: lang,
text: content
});
}
}
});
return localizedReleaseNotes;
}
return undefined;
});
}
function uploadMappingFile(appEdit, versionCode, options) {
return __awaiter(this, void 0, void 0, function* () {
if (options.mappingFile != undefined) {
const mapping = fs_1.readFileSync(options.mappingFile, 'utf-8');
if (mapping != undefined) {
core.debug(`[${appEdit.id}, versionCode=${versionCode}, packageName=${options.applicationId}]: Uploading Proguard mapping file @ ${options.mappingFile}`);
yield androidPublisher.edits.deobfuscationfiles.upload({
auth: options.auth,
packageName: options.applicationId,
editId: appEdit.id,
apkVersionCode: versionCode,
deobfuscationFileType: 'proguard',
media: {
mimeType: 'application/octet-stream',
body: fs.createReadStream(options.mappingFile)
}
});
}
}
});
}
function uploadApk(appEdit, options, apkReleaseFile) {
return __awaiter(this, void 0, void 0, function* () {
core.debug(`[${appEdit.id}, packageName=${options.applicationId}]: Uploading APK @ ${apkReleaseFile}`);
const res = yield androidPublisher.edits.apks.upload({
auth: options.auth,
packageName: options.applicationId,
editId: appEdit.id,
media: {
mimeType: 'application/vnd.android.package-archive',
body: fs.createReadStream(apkReleaseFile)
}
});
return res.data;
});
}
function uploadBundle(appEdit, options, bundleReleaseFile) {
return __awaiter(this, void 0, void 0, function* () {
core.debug(`[${appEdit.id}, packageName=${options.applicationId}]: Uploading App Bundle @ ${bundleReleaseFile}`);
const res = yield androidPublisher.edits.bundles.upload({
auth: options.auth,
packageName: options.applicationId,
editId: appEdit.id,
media: {
mimeType: 'application/octet-stream',
body: fs.createReadStream(bundleReleaseFile)
}
});
return res.data;
});
}

View File

@@ -16,16 +16,44 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const wait_1 = require("./wait");
const edits_1 = require("./edits");
const { google } = require('googleapis');
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/androidpublisher']
});
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const ms = core.getInput('milliseconds');
console.log(`Waiting ${ms} milliseconds ...`);
core.debug((new Date()).toTimeString());
wait_1.wait(parseInt(ms));
core.debug((new Date()).toTimeString());
core.setOutput('time', new Date().toTimeString());
const serviceAccountJson = core.getInput('serviceAccountJson', { required: true });
const packageName = core.getInput('packageName', { required: true });
const releaseFile = core.getInput('releaseFile', { required: true });
const track = core.getInput('track', { required: true });
const userFraction = core.getInput('userFraction', { required: false });
const whatsNewDir = core.getInput('whatsNewDirectory', { required: false });
const mappingFile = core.getInput('mappingFile', { required: false });
// verify inputs
let userFractionFloat = parseFloat(userFraction);
if (!isNaN(userFractionFloat)) {
if (userFractionFloat <= 0.0 || userFractionFloat >= 1.0) {
core.setFailed('A provided userFraction must be between 0.0 and 1.0, exclusive-exclusive');
return;
}
}
else {
userFractionFloat = undefined;
}
// Insure that the api can find our service account credentials
core.exportVariable("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountJson);
const authClient = yield auth.getClient();
yield edits_1.uploadRelease({
auth: authClient,
applicationId: packageName,
track: track,
userFraction: userFractionFloat,
whatsNewDir: whatsNewDir,
mappingFile: mappingFile
}, releaseFile);
core.debug('Finished App Release!');
}
catch (error) {
core.setFailed(error.message);

View File

@@ -1,11 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function wait(milliseconds) {
return new Promise((resolve, reject) => {
if (typeof (milliseconds) !== 'number') {
throw new Error('milleseconds not a number');
}
setTimeout(() => resolve("done!"), milliseconds);
});
}
exports.wait = wait;