Skip to content

Commit 3c15bb7

Browse files
author
Maxim Lobanov
committed
add cache restore
1 parent a34d3a9 commit 3c15bb7

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ inputs:
55
packages:
66
description: 'Packages to install'
77
required: true
8+
cache:
9+
description: 'Enable caching'
10+
required: false
811
runs:
912
using: 'node12'
1013
main: 'dist/index.js'

dist/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47561,17 +47561,28 @@ const run = async () => {
4756147561
core.info(`Installing '${packageName}'...`);
4756247562
const foundPackage = allPackages.find(p => p.name === packageName);
4756347563
if (!foundPackage) {
47564-
throw new Error(` Package '${packageName}' is not available. Enable debug output for more details.`);
47564+
throw new Error(`Package '${packageName}' is not available. Enable debug output for more details.`);
4756547565
}
4756647566
if (foundPackage.installed && !foundPackage.update) {
47567-
core.info(`Package '${foundPackage.name}' is already installed and update is not required`);
47567+
core.info(` Package '${foundPackage.name}' is already installed and update is not required`);
4756847568
continue;
4756947569
}
4757047570
const cacheKey = `${foundPackage.name} ${foundPackage.remoteVersion}`;
47571-
await sdkmanager.install(foundPackage);
4757247571
const localPackagePath = sdkmanager.getPackagePath(foundPackage);
47572+
let cacheHit = false;
47573+
if (enableCache) {
47574+
const cacheHitKey = await cache.restoreCache([localPackagePath], cacheKey);
47575+
cacheHit = Boolean(cacheHitKey);
47576+
}
47577+
if (cacheHit) {
47578+
core.info(` Package ${foundPackage.name}' is restored from cache`);
47579+
continue;
47580+
}
47581+
await sdkmanager.install(foundPackage);
47582+
core.info(` Package ${foundPackage.name}' is downloaded and installed`);
4757347583
if (enableCache) {
4757447584
await cache.saveCache([localPackagePath], cacheKey);
47585+
core.info(` Package ${foundPackage.name}' is saved to cache`);
4757547586
}
4757647587
}
4757747588
}

src/setup-android-tools.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,34 @@ const run = async(): Promise<void> => {
2828
core.info(`Installing '${packageName}'...`);
2929
const foundPackage = allPackages.find(p => p.name === packageName);
3030
if (!foundPackage) {
31-
throw new Error(` Package '${packageName}' is not available. Enable debug output for more details.`);
31+
throw new Error(`Package '${packageName}' is not available. Enable debug output for more details.`);
3232
}
3333

3434
if (foundPackage.installed && !foundPackage.update) {
35-
core.info(`Package '${foundPackage.name}' is already installed and update is not required`);
35+
core.info(` Package '${foundPackage.name}' is already installed and update is not required`);
3636
continue;
3737
}
3838

3939
const cacheKey = `${foundPackage.name} ${foundPackage.remoteVersion}`;
40+
const localPackagePath = sdkmanager.getPackagePath(foundPackage);
4041

41-
await sdkmanager.install(foundPackage);
42+
let cacheHit = false;
43+
if (enableCache) {
44+
const cacheHitKey = await cache.restoreCache([localPackagePath], cacheKey);
45+
cacheHit = Boolean(cacheHitKey);
46+
}
4247

43-
const localPackagePath = sdkmanager.getPackagePath(foundPackage);
48+
if (cacheHit) {
49+
core.info(` Package ${foundPackage.name}' is restored from cache`);
50+
continue;
51+
}
52+
53+
await sdkmanager.install(foundPackage);
54+
core.info(` Package ${foundPackage.name}' is downloaded and installed`);
4455

4556
if (enableCache) {
4657
await cache.saveCache([localPackagePath], cacheKey);
58+
core.info(` Package ${foundPackage.name}' is saved to cache`);
4759
}
4860
}
4961
} catch (error) {

0 commit comments

Comments
 (0)