Skip to content

Commit 6f533eb

Browse files
Skycoder42mymindstorm
authored andcommitted
Improve caching logic of #1 (#3)
* Improve caching logic of #1 Uses a single step instead of two seperate steps, as it is less bugprone * Update as requested and suggested by @mymindstorm
1 parent 20f9d85 commit 6f533eb

5 files changed

Lines changed: 23 additions & 47 deletions

File tree

.github/workflows/run.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,13 @@ jobs:
2121
with:
2222
path: emsdk-cache
2323
key: ${{ runner.os }}-emsdk-1.38.48
24-
- name: Setup emsdk (cache not found)
24+
- name: Setup emsdk (use cache if found, create otherwise)
2525
uses: mymindstorm/setup-emsdk@master
26-
if: steps.cache.outputs.cache-hit != 'true'
27-
with:
28-
version: 1.38.48
29-
store-actions-cache: 'emsdk-cache'
30-
no-cache: true
31-
- name: Setup emsdk (cache found)
32-
uses: mymindstorm/setup-emsdk@master
33-
if: steps.cache.outputs.cache-hit == 'true'
3426
with:
3527
version: 1.38.48
3628
actions-cache-folder: 'emsdk-cache'
3729
no-cache: true
30+
3831
- name: Verify
3932
run: emcc -v
4033
no-install:

README.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,24 @@ jobs:
2525
uses: actions/cache@v1
2626
id: cache # This is important!
2727
with:
28-
# Set to the same folder as store-actions-cache (more below)
28+
# Set to the same folder as actions-cache-folder (more below)
2929
path: 'emsdk-cache'
3030
# Set the end bit to emsdk version
3131
key: ${{ runner.os }}-emsdk-1.38.40
3232

33-
- name: Setup emsdk (cache not found)
33+
- name: Setup emsdk (use cache if found, create otherwise)
3434
uses: mymindstorm/setup-emsdk@v2
35-
if: steps.cache.outputs.cache-hit != 'true'
3635
with:
3736
# Make sure to set a version number!
3837
version: 1.38.40
3938
# This is the name of the cache folder.
4039
# The cache folder will be placed in the build directory,
4140
# so make sure it doesn't conflict with anything!
42-
store-actions-cache: 'emsdk-cache'
41+
actions-cache-folder: 'emsdk-cache'
4342
# This stops it from using tc.cacheDir since we are using
4443
# actions/cache.
4544
no-cache: true
4645

47-
- name: Setup emsdk (cache found)
48-
uses: mymindstorm/setup-emsdk@v2
49-
if: steps.cache.outputs.cache-hit == 'true'
50-
with:
51-
# Make sure to set a version number!
52-
version: 1.38.40
53-
# Set to the same folder as store-actions-cache
54-
actions-cache-folder: 'emsdk-cache'
55-
no-cache: true
56-
5746
- name: Verify
5847
run: emcc -v
5948
```
@@ -70,11 +59,8 @@ no-install:
7059
no-cache:
7160
description: "If true will not cache any downloads with tc.cacheDir."
7261
default: false
73-
store-actions-cache:
74-
description: "Name of the folder emsdk cache will be copied to on sucessful run. This folder will go under $GITHUB_HOME (I.e. build dir)"
75-
default: ''
7662
actions-cache-folder:
77-
description: "Set to the folder where your cached emsdk-master folder is."
63+
description: "Set to the folder where your cached emsdk-master folder is or where emsdk cache will be copied to on sucessful run. This folder will go under $GITHUB_HOME (I.e. build dir)."
7864
default: ''
7965
```
8066

action.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ inputs:
1111
no-cache:
1212
description: "If true will not cache any downloads with tc.cacheDir."
1313
default: false
14-
store-actions-cache:
15-
description: "Name of the folder emsdk cache will be copied to on sucessful run. This folder will go under $GITHUB_HOME (I.e. build dir)"
16-
default: ''
1714
actions-cache-folder:
18-
description: "Set to the folder where your cached emsdk-master folder is."
15+
description: "Set to the folder where your cached emsdk-master folder is or where emsdk cache will be copied to on sucessful run. This folder will go under $GITHUB_HOME (I.e. build dir)."
1916
default: ''
2017
runs:
2118
using: 'node12'

