Skip to content

Commit

Permalink
Actually take advantage of the tools cache
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Mar 15, 2024
1 parent 06b223e commit 7e2ecb2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 17 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ jobs:
go-version: '1.21'
- name: Make
run: make integration

setup_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: ./actions/setup

- name: Lint
run: grr --version
32 changes: 24 additions & 8 deletions actions/setup/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
/***/ 2932:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const fsPromises = (__nccwpck_require__(7147).promises);
const path = __nccwpck_require__(1017);
const core = __nccwpck_require__(2186);
const tc = __nccwpck_require__(7784);
const { downloadBinary, identifyLatest } = __nccwpck_require__(918);

const toolName = 'grr';

async function setup() {
try {
// Get the version to be installed
Expand All @@ -20,21 +22,30 @@ async function setup() {
console.log(`Latest version is ${version}`);
}

console.log(tc.findAllVersions(toolName));

const cachedPath = tc.find(toolName, version)
if (cachedPath) {
console.log(`Using Grizzly ${version} from cache`);
core.addPath(cachedPath);
return;
}

const pathToBinary = await downloadBinary(version);
const binaryDirectory = path.dirname(pathToBinary);

await fsPromises.rename(pathToBinary, `${binaryDirectory}/grr`);
await fsPromises.chmod(`${binaryDirectory}/grr`, 0o755);
console.log(`path to downloaded binary: '${pathToBinary}'`);

const grrCacheDir = await tc.cacheFile(pathToBinary, toolName, toolName, version)

// Expose grizzly by adding it to the PATH
console.log('Adding Grizzly to PATH')
core.addPath(binaryDirectory);
console.log(`Adding Grizzly to PATH: ${grrCacheDir}`)
core.addPath(grrCacheDir);
} catch (e) {
core.setFailed(e);
}
}

module.exports = setup
module.exports = setup;

if (require.main === require.cache[eval('__filename')]) {
setup();
Expand All @@ -46,6 +57,7 @@ if (require.main === require.cache[eval('__filename')]) {
/***/ 918:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const fsPromises = (__nccwpck_require__(7147).promises);
const os = __nccwpck_require__(2037);
const tc = __nccwpck_require__(7784);

Expand Down Expand Up @@ -79,7 +91,11 @@ async function downloadBinary(version) {

console.log(`Downloading Grizzly ${version} from ${binaryURL}`);

return await tc.downloadTool(binaryURL);
const pathToBinary = await tc.downloadTool(binaryURL);

await fsPromises.chmod(pathToBinary, 0o755);

return pathToBinary;
}

async function identifyLatest() {
Expand Down
2 changes: 1 addition & 1 deletion actions/setup/dist/index.js.map

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions actions/setup/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const fsPromises = require('fs').promises;
const path = require('path');
const core = require('@actions/core');
const tc = require("@actions/tool-cache");
const { downloadBinary, identifyLatest } = require('./lib/utils');

const toolName = 'grr';

async function setup() {
try {
// Get the version to be installed
Expand All @@ -14,21 +16,30 @@ async function setup() {
console.log(`Latest version is ${version}`);
}

console.log(tc.findAllVersions(toolName));

const cachedPath = tc.find(toolName, version)
if (cachedPath) {
console.log(`Using Grizzly ${version} from cache`);
core.addPath(cachedPath);
return;
}

const pathToBinary = await downloadBinary(version);
const binaryDirectory = path.dirname(pathToBinary);

await fsPromises.rename(pathToBinary, `${binaryDirectory}/grr`);
await fsPromises.chmod(`${binaryDirectory}/grr`, 0o755);
console.log(`path to downloaded binary: '${pathToBinary}'`);

const grrCacheDir = await tc.cacheFile(pathToBinary, toolName, toolName, version)

// Expose grizzly by adding it to the PATH
console.log('Adding Grizzly to PATH')
core.addPath(binaryDirectory);
console.log(`Adding Grizzly to PATH: ${grrCacheDir}`)
core.addPath(grrCacheDir);
} catch (e) {
core.setFailed(e);
}
}

module.exports = setup
module.exports = setup;

if (require.main === module) {
setup();
Expand Down
7 changes: 6 additions & 1 deletion actions/setup/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fsPromises = require('fs').promises;
const os = require('os');
const tc = require("@actions/tool-cache");

Expand Down Expand Up @@ -31,7 +32,11 @@ async function downloadBinary(version) {

console.log(`Downloading Grizzly ${version} from ${binaryURL}`);

return await tc.downloadTool(binaryURL);
const pathToBinary = await tc.downloadTool(binaryURL);

await fsPromises.chmod(pathToBinary, 0o755);

return pathToBinary;
}

async function identifyLatest() {
Expand Down

0 comments on commit 7e2ecb2

Please sign in to comment.