mirror of
https://github.com/mshick/add-pr-comment.git
synced 2025-12-31 22:29:45 +11:00
initial commit
This commit is contained in:
commit
3d8df2a501
21 changed files with 6283 additions and 0 deletions
17
.eslintrc.json
Normal file
17
.eslintrc.json
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"commonjs": true,
|
||||||
|
"es6": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"globals": {
|
||||||
|
"Atomics": "readonly",
|
||||||
|
"SharedArrayBuffer": "readonly"
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2018
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
}
|
||||||
|
}
|
||||||
15
.github/workflows/test.yml
vendored
Normal file
15
.github/workflows/test.yml
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
name: "test-local"
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm test
|
||||||
|
- uses: ./
|
||||||
|
with:
|
||||||
|
msg: Hello!
|
||||||
65
.gitignore
vendored
Normal file
65
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Editors
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Other Dependency directories
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# next.js build output
|
||||||
|
.next
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2019 Michael Shick
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
1
README.md
Normal file
1
README.md
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# add-pr-comment
|
||||||
16
action.yml
Normal file
16
action.yml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
name: "Add PR Comment"
|
||||||
|
description: "Add a comment to a PR"
|
||||||
|
inputs:
|
||||||
|
msg:
|
||||||
|
description: "the message to print"
|
||||||
|
required: true
|
||||||
|
milliseconds: # id of input
|
||||||
|
description: "number of milliseconds to wait"
|
||||||
|
required: true
|
||||||
|
default: "1000"
|
||||||
|
outputs:
|
||||||
|
time: # output will be available to future steps
|
||||||
|
description: "The message to output"
|
||||||
|
runs:
|
||||||
|
using: "node12"
|
||||||
|
main: "dist/index.js"
|
||||||
11
add-pr-comment/.github/main.workflow
vendored
Normal file
11
add-pr-comment/.github/main.workflow
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
workflow "Run Add PR Comment" {
|
||||||
|
on = "pull_request"
|
||||||
|
resolves = ["AddPrCommentActions"]
|
||||||
|
}
|
||||||
|
|
||||||
|
action "AddPrCommentActions" {
|
||||||
|
uses = "./"
|
||||||
|
secrets = [
|
||||||
|
"GITHUB_TOKEN"
|
||||||
|
]
|
||||||
|
}
|
||||||
13
add-pr-comment/.github/workflows/pull-request.yml
vendored
Normal file
13
add-pr-comment/.github/workflows/pull-request.yml
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
on: pull_request
|
||||||
|
name: Run Add PR Comment
|
||||||
|
jobs:
|
||||||
|
add-pr-comment-actions:
|
||||||
|
name: Add PR Comment Actions
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
|
||||||
|
- name: Add PR Comment Actions
|
||||||
|
uses: ./
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
61
add-pr-comment/.gitignore
vendored
Normal file
61
add-pr-comment/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# next.js build output
|
||||||
|
.next
|
||||||
3
add-pr-comment/.prettierrc
Normal file
3
add-pr-comment/.prettierrc
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"semi": true
|
||||||
|
}
|
||||||
14
add-pr-comment/Dockerfile
Normal file
14
add-pr-comment/Dockerfile
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
FROM node:slim
|
||||||
|
|
||||||
|
LABEL "com.github.actions.name"="Add PR Comment"
|
||||||
|
LABEL "com.github.actions.description"="Add a comment to the PR triggering this action"
|
||||||
|
LABEL "com.github.actions.icon"="send"
|
||||||
|
LABEL "com.github.actions.color"="gray-dark"
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ENTRYPOINT ["node", "/entrypoint.js"]
|
||||||
21
add-pr-comment/LICENSE
Normal file
21
add-pr-comment/LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2019 Michael Shick
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
1
add-pr-comment/README.md
Normal file
1
add-pr-comment/README.md
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# Add PR Comment GitHub Action
|
||||||
85
add-pr-comment/entrypoint.js
Executable file
85
add-pr-comment/entrypoint.js
Executable file
|
|
@ -0,0 +1,85 @@
|
||||||
|
// entrypoint.js
|
||||||
|
const { Toolkit } = require("actions-toolkit");
|
||||||
|
const tools = new Toolkit();
|
||||||
|
const webPageTest = require("webpagetest");
|
||||||
|
const argv = tools.arguments;
|
||||||
|
|
||||||
|
const { event, payload, sha } = tools.context;
|
||||||
|
|
||||||
|
// check pre-requirements
|
||||||
|
if (!checkForMissingEnv) tools.exit.failure("Failed!");
|
||||||
|
|
||||||
|
// run the script
|
||||||
|
runAudit();
|
||||||
|
|
||||||
|
async function runAudit() {
|
||||||
|
try {
|
||||||
|
if (event === "push") {
|
||||||
|
tools.log("### Action triggered! ###");
|
||||||
|
|
||||||
|
// 1. An authenticated instance of `@octokit/rest`, a GitHub API SDK
|
||||||
|
const octokit = tools.github;
|
||||||
|
|
||||||
|
// initialize webPagetest
|
||||||
|
const wpt = new webPageTest(
|
||||||
|
process.env.WEBPAGETEST_SERVER_URL || "www.webpagetest.org",
|
||||||
|
process.env.WEBPAGETEST_API_KEY
|
||||||
|
);
|
||||||
|
|
||||||
|
// 2. run tests and save results
|
||||||
|
const webpagetestResults = await runWebPagetest(wpt);
|
||||||
|
|
||||||
|
// 3. convert results to markdown
|
||||||
|
const finalResultsAsMarkdown = convertToMarkdown(webpagetestResults);
|
||||||
|
|
||||||
|
// 4. print results to as commit comment
|
||||||
|
const { owner, repo } = {
|
||||||
|
...tools.context.repo,
|
||||||
|
ref: `${payload.ref}`
|
||||||
|
};
|
||||||
|
|
||||||
|
await octokit.repos.createCommitComment({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
sha,
|
||||||
|
body: finalResultsAsMarkdown
|
||||||
|
});
|
||||||
|
|
||||||
|
tools.exit.success("Succesfully run!");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
tools.log.error(`Something went wrong ${error}!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log warnings to the console for missing environment variables
|
||||||
|
*/
|
||||||
|
function checkForMissingEnv() {
|
||||||
|
const requiredEnvVars = [
|
||||||
|
"HOME",
|
||||||
|
"GITHUB_WORKFLOW",
|
||||||
|
"GITHUB_ACTION",
|
||||||
|
"GITHUB_ACTOR",
|
||||||
|
"GITHUB_REPOSITORY",
|
||||||
|
"GITHUB_EVENT_NAME",
|
||||||
|
"GITHUB_EVENT_PATH",
|
||||||
|
"GITHUB_WORKSPACE",
|
||||||
|
"GITHUB_SHA",
|
||||||
|
"GITHUB_REF",
|
||||||
|
"GITHUB_TOKEN"
|
||||||
|
];
|
||||||
|
|
||||||
|
const requiredButMissing = requiredEnvVars.filter(
|
||||||
|
key => !process.env.hasOwnProperty(key)
|
||||||
|
);
|
||||||
|
if (requiredButMissing.length > 0) {
|
||||||
|
// This isn't being run inside of a GitHub Action environment!
|
||||||
|
const list = requiredButMissing.map(key => `- ${key}`).join("\n");
|
||||||
|
const warning = `There are environment variables missing from this runtime.\n${list}`;
|
||||||
|
tools.log.warn(warning);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
27
add-pr-comment/package.json
Normal file
27
add-pr-comment/package.json
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"name": "add-pr-comment-action",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "github action which adds a comment to a PR",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/mshick/add-pr-comment.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"github",
|
||||||
|
"actions",
|
||||||
|
"pr"
|
||||||
|
],
|
||||||
|
"author": "Michael Shick <m@shick.us>",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/mshick/add-pr-comment/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/mshick/add-pr-comment#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"actions-toolkit": "^2.1.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
364
dist/index.js
vendored
Normal file
364
dist/index.js
vendored
Normal file
|
|
@ -0,0 +1,364 @@
|
||||||
|
module.exports =
|
||||||
|
/******/ (function(modules, runtime) { // webpackBootstrap
|
||||||
|
/******/ "use strict";
|
||||||
|
/******/ // The module cache
|
||||||
|
/******/ var installedModules = {};
|
||||||
|
/******/
|
||||||
|
/******/ // The require function
|
||||||
|
/******/ function __webpack_require__(moduleId) {
|
||||||
|
/******/
|
||||||
|
/******/ // Check if module is in cache
|
||||||
|
/******/ if(installedModules[moduleId]) {
|
||||||
|
/******/ return installedModules[moduleId].exports;
|
||||||
|
/******/ }
|
||||||
|
/******/ // Create a new module (and put it into the cache)
|
||||||
|
/******/ var module = installedModules[moduleId] = {
|
||||||
|
/******/ i: moduleId,
|
||||||
|
/******/ l: false,
|
||||||
|
/******/ exports: {}
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // Execute the module function
|
||||||
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||||
|
/******/
|
||||||
|
/******/ // Flag the module as loaded
|
||||||
|
/******/ module.l = true;
|
||||||
|
/******/
|
||||||
|
/******/ // Return the exports of the module
|
||||||
|
/******/ return module.exports;
|
||||||
|
/******/ }
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ __webpack_require__.ab = __dirname + "/";
|
||||||
|
/******/
|
||||||
|
/******/ // the startup function
|
||||||
|
/******/ function startup() {
|
||||||
|
/******/ // Load entry module and return exports
|
||||||
|
/******/ return __webpack_require__(104);
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // run startup
|
||||||
|
/******/ return startup();
|
||||||
|
/******/ })
|
||||||
|
/************************************************************************/
|
||||||
|
/******/ ({
|
||||||
|
|
||||||
|
/***/ 87:
|
||||||
|
/***/ (function(module) {
|
||||||
|
|
||||||
|
module.exports = require("os");
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 104:
|
||||||
|
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
|
||||||
|
|
||||||
|
const core = __webpack_require__(470);
|
||||||
|
const wait = __webpack_require__(949);
|
||||||
|
|
||||||
|
|
||||||
|
// most @actions toolkit packages have async methods
|
||||||
|
async function run() {
|
||||||
|
try {
|
||||||
|
const ms = core.getInput('milliseconds');
|
||||||
|
console.log(`Waiting ${ms} milliseconds ...`)
|
||||||
|
|
||||||
|
core.debug((new Date()).toTimeString())
|
||||||
|
wait(parseInt(ms));
|
||||||
|
core.debug((new Date()).toTimeString())
|
||||||
|
|
||||||
|
core.setOutput('time', new Date().toTimeString());
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.setFailed(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 431:
|
||||||
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const os = __webpack_require__(87);
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 470:
|
||||||
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
"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 = __webpack_require__(431);
|
||||||
|
const os = __webpack_require__(87);
|
||||||
|
const path = __webpack_require__(622);
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
/**
|
||||||
|
* exports the variable and registers a secret which will get masked from logs
|
||||||
|
* @param name the name of the variable to set
|
||||||
|
* @param val value of the secret
|
||||||
|
*/
|
||||||
|
function exportSecret(name, val) {
|
||||||
|
exportVariable(name, val);
|
||||||
|
// the runner will error with not implemented
|
||||||
|
// leaving the function but raising the error earlier
|
||||||
|
command_1.issueCommand('set-secret', {}, val);
|
||||||
|
throw new Error('Not implemented.');
|
||||||
|
}
|
||||||
|
exports.exportSecret = exportSecret;
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
//# sourceMappingURL=core.js.map
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 622:
|
||||||
|
/***/ (function(module) {
|
||||||
|
|
||||||
|
module.exports = require("path");
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 949:
|
||||||
|
/***/ (function(module) {
|
||||||
|
|
||||||
|
let wait = function(milliseconds) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (typeof(milliseconds) !== 'number') {
|
||||||
|
throw new Error('milleseconds not a number');
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => resolve("done!"), milliseconds)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = wait;
|
||||||
|
|
||||||
|
|
||||||
|
/***/ })
|
||||||
|
|
||||||
|
/******/ });
|
||||||
22
index.js
Normal file
22
index.js
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
const core = require('@actions/core');
|
||||||
|
const wait = require('./wait');
|
||||||
|
|
||||||
|
|
||||||
|
// most @actions toolkit packages have async methods
|
||||||
|
async function run() {
|
||||||
|
try {
|
||||||
|
const ms = core.getInput('milliseconds');
|
||||||
|
console.log(`Waiting ${ms} milliseconds ...`)
|
||||||
|
|
||||||
|
core.debug((new Date()).toTimeString())
|
||||||
|
wait(parseInt(ms));
|
||||||
|
core.debug((new Date()).toTimeString())
|
||||||
|
|
||||||
|
core.setOutput('time', new Date().toTimeString());
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.setFailed(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run()
|
||||||
23
index.test.js
Normal file
23
index.test.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
const wait = require('./wait');
|
||||||
|
const process = require('process');
|
||||||
|
const cp = require('child_process');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
test('throws invalid number', async() => {
|
||||||
|
await expect(wait('foo')).rejects.toThrow('milleseconds not a number');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('wait 500 ms', async() => {
|
||||||
|
const start = new Date();
|
||||||
|
await wait(500);
|
||||||
|
const end = new Date();
|
||||||
|
var delta = Math.abs(end - start);
|
||||||
|
expect(delta).toBeGreaterThan(450);
|
||||||
|
});
|
||||||
|
|
||||||
|
// shows how the runner will run a javascript action with env / stdout protocol
|
||||||
|
test('test runs', () => {
|
||||||
|
process.env['INPUT_MILLISECONDS'] = 500;
|
||||||
|
const ip = path.join(__dirname, 'index.js');
|
||||||
|
console.log(cp.execSync(`node ${ip}`).toString());
|
||||||
|
})
|
||||||
5458
package-lock.json
generated
Normal file
5458
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
34
package.json
Normal file
34
package.json
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"name": "add-pr-comment",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "JavaScript Action Template",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"lint": "eslint index.js",
|
||||||
|
"package": "ncc build index.js -o dist",
|
||||||
|
"test": "eslint index.js && jest"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/actions/javascript-action.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"GitHub",
|
||||||
|
"Actions",
|
||||||
|
"JavaScript"
|
||||||
|
],
|
||||||
|
"author": "GitHub",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/actions/javascript-action/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/actions/javascript-action#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "^1.1.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@zeit/ncc": "^0.20.5",
|
||||||
|
"eslint": "^6.3.0",
|
||||||
|
"jest": "^24.9.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
11
wait.js
Normal file
11
wait.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
let wait = function(milliseconds) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (typeof(milliseconds) !== 'number') {
|
||||||
|
throw new Error('milleseconds not a number');
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => resolve("done!"), milliseconds)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = wait;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue