Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit 7b5d7d9

Browse files
authored
Merge pull request #4 from microsoft/githubAction
Added Github action
2 parents 21f5718 + 45bc00d commit 7b5d7d9

File tree

14 files changed

+170
-45
lines changed

14 files changed

+170
-45
lines changed

.github/workflows/gh-action-test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Github Action Test
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
os: [ubuntu-latest, macos-latest, windows-latest]
12+
13+
steps:
14+
- uses: actions/checkout@v1
15+
name: Checkout repo
16+
17+
- name: Run App size diff
18+
uses: ./
19+
with:
20+
baseAppPath: 'test/assets/test.apk'
21+
targetAppPath: 'test/assets/test.apk'
22+
summaryOutputPath: summary.md
23+
24+
- name: Print summary
25+
run: cat summary.md

action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'Android App size difference'
2+
description: 'Compares the size of 2 APKs'
3+
inputs:
4+
baseAppPath:
5+
description: 'Path to base apk. This is the app before changes'
6+
required: true
7+
default: ''
8+
targetAppPath:
9+
description: 'Path to target apk. This is the app after changes'
10+
required: true
11+
default: ''
12+
summaryOutputPath:
13+
description: 'Output file where comparision summary should be written to'
14+
required: true
15+
default: ''
16+
runs:
17+
using: 'node12'
18+
main: 'dist_gh_action/index.js'

