diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 16fb83ef..8500936d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -56,7 +56,7 @@ jobs: sccache -V sccache -s # sccache -s | grep -E 'Max cache size.+10 MiB' - sccache -s | grep -E 'Cache location.+ccache-action/\.sccache' + sccache -s | grep -E "Cache location.+${SCCACHE_DIR:-ccache-action[\\/]+\.sccache}" else which ccache ccache -V diff --git a/dist/restore/index.js b/dist/restore/index.js index 09faf964..b10d6669 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -59573,6 +59573,19 @@ var exec = __nccwpck_require__(1514); const external_process_namespaceObject = require("process"); // EXTERNAL MODULE: ./node_modules/@actions/cache/lib/cache.js var cache = __nccwpck_require__(7799); +;// CONCATENATED MODULE: ./src/common.ts + +function cacheDir(ccacheVariant) { + const ghWorkSpace = process.env.GITHUB_WORKSPACE || "unreachable, make ncc happy"; + if (ccacheVariant === "ccache") { + return process.env.CCACHE_DIR || external_path_default().join(ghWorkSpace, ".ccache"); + } + else if (ccacheVariant === "sccache") { + return process.env.SCCACHE_DIR || external_path_default().join(ghWorkSpace, ".sccache"); + } + throw Error("Unknown ccache variant: " + ccacheVariant); +} + ;// CONCATENATED MODULE: ./src/restore.ts @@ -59583,6 +59596,7 @@ var cache = __nccwpck_require__(7799); + const SELF_CI = external_process_namespaceObject.env.CCACHE_ACTION_CI === "true"; // based on https://cristianadam.eu/20200113/speeding-up-c-plus-plus-github-actions-using-ccache/ async function restore(ccacheVariant) { @@ -59594,7 +59608,7 @@ async function restore(ccacheVariant) { const keyPrefix = ccacheVariant + "-"; const primaryKey = inputs.primaryKey ? keyPrefix + inputs.primaryKey + "-" : keyPrefix; const restoreKeys = inputs.restoreKeys.map(k => keyPrefix + k + "-"); - const paths = [`.${ccacheVariant}`]; + const paths = [cacheDir(ccacheVariant)]; core.saveState("primaryKey", primaryKey); const shouldRestore = core.getBooleanInput("restore"); if (!shouldRestore) { @@ -59616,10 +59630,9 @@ async function restore(ccacheVariant) { } } async function configure(ccacheVariant, platform) { - const ghWorkSpace = external_process_namespaceObject.env.GITHUB_WORKSPACE || "unreachable, make ncc happy"; const maxSize = core.getInput('max-size'); if (ccacheVariant === "ccache") { - await execBash(`ccache --set-config=cache_dir='${external_path_default().join(ghWorkSpace, '.ccache')}'`); + await execBash(`ccache --set-config=cache_dir='${cacheDir(ccacheVariant)}'`); await execBash(`ccache --set-config=max_size='${maxSize}'`); await execBash(`ccache --set-config=compression=true`); if (platform === "darwin") { @@ -59640,7 +59653,7 @@ async function configure(ccacheVariant, platform) { await execBash("ccache -p"); } else { - const options = `SCCACHE_IDLE_TIMEOUT=0 SCCACHE_DIR='${ghWorkSpace}'/.sccache SCCACHE_CACHE_SIZE='${maxSize}'`; + const options = `SCCACHE_IDLE_TIMEOUT=0 SCCACHE_DIR='${cacheDir(ccacheVariant)}' SCCACHE_CACHE_SIZE='${maxSize}'`; await execBash(`env ${options} sccache --start-server`); } } diff --git a/dist/save/index.js b/dist/save/index.js index eef651d3..cd65ce5a 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -59543,16 +59543,38 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { "use strict"; +// ESM COMPAT FLAG __nccwpck_require__.r(__webpack_exports__); -/* harmony export */ __nccwpck_require__.d(__webpack_exports__, { -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) -/* harmony export */ }); -/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(2186); -/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _actions_cache__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(7799); -/* harmony import */ var _actions_cache__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__nccwpck_require__.n(_actions_cache__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(1514); -/* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__nccwpck_require__.n(_actions_exec__WEBPACK_IMPORTED_MODULE_2__); + +// EXPORTS +__nccwpck_require__.d(__webpack_exports__, { + "default": () => (/* binding */ save) +}); + +// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js +var core = __nccwpck_require__(2186); +// EXTERNAL MODULE: ./node_modules/@actions/cache/lib/cache.js +var cache = __nccwpck_require__(7799); +// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js +var exec = __nccwpck_require__(1514); +// EXTERNAL MODULE: external "path" +var external_path_ = __nccwpck_require__(1017); +var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_); +;// CONCATENATED MODULE: ./src/common.ts + +function cacheDir(ccacheVariant) { + const ghWorkSpace = process.env.GITHUB_WORKSPACE || "unreachable, make ncc happy"; + if (ccacheVariant === "ccache") { + return process.env.CCACHE_DIR || external_path_default().join(ghWorkSpace, ".ccache"); + } + else if (ccacheVariant === "sccache") { + return process.env.SCCACHE_DIR || external_path_default().join(ghWorkSpace, ".sccache"); + } + throw Error("Unknown ccache variant: " + ccacheVariant); +} + +;// CONCATENATED MODULE: ./src/save.ts + @@ -59578,51 +59600,51 @@ async function getVerbosity(verbositySetting) { case '2': return ' -vv'; default: - _actions_core__WEBPACK_IMPORTED_MODULE_0__.warning(`Invalid value "${verbositySetting}" of "verbose" option ignored.`); + core.warning(`Invalid value "${verbositySetting}" of "verbose" option ignored.`); return ''; } } function getExecBashOutput(cmd) { - return _actions_exec__WEBPACK_IMPORTED_MODULE_2__.getExecOutput("bash", ["-xc", cmd], { silent: true }); + return exec.getExecOutput("bash", ["-xc", cmd], { silent: true }); } async function run(earlyExit) { try { - const ccacheVariant = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getState("ccacheVariant"); - const primaryKey = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getState("primaryKey"); + const ccacheVariant = core.getState("ccacheVariant"); + const primaryKey = core.getState("primaryKey"); if (!ccacheVariant || !primaryKey) { - _actions_core__WEBPACK_IMPORTED_MODULE_0__.notice("ccache setup failed, skipping saving."); + core.notice("ccache setup failed, skipping saving."); return; } // Some versions of ccache do not support --verbose const ccacheKnowsVerbosityFlag = !!(await getExecBashOutput(`${ccacheVariant} --help`)).stdout.includes("--verbose"); - _actions_core__WEBPACK_IMPORTED_MODULE_0__.startGroup(`${ccacheVariant} stats`); - const verbosity = ccacheKnowsVerbosityFlag ? await getVerbosity(_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput("verbose")) : ''; - await _actions_exec__WEBPACK_IMPORTED_MODULE_2__.exec(`${ccacheVariant} -s${verbosity}`); - _actions_core__WEBPACK_IMPORTED_MODULE_0__.endGroup(); - if (_actions_core__WEBPACK_IMPORTED_MODULE_0__.getState("shouldSave") !== "true") { - _actions_core__WEBPACK_IMPORTED_MODULE_0__.info("Not saving cache because 'save' is set to 'false'."); + core.startGroup(`${ccacheVariant} stats`); + const verbosity = ccacheKnowsVerbosityFlag ? await getVerbosity(core.getInput("verbose")) : ''; + await exec.exec(`${ccacheVariant} -s${verbosity}`); + core.endGroup(); + if (core.getState("shouldSave") !== "true") { + core.info("Not saving cache because 'save' is set to 'false'."); return; } if (await ccacheIsEmpty(ccacheVariant, ccacheKnowsVerbosityFlag)) { - _actions_core__WEBPACK_IMPORTED_MODULE_0__.info("Not saving cache because no objects are cached."); + core.info("Not saving cache because no objects are cached."); } else { let saveKey = primaryKey; - if (_actions_core__WEBPACK_IMPORTED_MODULE_0__.getState("appendTimestamp") == "true") { + if (core.getState("appendTimestamp") == "true") { saveKey += new Date().toISOString(); } else { - _actions_core__WEBPACK_IMPORTED_MODULE_0__.debug("Not appending timestamp because 'append-timestamp' is not set to 'true'."); + core.debug("Not appending timestamp because 'append-timestamp' is not set to 'true'."); } - const paths = [`.${ccacheVariant}`]; - _actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Save cache using key "${saveKey}".`); - await _actions_cache__WEBPACK_IMPORTED_MODULE_1__.saveCache(paths, saveKey); + const paths = [cacheDir(ccacheVariant)]; + core.info(`Save cache using key "${saveKey}".`); + await cache.saveCache(paths, saveKey); } } catch (error) { // A failure to save cache shouldn't prevent the entire CI run from // failing, so do not call setFailed() here. - _actions_core__WEBPACK_IMPORTED_MODULE_0__.warning(`Saving cache failed: ${error}`); + core.warning(`Saving cache failed: ${error}`); } // Since we are not using http requests after this // we can safely exit early @@ -59631,7 +59653,7 @@ async function run(earlyExit) { } } run(true); -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (run); +/* harmony default export */ const save = (run); })(); diff --git a/src/common.ts b/src/common.ts new file mode 100644 index 00000000..63cfbe29 --- /dev/null +++ b/src/common.ts @@ -0,0 +1,11 @@ +import path from "path"; + +export function cacheDir(ccacheVariant: string): string { + const ghWorkSpace = process.env.GITHUB_WORKSPACE || "unreachable, make ncc happy"; + if (ccacheVariant === "ccache") { + return process.env.CCACHE_DIR || path.join(ghWorkSpace, ".ccache"); + } else if (ccacheVariant === "sccache") { + return process.env.SCCACHE_DIR || path.join(ghWorkSpace, ".sccache"); + } + throw Error("Unknown ccache variant: " + ccacheVariant); +} diff --git a/src/restore.ts b/src/restore.ts index 4f4f41a8..e196c8b4 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -7,6 +7,7 @@ import * as io from "@actions/io"; import * as exec from "@actions/exec"; import * as process from "process"; import * as cache from "@actions/cache"; +import { cacheDir } from "./common"; const SELF_CI = process.env["CCACHE_ACTION_CI"] === "true" @@ -22,8 +23,8 @@ async function restore(ccacheVariant : string) : Promise { const keyPrefix = ccacheVariant + "-"; const primaryKey = inputs.primaryKey ? keyPrefix + inputs.primaryKey + "-" : keyPrefix; const restoreKeys = inputs.restoreKeys.map(k => keyPrefix + k + "-") - const paths = [`.${ccacheVariant}`]; - + const paths = [cacheDir(ccacheVariant)]; + core.saveState("primaryKey", primaryKey); const shouldRestore = core.getBooleanInput("restore"); @@ -46,11 +47,10 @@ async function restore(ccacheVariant : string) : Promise { } async function configure(ccacheVariant : string, platform : string) : Promise { - const ghWorkSpace = process.env.GITHUB_WORKSPACE || "unreachable, make ncc happy"; const maxSize = core.getInput('max-size'); if (ccacheVariant === "ccache") { - await execBash(`ccache --set-config=cache_dir='${path.join(ghWorkSpace, '.ccache')}'`); + await execBash(`ccache --set-config=cache_dir='${cacheDir(ccacheVariant)}'`); await execBash(`ccache --set-config=max_size='${maxSize}'`); await execBash(`ccache --set-config=compression=true`); if (platform === "darwin") { @@ -70,7 +70,7 @@ async function configure(ccacheVariant : string, platform : string) : Promise { if (ccacheVariant === "ccache") { @@ -51,7 +52,7 @@ async function run(earlyExit : boolean | undefined) : Promise { const verbosity = ccacheKnowsVerbosityFlag ? await getVerbosity(core.getInput("verbose")) : ''; await exec.exec(`${ccacheVariant} -s${verbosity}`); core.endGroup(); - + if (core.getState("shouldSave") !== "true") { core.info("Not saving cache because 'save' is set to 'false'."); return; @@ -66,8 +67,9 @@ async function run(earlyExit : boolean | undefined) : Promise { } else { core.debug("Not appending timestamp because 'append-timestamp' is not set to 'true'."); } - const paths = [`.${ccacheVariant}`]; - + + const paths = [cacheDir(ccacheVariant)]; + core.info(`Save cache using key "${saveKey}".`); await cache.saveCache(paths, saveKey); }