diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b70e4f --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.vscode +node_modules/* +!node_modules/@actions +node_modules/@actions/**/README.md +node_modules/@actions/**/*.map +node_modules/@actions/**/*.d.ts diff --git a/index.js b/index.js index 6941df6..b7f524b 100644 --- a/index.js +++ b/index.js @@ -1,28 +1,22 @@ const https = require('https'); -const { existsSync } = require('fs'); const path = require('path'); +const { existsSync } = require('fs'); const { spawn } = require('child_process'); +const core = require('@actions/core'); // GitHub JavaScript Actions require we "must include any package dependencies // required to run the JavaScript code" - import node_modules in version control // or other weird things. // (https://help.github.com/en/articles/creating-a-javascript-action#commit-and-push-your-action-to-github). // To overcome that, we do `npm install` dynamically from within this script 🎉. -let core; // this will become lazily imported '@actions/core' main().catch(err => { console.error(err); - core && core.setFailed(err); + core.setFailed(err); process.exit(1); }); async function main() { - await install(['@actions/core']); - const actionsCore = require.resolve( - path.join(process.cwd(), 'node_modules/@actions/core') - ); - core = require(actionsCore); - await core.group('Install dependencies', installDependencies); await core.group('Validate spec', validate); await core.group('Publish to /TR/', publish); @@ -87,7 +81,7 @@ function shell(command, args = [], options = {}) { } async function install(dependencies) { - await shell('npm', ['install', '--quiet', ...dependencies]); + await shell('npm', ['install', '--silent', ...dependencies]); } function request(url, options) { diff --git a/node_modules/@actions/core/lib/command.js b/node_modules/@actions/core/lib/command.js new file mode 100644 index 0000000..b0ea009 --- /dev/null +++ b/node_modules/@actions/core/lib/command.js @@ -0,0 +1,66 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const os = require("os"); +/** + * Commands + * + * Command Format: + * ##[name key=value;key=value]message + * + * Examples: + * ##[warning]This is the user warning message + * ##[set-secret name=mypassword]definitelyNotAPassword! + */ +function issueCommand(command, properties, message) { + const cmd = new Command(command, properties, message); + process.stdout.write(cmd.toString() + os.EOL); +} +exports.issueCommand = issueCommand; +function issue(name, message = '') { + issueCommand(name, {}, message); +} +exports.issue = issue; +const CMD_STRING = '::'; +class Command { + constructor(command, properties, message) { + if (!command) { + command = 'missing.command'; + } + this.command = command; + this.properties = properties; + this.message = message; + } + toString() { + let cmdStr = CMD_STRING + this.command; + if (this.properties && Object.keys(this.properties).length > 0) { + cmdStr += ' '; + for (const key in this.properties) { + if (this.properties.hasOwnProperty(key)) { + const val = this.properties[key]; + if (val) { + // safely append the val - avoid blowing up when attempting to + // call .replace() if message is not a string for some reason + cmdStr += `${key}=${escape(`${val || ''}`)},`; + } + } + } + } + cmdStr += CMD_STRING; + // safely append the message - avoid blowing up when attempting to + // call .replace() if message is not a string for some reason + const message = `${this.message || ''}`; + cmdStr += escapeData(message); + return cmdStr; + } +} +function escapeData(s) { + return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A'); +} +function escape(s) { + return s + .replace(/\r/g, '%0D') + .replace(/\n/g, '%0A') + .replace(/]/g, '%5D') + .replace(/;/g, '%3B'); +} +//# sourceMappingURL=command.js.map \ No newline at end of file diff --git a/node_modules/@actions/core/lib/core.js b/node_modules/@actions/core/lib/core.js new file mode 100644 index 0000000..f43d507 --- /dev/null +++ b/node_modules/@actions/core/lib/core.js @@ -0,0 +1,195 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const command_1 = require("./command"); +const os = require("os"); +const path = require("path"); +/** + * The code to exit an action + */ +var ExitCode; +(function (ExitCode) { + /** + * A code indicating that the action was successful + */ + ExitCode[ExitCode["Success"] = 0] = "Success"; + /** + * A code indicating that the action was a failure + */ + ExitCode[ExitCode["Failure"] = 1] = "Failure"; +})(ExitCode = exports.ExitCode || (exports.ExitCode = {})); +//----------------------------------------------------------------------- +// Variables +//----------------------------------------------------------------------- +/** + * 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 + */ +function exportVariable(name, val) { + process.env[name] = val; + command_1.issueCommand('set-env', { name }, val); +} +exports.exportVariable = exportVariable; +/** + * Registers a secret which will get masked from logs + * @param secret value of the secret + */ +function setSecret(secret) { + command_1.issueCommand('add-mask', {}, secret); +} +exports.setSecret = setSecret; +/** + * Prepends inputPath to the PATH (for this action and future actions) + * @param inputPath + */ +function addPath(inputPath) { + command_1.issueCommand('add-path', {}, inputPath); + process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`; +} +exports.addPath = addPath; +/** + * Gets the value of an input. The value is also trimmed. + * + * @param name name of the input to get + * @param options optional. See InputOptions. + * @returns string + */ +function getInput(name, options) { + const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''; + if (options && options.required && !val) { + throw new Error(`Input required and not supplied: ${name}`); + } + return val.trim(); +} +exports.getInput = getInput; +/** + * Sets the value of an output. + * + * @param name name of the output to set + * @param value value to store + */ +function setOutput(name, value) { + command_1.issueCommand('set-output', { name }, value); +} +exports.setOutput = setOutput; +//----------------------------------------------------------------------- +// Results +//----------------------------------------------------------------------- +/** + * Sets the action status to failed. + * When the action exits it will be with an exit code of 1 + * @param message add error issue message + */ +function setFailed(message) { + process.exitCode = ExitCode.Failure; + error(message); +} +exports.setFailed = setFailed; +//----------------------------------------------------------------------- +// Logging Commands +//----------------------------------------------------------------------- +/** + * Writes debug message to user log + * @param message debug message + */ +function debug(message) { + command_1.issueCommand('debug', {}, message); +} +exports.debug = debug; +/** + * Adds an error issue + * @param message error issue message + */ +function error(message) { + command_1.issue('error', message); +} +exports.error = error; +/** + * Adds an warning issue + * @param message warning issue message + */ +function warning(message) { + command_1.issue('warning', message); +} +exports.warning = warning; +/** + * Writes info to log with console.log. + * @param message info message + */ +function info(message) { + process.stdout.write(message + os.EOL); +} +exports.info = info; +/** + * Begin an output group. + * + * Output until the next `groupEnd` will be foldable in this group + * + * @param name The name of the output group + */ +function startGroup(name) { + command_1.issue('group', name); +} +exports.startGroup = startGroup; +/** + * End an output group. + */ +function endGroup() { + command_1.issue('endgroup'); +} +exports.endGroup = endGroup; +/** + * Wrap an asynchronous function call in a group. + * + * Returns the same type as the function itself. + * + * @param name The name of the group + * @param fn The function to wrap in the group + */ +function group(name, fn) { + return __awaiter(this, void 0, void 0, function* () { + startGroup(name); + let result; + try { + result = yield fn(); + } + finally { + endGroup(); + } + return result; + }); +} +exports.group = group; +//----------------------------------------------------------------------- +// Wrapper action state +//----------------------------------------------------------------------- +/** + * 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 + */ +function saveState(name, value) { + command_1.issueCommand('save-state', { name }, value); +} +exports.saveState = saveState; +/** + * Gets the value of an state set by this action's main execution. + * + * @param name name of the state to get + * @returns string + */ +function getState(name) { + return process.env[`STATE_${name}`] || ''; +} +exports.getState = getState; +//# sourceMappingURL=core.js.map \ No newline at end of file diff --git a/node_modules/@actions/core/package.json b/node_modules/@actions/core/package.json new file mode 100644 index 0000000..a194d54 --- /dev/null +++ b/node_modules/@actions/core/package.json @@ -0,0 +1,65 @@ +{ + "_from": "@actions/core", + "_id": "@actions/core@1.2.0", + "_inBundle": false, + "_integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw==", + "_location": "/@actions/core", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "@actions/core", + "name": "@actions/core", + "escapedName": "@actions%2fcore", + "scope": "@actions", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz", + "_shasum": "aa5f52b26c362c821d41557e599371a42f6c0b3d", + "_spec": "@actions/core", + "_where": "/home/sid/work/sidvishnoi/respec-w3c-auto-publish", + "bugs": { + "url": "https://github.com/actions/toolkit/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Actions core lib", + "devDependencies": { + "@types/node": "^12.0.2" + }, + "directories": { + "lib": "lib", + "test": "__tests__" + }, + "files": [ + "lib" + ], + "homepage": "https://github.com/actions/toolkit/tree/master/packages/core", + "keywords": [ + "github", + "actions", + "core" + ], + "license": "MIT", + "main": "lib/core.js", + "name": "@actions/core", + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/actions/toolkit.git", + "directory": "packages/core" + }, + "scripts": { + "test": "echo \"Error: run tests from root\" && exit 1", + "tsc": "tsc" + }, + "version": "1.2.0" +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..b3ac544 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,11 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "@actions/core": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz", + "integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw==" + } + } +}