ado-extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifestVersion": 1,
33
"id": "android-app-size-diff",
44
"name": "Android app size changes",
5-
"version": "0.0.22",
5+
"version": "0.0.24",
66
"publisher": "PraveenPendyala",
77
"targets": [
88
{

dist_gh_action/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist_gh_action/lib.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"messages": {
3+
"LIB_UnhandledEx": "Unhandled: %s",
4+
"LIB_FailOnCode": "Failure return code: %d",
5+
"LIB_MkdirFailed": "Unable to create directory '%s'. %s",
6+
"LIB_MkdirFailedFileExists": "Unable to create directory '%s'. Conflicting file exists: '%s'",
7+
"LIB_MkdirFailedInvalidDriveRoot": "Unable to create directory '%s'. Root directory does not exist: '%s'",
8+
"LIB_MkdirFailedInvalidShare": "Unable to create directory '%s'. Unable to verify the directory exists: '%s'. If directory is a file share, please verify the share name is correct, the share is online, and the current process has permission to access the share.",
9+
"LIB_MultilineSecret": "Secrets cannot contain multiple lines",
10+
"LIB_ProcessError": "There was an error when attempting to execute the process '%s'. This may indicate the process failed to start. Error: %s",
11+
"LIB_ProcessExitCode": "The process '%s' failed with exit code %s",
12+
"LIB_ProcessStderr": "The process '%s' failed because one or more lines were written to the STDERR stream",
13+
"LIB_ReturnCode": "Return code: %d",
14+
"LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s",
15+
"LIB_ResourceFileAlreadySet": "Resource file has already set to: %s",
16+
"LIB_ResourceFileNotSet": "Resource file haven\\'t set, can\\'t find loc string for key: %s",
17+
"LIB_StdioNotClosed": "The STDIO streams did not close within %s seconds of the exit event from process '%s'. This may indicate a child process inherited the STDIO streams and has not yet exited.",
18+
"LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.",
19+
"LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.",
20+
"LIB_LocStringNotFound": "Can\\'t find loc string for key: %s",
21+
"LIB_ParameterIsRequired": "%s not supplied",
22+
"LIB_InputRequired": "Input required: %s",
23+
"LIB_InvalidPattern": "Invalid pattern: '%s'",
24+
"LIB_EndpointNotExist": "Endpoint not present: %s",
25+
"LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s",
26+
"LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s",
27+
"LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s",
28+
"LIB_InvalidSecureFilesInput": "Invalid secure file input: %s",
29+
"LIB_PathNotFound": "Not found %s: %s",
30+
"LIB_PathHasNullByte": "Path cannot contain null bytes",
31+
"LIB_OperationFailed": "Failed %s: %s",
32+
"LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.",
33+
"LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
34+
"LIB_PlatformNotSupported": "Platform not supported: %s"
35+
}
36+
}

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "android-app-size-ado",
3-
"version": "0.0.22",
3+
"version": "0.0.24",
44
"description": "Azure DevOps task to measure the size in Android app size by looking at 2 given APKs and AABs",
55
"main": "index.js",
66
"scripts": {
@@ -9,7 +9,8 @@
99
"build-ts": "tsc",
1010
"copy-files": "ts-node copyFiles.ts",
1111
"test": "npm run build && mocha dist/test/**/*.js",
12-
"bundle": "npm run build && npm run bundle-ado-task",
12+
"bundle": "npm run build && npm run bundle-ado-task && npm run bundle-gh-action",
13+
"bundle-gh-action": "ncc build src/gh-action-index.ts -m -o dist_gh_action",
1314
"bundle-ado-task": "tfx extension create --manifest-globs ado-extension.json",
1415
"bump-major": "ts-node bumpVersion.ts major",
1516
"bump-minor": "ts-node bumpVersion.ts minor",
@@ -32,6 +33,7 @@
3233
},
3334
"homepage": "https://github.com/microsoft/android-app-size-ci#readme",
3435
"dependencies": {
36+
"@actions/core": "^1.2.0",
3537
"@types/adm-zip": "^0.4.32",
3638
"@types/line-reader": "0.0.28",
3739
"adm-zip": "^0.4.13",

src/adoTask/adoTaskRunner.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,12 @@
11
import * as adoTask from 'azure-pipelines-task-lib/task';
2-
import * as util from 'util';
3-
import ApkAnalyzer from '../apkAnalyzer/ApkAnalyzer';
4-
import ComparisionReportGenerator from '../apkAnalyzer/ComparisionReportGenerator';
5-
import { MarkdownReporter } from '../apkAnalyzer/reporter/MarkdownReporter';
2+
import CiRunner from '../apkAnalyzer/CiRunner';
63

74
export default class AdoTaskRunner {
85

96
public async run() {
107
try {
11-
const baseAppPath: string | undefined = adoTask.getInput('baseAppPath', true);
12-
const targetAppPath: string | undefined = adoTask.getInput('targetAppPath', true);
13-
const summaryOutputPath: string | undefined = adoTask.getInput('summaryOutputPath', false);
14-
15-
if (util.isUndefined(baseAppPath)
16-
|| util.isUndefined(targetAppPath)
17-
|| util.isUndefined(summaryOutputPath)) {
18-
throw 'App paths not supplied!'
19-
}
20-
21-
const apkAnalyzer = new ApkAnalyzer();
22-
const markdownReportor = new MarkdownReporter();
23-
const compareReportGenerator = new ComparisionReportGenerator(
24-
apkAnalyzer, markdownReportor);
25-
26-
console.log(await compareReportGenerator.generateComparisionReport(
27-
baseAppPath,
28-
targetAppPath,
29-
summaryOutputPath,
30-
'Base APK',
31-
'Target APK',
32-
['apkSize', 'installSize', 'dexFiles', 'arscFile']
33-
));
8+
const ciRunner = new CiRunner(adoTask);
9+
await ciRunner.run();
3410
}
3511
catch (err) {
3612
adoTask.setResult(adoTask.TaskResult.Failed, err.message);

src/apkAnalyzer/CiRunner.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as util from 'util';
2+
import ApkAnalyzer from '../apkAnalyzer/ApkAnalyzer';
3+
import ComparisionReportGenerator from '../apkAnalyzer/ComparisionReportGenerator';
4+
import { MarkdownReporter } from '../apkAnalyzer/reporter/MarkdownReporter';
5+
6+
export interface CiCore {
7+
getInput(name: string): string | undefined;
8+
}
9+
10+
/**
11+
* Runs Apk comparision on a CI - Github workflow or ADO Task
12+
*/
13+
export default class CiRunner {
14+
ciCore: CiCore; // either Github action core or ADO Task
15+
16+
constructor(ciCore: CiCore) {
17+
this.ciCore = ciCore;
18+
}
19+
20+
public async run() {
21+
const baseAppPath = this.ciCore.getInput('baseAppPath');
22+
const targetAppPath = this.ciCore.getInput('targetAppPath');
23+
const summaryOutputPath = this.ciCore.getInput('summaryOutputPath');
24+
25+
if (util.isUndefined(baseAppPath)
26+
|| util.isUndefined(targetAppPath)
27+
|| util.isUndefined(summaryOutputPath)) {
28+
throw 'App paths not supplied!'
29+
}
30+
31+
const apkAnalyzer = new ApkAnalyzer();
32+
const markdownReportor = new MarkdownReporter();
33+
const compareReportGenerator = new ComparisionReportGenerator(
34+
apkAnalyzer, markdownReportor);
35+
36+
return console.log(await compareReportGenerator.generateComparisionReport(
37+
baseAppPath,
38+
targetAppPath,
39+
summaryOutputPath,
40+
'Base APK',
41+
'Target APK',
42+
['apkSize', 'installSize', 'dexFiles', 'arscFile']
43+
));
44+
}
45+
46+
47+
}

src/apkAnalyzer/MetaMfParser.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ import LineReader from 'line-reader';
22
import * as path from 'path';
33
import * as util from 'util';
44

5-
/**
6-
* Map from extension to all files with that extension
7-
*/
8-
interface ExtensionFiles {
9-
[key: string]: Array<string>;
10-
}
11-
125
/**
136
* Parses the contents of the Android MetaMf file and sorts the list of files based on extension
147
*/
@@ -53,11 +46,14 @@ interface ExtensionFiles {
5346

5447
const filePath = path.join(this.mBasePath, line.split('Name: ', 2)[1]);
5548
const extension = path.extname(filePath);
56-
49+
5750
if (!this.mFilesExtensionMap.has(extension)) {
5851
this.mFilesExtensionMap.set(extension, []);
5952
}
6053

61-
this.mFilesExtensionMap.get(extension)?.push(filePath);
54+
const filesForExt = this.mFilesExtensionMap.get(extension);
55+
if (!util.isUndefined(filesForExt)) {
56+
filesForExt.push(filePath);
57+
}
6258
}
6359
}

0 commit comments

Comments
 (0)