Skip to content

Commit 6b81c8e

Browse files
committed
debug cache
1 parent 0940221 commit 6b81c8e

File tree

5 files changed

+73
-61
lines changed

5 files changed

+73
-61
lines changed

.github/workflows/test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ jobs:
2727
with:
2828
version: ${{ matrix.version }}
2929

30+
- name: Capture Calcit
31+
run: |
32+
cr -e "range 20"
33+
34+
- name: Setup Calcit
35+
uses: ./
36+
with:
37+
version: ${{ matrix.version }}
38+
skipCache: true
39+
40+
- name: Capture Calcit
41+
run: |
42+
cr -e "range 20"
43+
44+
- name: Setup Calcit
45+
uses: ./
46+
with:
47+
version: ${{ matrix.version }}
48+
skipCache: false
49+
3050
- name: Capture Calcit
3151
run: |
3252
cr --help

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ inputs:
66
description: Version of Calcit install
77
required: true
88
default: 0.8.38
9+
skipCache:
10+
description: Disable Cache
11+
required: false
12+
default: false
913
runs:
1014
using: node20
1115
main: dist/index.js

dist/index.js

Lines changed: 25 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

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

index.js

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,32 @@ const fs = require("fs");
33
const core = require("@actions/core");
44
const tc = require("@actions/tool-cache");
55

6-
let getCrDownloadUrl = (version) => {
7-
return `https://github.com/calcit-lang/calcit/releases/download/${version}/cr`;
8-
};
9-
10-
let getCapsDownloadUrl = (version) => {
11-
return `https://github.com/calcit-lang/calcit/releases/download/${version}/caps`;
12-
};
13-
146
const version = core.getInput("version");
7+
const skipCache = core.getInput("skipCache");
158

16-
async function setup() {
9+
const binFolder = `/home/runner/bin/`;
10+
11+
async function setup(bin) {
1712
try {
1813
// Get version of tool to be installed
1914

20-
const pathToCr = await tc.downloadTool(
21-
getCrDownloadUrl(version),
22-
"/home/runner/bin/cr"
23-
);
24-
const pathToCaps = await tc.downloadTool(
25-
getCapsDownloadUrl(version),
26-
"/home/runner/bin/caps"
27-
);
28-
29-
// TODO cache
30-
// https://github.com/actions/toolkit/tree/main/packages/tool-cache#cache
31-
32-
// Expose the tool by adding it to the PATH
33-
fs.chmodSync(pathToCr, 0o755);
34-
core.addPath(path.dirname(pathToCr));
35-
36-
console.log(`add to path: ${pathToCr}`);
37-
38-
fs.chmodSync(pathToCaps, 0o755);
39-
core.addPath(path.dirname(pathToCaps));
40-
console.log(`add to path: ${pathToCaps}`);
15+
let url = `https://github.com/calcit-lang/calcit/releases/download/${version}/${bin}`;
16+
17+
let prevCr = tc.find(bin, version);
18+
let binPath = `${binFolder}${bin}`;
19+
20+
if (prevCr && !skipCache) {
21+
fs.copyFileSync(prevCr, binPath);
22+
console.log(`use cached: ${prevCr}`);
23+
} else {
24+
const pathToCr = await tc.downloadTool(url, binPath);
25+
console.log(`downloaded to: ${pathToCr}`);
26+
const cachedPath = await tc.cacheFile(pathToCr, bin, bin, version);
27+
console.log(`cached to: ${cachedPath}`);
28+
}
29+
fs.chmodSync(binPath, 0o755);
30+
core.addPath(binFolder);
31+
console.log(`add binary to path: ${binPath}`);
4132
} catch (e) {
4233
core.setFailed(e);
4334
}
@@ -47,5 +38,6 @@ module.exports = setup;
4738

4839
if (require.main === module) {
4940
console.log(`Setting up Calcit ${version}`);
50-
setup();
41+
setup("cr");
42+
setup("caps");
5143
}

0 commit comments

Comments
 (0)