Skip to content

Commit

Permalink
try with input "local"
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Sep 12, 2023
1 parent ef85715 commit a8bbcb1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 36 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
token:
description: "Used to pull the latest release from sccache. When running this action outside of github.com, you have to pass a personal access token for github.com."
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
local:
description: "Creates a single cache artifact. Uses the local cache of the runner, saving and restoring. Will not create duplicate caches, only a single `sccache` bundle"
default: "true"
runs:
using: "node16"
main: "dist/setup/index.js"
Expand Down
2 changes: 1 addition & 1 deletion dist/post_run/index.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export const pleaseRestore = async () => {
return;
}
await restoreCache([path], key).then(r => {
console.log(`successfully restored cache: ${JSON.stringify(r)}`);
if (!r) {
console.log(`no cache matching "${path}" to restore`);
}
});
};

Expand Down
8 changes: 6 additions & 2 deletions src/post_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import {show_stats} from './show_stats';

const postRun = async () => {
await show_stats();
await deduplicate();
await pleaseSave();

const is_local = core.getInput('local', {required: false});
if (is_local == 'true') {
await deduplicate();
await pleaseSave();
}
};

postRun().catch(err => {
Expand Down
64 changes: 33 additions & 31 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,37 +99,39 @@ async function setup() {
process.env.ACTIONS_RUNTIME_TOKEN || ''
);

// TODO: get this the right way
let myOutput = '';
let myError = '';

const options: ExecOptions = {};
options.listeners = {
stdout: (data: Buffer) => {
myOutput += data.toString();
},
stderr: (data: Buffer) => {
myError += data.toString();
}
};

await exec(
`${sccacheHome}/sccache`,
['--show-stats', '--stats-format', 'json'],
options
).catch(e => {
console.log(`exec error: ${e}`);
console.log(myError);
});
const json = JSON.parse(myOutput);
console.log(`\n${json.cache_location}`);
let cache_path = json.cache_location.split(':')[1].trim().slice(1, -1);

core.exportVariable('SCCACHE_CACHE_DIR', cache_path);

await pleaseRestore();

core.exportVariable('RUSTC_WRAPPER', `sccache`);
const is_local = core.getInput('local', {required: false});

if (is_local == 'true') {
let myOutput = '';
let myError = '';

const options: ExecOptions = {};
options.listeners = {
stdout: (data: Buffer) => {
myOutput += data.toString();
},
stderr: (data: Buffer) => {
myError += data.toString();
}
};

await exec(
`${sccacheHome}/sccache`,
['--show-stats', '--stats-format', 'json'],
options
).catch(e => {
console.log(`exec error: ${e}`);
console.log(myError);
});
const json = JSON.parse(myOutput);
console.log(`\n${json.cache_location}`);
let cache_path = json.cache_location.split(':')[1].trim().slice(1, -1);

Check failure on line 128 in src/setup.ts

View workflow job for this annotation

GitHub Actions / build

'cache_path' is never reassigned. Use 'const' instead

Check failure on line 128 in src/setup.ts

View workflow job for this annotation

GitHub Actions / build

'cache_path' is never reassigned. Use 'const' instead

core.exportVariable('SCCACHE_CACHE_DIR', cache_path);

await pleaseRestore();
core.exportVariable('RUSTC_WRAPPER', `sccache`);
}
}

function getFilename(version: string): Error | string {
Expand Down

0 comments on commit a8bbcb1

Please sign in to comment.