Skip to content

Commit

Permalink
workaround actions/toolkit#537
Browse files Browse the repository at this point in the history
  • Loading branch information
lukka committed Oct 7, 2020
1 parent b7da4c5 commit d3216f7
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 47 deletions.
190 changes: 149 additions & 41 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,31 @@ if (typeof Symbol === undefined || !Symbol.asyncIterator) {
/* 79 */,
/* 80 */,
/* 81 */,
/* 82 */,
/* 82 */
/***/ (function(__unusedmodule, exports) {

"use strict";

// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Sanitizes an input into a string so it can be passed into issueCommand safely
* @param input input to sanitize into a string
*/
function toCommandValue(input) {
if (input === null || input === undefined) {
return '';
}
else if (typeof input === 'string' || input instanceof String) {
return input;
}
return JSON.stringify(input);
}
exports.toCommandValue = toCommandValue;
//# sourceMappingURL=utils.js.map

/***/ }),
/* 83 */,
/* 84 */,
/* 85 */,
Expand Down Expand Up @@ -2309,11 +2333,13 @@ class ToolsGetter {
get(cmakeData, ninjaData) {
return __awaiter(this, void 0, void 0, function* () {
// Get an unique output directory name from the URL.
const key = hashCode(`${cmakeData.url}${ninjaData.url}`);
const inputHash = `${cmakeData.url}${ninjaData.url}`;
const key = hashCode(inputHash);
core.debug(`hash('${inputHash}') === '${key}'`);
const outPath = this.getOutputPath(key);
let hitKey;
let hitKey = undefined;
try {
core.startGroup(`Restore from cache`);
core.startGroup(`Restore from cache into ${outPath}`);
hitKey = yield cache.restoreCache([outPath], key);
}
finally {
Expand All @@ -2340,9 +2366,9 @@ class ToolsGetter {
core.endGroup();
}
try {
core.startGroup('Save to cache');
core.startGroup(`Save to cache into ${outPath}`);
if (hitKey === undefined) {
yield cache.saveCache([outPath], key);
yield this.saveCache([outPath], key);
}
else {
core.info("Skipping as cache hit.");
Expand All @@ -2359,6 +2385,24 @@ class ToolsGetter {
return path.join(process.env.RUNNER_TEMP, subDir);
;
}
saveCache(paths, key) {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield cache.saveCache(paths, key);
}
catch (error) {
if (error.name === cache.ValidationError.name) {
throw error;
}
else if (error.name === cache.ReserveCacheError.name) {
core.info(error.message);
}
else {
core.warning(error.message);
}
}
});
}
}
exports.ToolsGetter = ToolsGetter;
ToolsGetter.CMakeVersion = '3.18.3';
Expand Down Expand Up @@ -3515,31 +3559,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
/* 100 */,
/* 101 */,
/* 102 */
/***/ (function(__unusedmodule, exports) {
/***/ (function(__unusedmodule, exports, __webpack_require__) {

"use strict";

/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// For internal use, subject to change.
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports._globalThis = void 0;
/** only globals that common to node and browsers are allowed */
// eslint-disable-next-line node/no-unsupported-features/es-builtins
exports._globalThis = typeof globalThis === 'object' ? globalThis : global;
//# sourceMappingURL=globalThis.js.map
// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
const fs = __importStar(__webpack_require__(747));
const os = __importStar(__webpack_require__(365));
const utils_1 = __webpack_require__(82);
function issueCommand(command, message) {
const filePath = process.env[`GITHUB_${command}`];
if (!filePath) {
throw new Error(`Unable to find environment variable for file command ${command}`);
}
if (!fs.existsSync(filePath)) {
throw new Error(`Missing file at path: ${filePath}`);
}
fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
encoding: 'utf8'
});
}
exports.issueCommand = issueCommand;
//# sourceMappingURL=file-command.js.map

/***/ }),
/* 103 */,
Expand Down Expand Up @@ -4777,7 +4828,34 @@ var __createBinding;


/***/ }),
/* 145 */,
/* 145 */
/***/ (function(__unusedmodule, exports) {

"use strict";

/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports._globalThis = void 0;
/** only globals that common to node and browsers are allowed */
// eslint-disable-next-line node/no-unsupported-features/es-builtins
exports._globalThis = typeof globalThis === 'object' ? globalThis : global;
//# sourceMappingURL=globalThis.js.map

/***/ }),
/* 146 */,
/* 147 */
/***/ (function(__unusedmodule, exports) {
Expand Down Expand Up @@ -37296,6 +37374,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const os = __importStar(__webpack_require__(365));
const utils_1 = __webpack_require__(82);
/**
* Commands
*
Expand Down Expand Up @@ -37350,13 +37429,13 @@ class Command {
}
}
function escapeData(s) {
return (s || '')
return utils_1.toCommandValue(s)
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A');
}
function escapeProperty(s) {
return (s || '')
return utils_1.toCommandValue(s)
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A')
Expand Down Expand Up @@ -39636,6 +39715,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = __webpack_require__(431);
const file_command_1 = __webpack_require__(102);
const utils_1 = __webpack_require__(82);
const os = __importStar(__webpack_require__(365));
const path = __importStar(__webpack_require__(622));
/**
Expand All @@ -39658,11 +39739,21 @@ var ExitCode;
/**
* Sets env variable for this action and future actions in the job
* @param name the name of the variable to set
* @param val the value of the variable
* @param val the value of the variable. Non-string values will be converted to a string via JSON.stringify
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function exportVariable(name, val) {
process.env[name] = val;
command_1.issueCommand('set-env', { name }, val);
const convertedVal = utils_1.toCommandValue(val);
process.env[name] = convertedVal;
const filePath = process.env['GITHUB_ENV'] || '';
if (filePath) {
const delimiter = '_GitHubActionsFileCommandDelimeter_';
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
file_command_1.issueCommand('ENV', commandValue);
}
else {
command_1.issueCommand('set-env', { name }, convertedVal);
}
}
exports.exportVariable = exportVariable;
/**
Expand All @@ -39678,7 +39769,13 @@ exports.setSecret = setSecret;
* @param inputPath
*/
function addPath(inputPath) {
command_1.issueCommand('add-path', {}, inputPath);
const filePath = process.env['GITHUB_PATH'] || '';
if (filePath) {
file_command_1.issueCommand('PATH', inputPath);
}
else {
command_1.issueCommand('add-path', {}, inputPath);
}
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
}
exports.addPath = addPath;
Expand All @@ -39701,12 +39798,22 @@ exports.getInput = getInput;
* Sets the value of an output.
*
* @param name name of the output to set
* @param value value to store
* @param value value to store. Non-string values will be converted to a string via JSON.stringify
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setOutput(name, value) {
command_1.issueCommand('set-output', { name }, value);
}
exports.setOutput = setOutput;
/**
* Enables or disables the echoing of commands into stdout for the rest of the step.
* Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set.
*
*/
function setCommandEcho(enabled) {
command_1.issue('echo', enabled ? 'on' : 'off');
}
exports.setCommandEcho = setCommandEcho;
//-----------------------------------------------------------------------
// Results
//-----------------------------------------------------------------------
Expand Down Expand Up @@ -39740,18 +39847,18 @@ function debug(message) {
exports.debug = debug;
/**
* Adds an error issue
* @param message error issue message
* @param message error issue message. Errors will be converted to string via toString()
*/
function error(message) {
command_1.issue('error', message);
command_1.issue('error', message instanceof Error ? message.toString() : message);
}
exports.error = error;
/**
* Adds an warning issue
* @param message warning issue message
* @param message warning issue message. Errors will be converted to string via toString()
*/
function warning(message) {
command_1.issue('warning', message);
command_1.issue('warning', message instanceof Error ? message.toString() : message);
}
exports.warning = warning;
/**
Expand Down Expand Up @@ -39809,8 +39916,9 @@ exports.group = group;
* Saves state for current action, the state can only be retrieved by this action's post job execution.
*
* @param name name of the state to store
* @param value value to store
* @param value value to store. Non-string values will be converted to a string via JSON.stringify
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function saveState(name, value) {
command_1.issueCommand('save-state', { name }, value);
}
Expand Down Expand Up @@ -47193,7 +47301,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(__webpack_require__(102), exports);
__exportStar(__webpack_require__(145), exports);
//# sourceMappingURL=index.js.map

/***/ }),
Expand Down
30 changes: 24 additions & 6 deletions src/get-cmake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ export class ToolsGetter {

private async get(cmakeData: PackageInfo, ninjaData: PackageInfo): Promise<void> {
// Get an unique output directory name from the URL.
const key: string = hashCode(`${cmakeData.url}${ninjaData.url}`);
const inputHash = `${cmakeData.url}${ninjaData.url}`;
const key: string = hashCode(inputHash);
core.debug(`hash('${inputHash}') === '${key}'`);
const outPath = this.getOutputPath(key);
let hitKey: string | undefined;
let hitKey: string | undefined = undefined;
try {
core.startGroup(`Restore from cache`);
core.startGroup(`Restore from cache into ${outPath}`);
hitKey = await cache.restoreCache([outPath], key);
} finally {
core.endGroup();
Expand Down Expand Up @@ -122,9 +124,9 @@ export class ToolsGetter {
}

try {
core.startGroup('Save to cache');
core.startGroup(`Save to cache into ${outPath}`);
if (hitKey === undefined) {
await cache.saveCache([outPath], key);
await this.saveCache([outPath], key);
} else {
core.info("Skipping as cache hit.");
}
Expand All @@ -138,8 +140,24 @@ export class ToolsGetter {
throw new Error("Environment variable process.env.RUNNER_TEMP must be set, it is used as destination directory of the cache");
return path.join(process.env.RUNNER_TEMP, subDir);;
}

private async saveCache(paths: string[], key: string): Promise<number | undefined> {
try {
return await cache.saveCache(paths, key);
}
catch (error) {
if (error.name === cache.ValidationError.name) {
throw error;
} else if (error.name === cache.ReserveCacheError.name) {
core.info(error.message);
} else {
core.warning(error.message);
}
}
}
}


export async function main(): Promise<void> {
try {
const cmakeGetter: ToolsGetter = new ToolsGetter();
Expand All @@ -156,4 +174,4 @@ export async function main(): Promise<void> {
process.exitCode = -1000;

}
}
}

0 comments on commit d3216f7

Please sign in to comment.