Add Debug Symbol File/Folder Upload (#130)
* Add Debug Symbol File/Folder Upload Uploads Deobfuscation File type 'nativeCode'. Inputs allowed in 'debugSymbols', a .zip file, or a folder that contains the symbols. * Space Formatting * Zip Directory Function higher level, and formatting
This commit is contained in:
67
src/edits.ts
67
src/edits.ts
@@ -1,6 +1,9 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as fs from "fs";
|
||||
import { readFileSync } from "fs";
|
||||
import { readFileSync, lstatSync } from "fs";
|
||||
import JSZip from 'jszip';
|
||||
import path = require('path');
|
||||
import { Readable } from 'stream';
|
||||
|
||||
import * as google from '@googleapis/androidpublisher';
|
||||
import { androidpublisher_v3 } from "@googleapis/androidpublisher";
|
||||
@@ -24,6 +27,7 @@ export interface EditOptions {
|
||||
userFraction: number;
|
||||
whatsNewDir?: string;
|
||||
mappingFile?: string;
|
||||
debugSymbols?: string;
|
||||
name?: string;
|
||||
status: string;
|
||||
changesNotSentForReview?: boolean;
|
||||
@@ -122,10 +126,12 @@ async function uploadRelease(appEditId: string, options: EditOptions, releaseFil
|
||||
if (releaseFile.endsWith('.apk')) {
|
||||
const apk = await uploadApk(appEditId, options, releaseFile);
|
||||
await uploadMappingFile(appEditId, apk.versionCode!, options);
|
||||
await uploadDebugSymbolsFile(appEditId, apk.versionCode!, options);
|
||||
return Promise.resolve(apk.versionCode);
|
||||
} else if (releaseFile.endsWith('.aab')) {
|
||||
const bundle = await uploadBundle(appEditId, options, releaseFile);
|
||||
await uploadMappingFile(appEditId, bundle.versionCode!, options);
|
||||
await uploadDebugSymbolsFile(appEditId, bundle.versionCode!, options);
|
||||
return Promise.resolve(bundle.versionCode);
|
||||
} else {
|
||||
return Promise.reject(`${releaseFile} is invalid`);
|
||||
@@ -192,6 +198,65 @@ async function uploadMappingFile(appEditId: string, versionCode: number, options
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadDebugSymbolsFile(appEditId: string, versionCode: number, options: EditOptions) {
|
||||
if (options.debugSymbols != undefined && options.debugSymbols.length > 0) {
|
||||
const fileStat = lstatSync(options.debugSymbols);
|
||||
|
||||
var data: Buffer | null = null;
|
||||
if (fileStat.isDirectory()) {
|
||||
data = await createDebugSymbolZipFile(options.debugSymbols);
|
||||
}
|
||||
|
||||
if (data == null) {
|
||||
data = readFileSync(options.debugSymbols);
|
||||
}
|
||||
|
||||
if (data != null) {
|
||||
core.debug(`[${appEditId}, versionCode=${versionCode}, packageName=${options.applicationId}]: Uploading Debug Symbols file @ ${options.debugSymbols}`);
|
||||
const res = await androidPublisher.edits.deobfuscationfiles.upload({
|
||||
auth: options.auth,
|
||||
packageName: options.applicationId,
|
||||
editId: appEditId,
|
||||
apkVersionCode: versionCode,
|
||||
deobfuscationFileType: 'nativeCode',
|
||||
media: {
|
||||
mimeType: 'application/octet-stream',
|
||||
body: Readable.from(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function zipFileAddDirectory(root: JSZip | null, dirPath: string, rootPath: string, isRootRoot: boolean) {
|
||||
if (root == null) return root;
|
||||
|
||||
const newRootPath = path.join(rootPath, dirPath);
|
||||
const fileStat = lstatSync(newRootPath);
|
||||
|
||||
if (!fileStat.isDirectory()) {
|
||||
const data = readFileSync(newRootPath);
|
||||
root.file(dirPath, data);
|
||||
return root;
|
||||
}
|
||||
|
||||
const dir = fs.readdirSync(newRootPath);
|
||||
const zipFolder = isRootRoot ? root : root.folder(dirPath);
|
||||
for (var pathIndex = 0; pathIndex < dir.length; pathIndex++) {
|
||||
const underPath = dir[pathIndex];
|
||||
await zipFileAddDirectory(zipFolder, underPath, newRootPath, false);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
async function createDebugSymbolZipFile(debugSymbolsPath: string) {
|
||||
const zipFile = JSZip();
|
||||
await zipFileAddDirectory(zipFile, ".", debugSymbolsPath, true);
|
||||
|
||||
return zipFile.generateAsync({ type: "nodebuffer" });
|
||||
}
|
||||
|
||||
async function internalSharingUploadApk(options: EditOptions, apkReleaseFile: string): Promise<InternalAppSharingArtifact> {
|
||||
core.debug(`[packageName=${options.applicationId}]: Uploading Internal Sharing APK @ ${apkReleaseFile}`);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ async function run() {
|
||||
var status = core.getInput('status', { required: false });
|
||||
const whatsNewDir = core.getInput('whatsNewDirectory', { required: false });
|
||||
const mappingFile = core.getInput('mappingFile', { required: false });
|
||||
const debugSymbols = core.getInput('debugSymbols', { required: false });
|
||||
const changesNotSentForReview = core.getInput('changesNotSentForReview', { required: false }) == 'true';
|
||||
const existingEditId = core.getInput('existingEditId');
|
||||
|
||||
@@ -108,6 +109,11 @@ async function run() {
|
||||
return
|
||||
}
|
||||
|
||||
if (debugSymbols != undefined && debugSymbols.length > 0 && !fs.existsSync(debugSymbols)) {
|
||||
core.setFailed(`Unable to find 'debugSymbols' @ ${debugSymbols}`);
|
||||
return
|
||||
}
|
||||
|
||||
const authClient = await auth.getClient();
|
||||
|
||||
const result = await uploadToPlayStore({
|
||||
@@ -118,6 +124,7 @@ async function run() {
|
||||
userFraction: userFraction,
|
||||
whatsNewDir: whatsNewDir,
|
||||
mappingFile: mappingFile,
|
||||
debugSymbols: debugSymbols,
|
||||
name: releaseName,
|
||||
changesNotSentForReview: changesNotSentForReview,
|
||||
existingEditId: existingEditId,
|
||||
|
||||
Reference in New Issue
Block a user