Skip to content

Commit

Permalink
debug cache
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Mar 8, 2024
1 parent 0940221 commit 33d4919
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 61 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ jobs:
with:
version: ${{ matrix.version }}

- name: Capture Calcit
run: |
cr -e "range 20"
- name: Setup Calcit
uses: ./
with:
version: ${{ matrix.version }}
skipCache: true

- name: Capture Calcit
run: |
cr -e "range 20"
- name: Setup Calcit
uses: ./
with:
version: ${{ matrix.version }}
skipCache: false

- name: Capture Calcit
run: |
cr --help
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ inputs:
description: Version of Calcit install
required: true
default: 0.8.38
skipCache:
description: Disable Cache
required: false
default: false
runs:
using: node20
main: dist/index.js
Expand Down
54 changes: 25 additions & 29 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

54 changes: 23 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,32 @@ const fs = require("fs");
const core = require("@actions/core");
const tc = require("@actions/tool-cache");

let getCrDownloadUrl = (version) => {
return `https://github.com/calcit-lang/calcit/releases/download/${version}/cr`;
};

let getCapsDownloadUrl = (version) => {
return `https://github.com/calcit-lang/calcit/releases/download/${version}/caps`;
};

const version = core.getInput("version");
const skipCache = core.getInput("skipCache");

async function setup() {
const binFolder = `/home/runner/bin/`;

async function setup(bin) {
try {
// Get version of tool to be installed

const pathToCr = await tc.downloadTool(
getCrDownloadUrl(version),
"/home/runner/bin/cr"
);
const pathToCaps = await tc.downloadTool(
getCapsDownloadUrl(version),
"/home/runner/bin/caps"
);

// TODO cache
// https://github.com/actions/toolkit/tree/main/packages/tool-cache#cache

// Expose the tool by adding it to the PATH
fs.chmodSync(pathToCr, 0o755);
core.addPath(path.dirname(pathToCr));

console.log(`add to path: ${pathToCr}`);

fs.chmodSync(pathToCaps, 0o755);
core.addPath(path.dirname(pathToCaps));
console.log(`add to path: ${pathToCaps}`);
let url = `https://github.com/calcit-lang/calcit/releases/download/${version}/${bin}`;

let prevCr = tc.find(bin, version);
let binPath = `${binFolder}${bin}`;

if (prevCr && !skipCache) {
fs.copyFileSync(prevCr, binPath);
console.log(`use cached: ${prevCr}`);
} else {
const pathToCr = await tc.downloadTool(url, binPath);
console.log(`downloaded to: ${pathToCr}`);
const cachedPath = await tc.cacheFile(pathToCr, bin, bin, version);
console.log(`cached to: ${cachedPath}`);
}
fs.chmodSync(binPath, 0o755);
core.addPath(path.dirname(binFolder));
console.log(`add binary to path: ${binPath}`);
} catch (e) {
core.setFailed(e);
}
Expand All @@ -47,5 +38,6 @@ module.exports = setup;

if (require.main === module) {
console.log(`Setting up Calcit ${version}`);
setup();
setup("cr");
setup("caps");
}

0 comments on commit 33d4919

Please sign in to comment.