Skip to content

Commit 6ccc373

Browse files
author
Maxim Lobanov
committed
fix isPackageInstalled
1 parent 01cc11b commit 6ccc373

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

dist/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36236,9 +36236,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
3623636236
return result;
3623736237
};
3623836238
Object.defineProperty(exports, "__esModule", { value: true });
36239-
exports.isEmptyDirectory = exports.getBooleanInput = exports.getListInput = exports.splitByEOL = void 0;
36239+
exports.getBooleanInput = exports.getListInput = exports.splitByEOL = void 0;
3624036240
const core = __importStar(__webpack_require__(470));
36241-
const fs = __importStar(__webpack_require__(747));
3624236241
exports.splitByEOL = (stdout) => {
3624336242
return stdout.split(/[\r\n]/);
3624436243
};
@@ -36249,10 +36248,6 @@ exports.getListInput = (inputName) => {
3624936248
exports.getBooleanInput = (inputName) => {
3625036249
return (core.getInput(inputName) || "false").toUpperCase() === "TRUE";
3625136250
};
36252-
exports.isEmptyDirectory = (directoryPath) => {
36253-
const children = fs.readdirSync(directoryPath);
36254-
return children.length === 0;
36255-
};
3625636251

3625736252

3625836253
/***/ }),
@@ -42050,6 +42045,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4205042045
exports.SDKManager = void 0;
4205142046
const core = __importStar(__webpack_require__(470));
4205242047
const exec = __importStar(__webpack_require__(986));
42048+
const fs = __importStar(__webpack_require__(747));
4205342049
const path_1 = __importDefault(__webpack_require__(622));
4205442050
const sdk_manager_parser_1 = __webpack_require__(551);
4205542051
const utils_1 = __webpack_require__(611);
@@ -42074,6 +42070,13 @@ class SDKManager {
4207442070
const relativePath = packageInfo.name.replace(";", "/");
4207542071
return path_1.default.join(this.androidHome, relativePath);
4207642072
}
42073+
isPackageInstalled(packageInfo) {
42074+
const packagePath = this.getPackagePath(packageInfo);
42075+
if (!fs.existsSync(packagePath)) {
42076+
return false;
42077+
}
42078+
return fs.readdirSync(packagePath).length > 0;
42079+
}
4207742080
async run(args, printOutputInDebug) {
4207842081
let stdout = "";
4207942082
let previousPrintedLine = "";
@@ -47580,7 +47583,7 @@ const run = async () => {
4758047583
core.info("Trying to restore package from cache...");
4758147584
const cacheHitKey = await cache.restoreCache([localPackagePath], cacheKey);
4758247585
cacheHit = Boolean(cacheHitKey);
47583-
if (cacheHit && utils_1.isEmptyDirectory(localPackagePath)) {
47586+
if (cacheHit && !sdkmanager.isPackageInstalled(foundPackage)) {
4758447587
core.debug(" [WARNING] Cache is invalid and contains empty folder. ");
4758547588
cacheHit = false;
4758647589
}

src/sdk-manager.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from "@actions/core";
22
import * as exec from "@actions/exec";
3+
import * as fs from "fs";
34
import path from "path";
45
import { parseSDKManagerOutput, AndroidPackageInfo } from "./sdk-manager-parser";
56
import { splitByEOL } from "./utils";
@@ -31,6 +32,15 @@ export class SDKManager {
3132
return path.join(this.androidHome, relativePath);
3233
}
3334

35+
public isPackageInstalled(packageInfo: AndroidPackageInfo): boolean {
36+
const packagePath = this.getPackagePath(packageInfo);
37+
if (!fs.existsSync(packagePath)) {
38+
return false;
39+
}
40+
41+
return fs.readdirSync(packagePath).length > 0;
42+
}
43+
3444
private async run(args: string[], printOutputInDebug: boolean): Promise<string> {
3545
let stdout = "";
3646
let previousPrintedLine = "";

src/setup-android-tools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as core from "@actions/core";
33
import * as exec from "@actions/exec";
44
import * as os from "os";
55
import { SDKManager } from "./sdk-manager";
6-
import { getListInput, getBooleanInput, isEmptyDirectory } from "./utils";
6+
import { getListInput, getBooleanInput } from "./utils";
77

88
const patchUbuntuPermissions = async(androidHome: string): Promise<void> => {
99
core.info("Patch permissions for $ANDROID_HOME on Ubuntu");
@@ -44,7 +44,7 @@ const run = async(): Promise<void> => {
4444
core.info("Trying to restore package from cache...");
4545
const cacheHitKey = await cache.restoreCache([localPackagePath], cacheKey);
4646
cacheHit = Boolean(cacheHitKey);
47-
if (cacheHit && isEmptyDirectory(localPackagePath)) {
47+
if (cacheHit && !sdkmanager.isPackageInstalled(foundPackage)) {
4848
core.debug(" [WARNING] Cache is invalid and contains empty folder. ");
4949
cacheHit = false;
5050
}

src/utils.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as core from "@actions/core";
2-
import * as fs from "fs";
32

43
export const splitByEOL = (stdout: string): string[] => {
54
return stdout.split(/[\r\n]/);
@@ -12,9 +11,4 @@ export const getListInput = (inputName: string): string[] => {
1211

1312
export const getBooleanInput = (inputName: string): boolean => {
1413
return (core.getInput(inputName) || "false").toUpperCase() === "TRUE";
15-
};
16-
17-
export const isEmptyDirectory = (directoryPath: string): boolean => {
18-
const children = fs.readdirSync(directoryPath);
19-
return children.length === 0;
20-
}
14+
};

0 commit comments

Comments
 (0)