lib/main.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ function run() {
2727
version: yield core.getInput("version"),
2828
noInstall: yield core.getInput("no-install"),
2929
noCache: yield core.getInput("no-cache"),
30-
storeActionsCache: yield core.getInput("store-actions-cache"),
31-
useActionsCacheFolder: yield core.getInput("actions-cache-folder")
30+
actionsCacheFolder: yield core.getInput("actions-cache-folder")
3231
};
3332
let emsdkFolder;
3433
let foundInCache = false;
3534
if (emArgs.version !== "latest" && emArgs.noCache === "false") {
3635
emsdkFolder = yield tc.find('emsdk', emArgs.version, os.arch());
3736
}
38-
if (emArgs.useActionsCacheFolder) {
39-
const fullCachePath = `${process.env.GITHUB_WORKSPACE}/${emArgs.useActionsCacheFolder}`;
37+
if (emArgs.actionsCacheFolder) {
38+
const fullCachePath = `${process.env.GITHUB_WORKSPACE}/${emArgs.actionsCacheFolder}`;
4039
try {
4140
fs.accessSync(fullCachePath + '/emsdk-master/emsdk', fs.constants.X_OK);
4241
emsdkFolder = fullCachePath;
4342
foundInCache = true;
4443
}
4544
catch (e) {
46-
core.error(`Could not access cached files at path: ${fullCachePath}`);
45+
core.warning(`No cached files found at path "${fullCachePath}" - downloading and caching emsdk.`);
46+
yield exec.exec(`rm -rf ${fullCachePath}`);
4747
// core.debug(fs.readdirSync(fullCachePath + '/emsdk-master').toString());
4848
}
4949
}
@@ -92,9 +92,9 @@ function run() {
9292
}
9393
}
9494
} });
95-
if (emArgs.storeActionsCache) {
96-
fs.mkdirSync(`${process.env.GITHUB_WORKSPACE}/${emArgs.storeActionsCache}`, { recursive: true });
97-
yield exec.exec(`cp -r ${emsdkFolder}/emsdk-master ${process.env.GITHUB_WORKSPACE}/${emArgs.storeActionsCache}`);
95+
if (emArgs.actionsCacheFolder && !foundInCache) {
96+
fs.mkdirSync(`${process.env.GITHUB_WORKSPACE}/${emArgs.actionsCacheFolder}`, { recursive: true });
97+
yield exec.exec(`cp -r ${emsdkFolder}/emsdk-master ${process.env.GITHUB_WORKSPACE}/${emArgs.actionsCacheFolder}`);
9898
}
9999
}
100100
catch (error) {

src/main.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ async function run() {
1010
version: await core.getInput("version"),
1111
noInstall: await core.getInput("no-install"),
1212
noCache: await core.getInput("no-cache"),
13-
storeActionsCache: await core.getInput("store-actions-cache"),
14-
useActionsCacheFolder: await core.getInput("actions-cache-folder")
13+
actionsCacheFolder: await core.getInput("actions-cache-folder")
1514
};
1615

1716
let emsdkFolder;
@@ -21,14 +20,15 @@ async function run() {
2120
emsdkFolder = await tc.find('emsdk', emArgs.version, os.arch());
2221
}
2322

24-
if (emArgs.useActionsCacheFolder) {
25-
const fullCachePath = `${process.env.GITHUB_WORKSPACE}/${emArgs.useActionsCacheFolder}`
23+
if (emArgs.actionsCacheFolder) {
24+
const fullCachePath = `${process.env.GITHUB_WORKSPACE}/${emArgs.actionsCacheFolder}`
2625
try {
2726
fs.accessSync(fullCachePath + '/emsdk-master/emsdk', fs.constants.X_OK)
2827
emsdkFolder = fullCachePath;
2928
foundInCache = true;
3029
} catch (e) {
31-
core.error(`Could not access cached files at path: ${fullCachePath}`);
30+
core.warning(`No cached files found at path "${fullCachePath}" - downloading and caching emsdk.`);
31+
await exec.exec(`rm -rf ${fullCachePath}`);
3232
// core.debug(fs.readdirSync(fullCachePath + '/emsdk-master').toString());
3333
}
3434
}
@@ -86,9 +86,9 @@ async function run() {
8686
}
8787
}})
8888

89-
if (emArgs.storeActionsCache) {
90-
fs.mkdirSync(`${process.env.GITHUB_WORKSPACE}/${emArgs.storeActionsCache}`, { recursive: true });
91-
await exec.exec(`cp -r ${emsdkFolder}/emsdk-master ${process.env.GITHUB_WORKSPACE}/${emArgs.storeActionsCache}`);
89+
if (emArgs.actionsCacheFolder && !foundInCache) {
90+
fs.mkdirSync(`${process.env.GITHUB_WORKSPACE}/${emArgs.actionsCacheFolder}`, { recursive: true });
91+
await exec.exec(`cp -r ${emsdkFolder}/emsdk-master ${process.env.GITHUB_WORKSPACE}/${emArgs.actionsCacheFolder}`);
9292
}
9393
} catch (error) {
9494
core.setFailed(error.message);

0 commit comments

Comments
 (0)