25 Commits

Author SHA1 Message Date
Ross Brodbeck
4be183afbd Use main instead of master in the readme 2020-07-17 08:53:37 -04:00
Ross Brodbeck
53eafced66 run tests on main instead of master 2020-07-17 08:53:12 -04:00
Ross Brodbeck
82c9978d8c Bump checkout version 2020-07-17 08:51:46 -04:00
dependabot[bot]
02d8f06488 Bump @actions/core from 1.1.1 to 1.2.4 (#38)
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.1.1 to 1.2.4.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/master/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-07-17 08:50:21 -04:00
Ross Brodbeck
7e6d5ca343 Add basic dependabot config (#37) 2020-07-17 08:48:19 -04:00
dependabot[bot]
9c3d869495 Bump lodash from 4.17.15 to 4.17.19 (#35)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-07-17 08:41:17 -04:00
horo
ea496c8572 fix: setting process.env to child_pocess (#24) 2020-07-17 08:38:22 -04:00
Ross Brodbeck
16ddff4fe0 Fixes up issues with the template (#36)
* #27 remove console.log
* #16 change author to empty
* #30 maintain this repo 😄 
* #8 jest update for eslint
* update dependencies
* #22 generate source maps
* #21 use prepare instead of package
* add `npm run all` to run everything
2020-07-17 08:34:34 -04:00
Ross Brodbeck
89ae381fbe Merge pull request #23 from actions/dependabot/npm_and_yarn/acorn-5.7.4
Bump acorn from 5.7.3 to 5.7.4
2020-07-17 07:54:51 -04:00
dependabot[bot]
81c612ca57 Bump acorn from 5.7.3 to 5.7.4
Bumps [acorn](https://github.com/acornjs/acorn) from 5.7.3 to 5.7.4.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](https://github.com/acornjs/acorn/compare/5.7.3...5.7.4)

Signed-off-by: dependabot[bot] <support@github.com>
2020-04-06 10:29:23 +00:00
Bryan MacFarlane
5eabdae304 Merge pull request #15 from fregante/patch-1
Actually await the promise returned by wait.js
2020-02-17 20:42:16 -05:00
Federico Brigante
5fc9bf9e92 Actually await wait.js 2020-02-15 21:37:13 +08:00
Bryan MacFarlane
c4da6cbeb3 update readme badge 2019-12-07 10:51:29 -08:00
Bryan MacFarlane
33a61e5e78 Merge pull request #13 from actions/twojobs
split into two jobs for better testing
2019-12-07 10:49:22 -08:00
Bryan MacFarlane
07caa9db18 split into two jobs for better testing 2019-12-07 10:46:15 -08:00
Bryan MacFarlane
86347f385e update incorrect .gitignore comment 2019-11-15 09:36:34 -05:00
Bryan MacFarlane
5cd62f0ad8 readme tweak 2019-10-22 22:50:26 -04:00
Bryan MacFarlane
d080a47b66 Merge pull request #5 from actions/pkgaction
Package action and do not checkin node_modules in any branch
2019-10-22 22:26:04 -04:00
Bryan MacFarlane
e4a2aaba52 PR feedback 2019-10-22 22:13:09 -04:00
Bryan MacFarlane
1f8ff94664 PR feedback 2019-10-22 22:09:30 -04:00
Bryan MacFarlane
b2ef94412d pkg action 2019-10-22 21:51:21 -04:00
Bryan MacFarlane
a2b6fc15fd rename workflow 2019-09-26 20:30:18 -04:00
Bryan MacFarlane
81162dcb01 add badge 2019-09-26 20:20:41 -04:00
Bryan MacFarlane
7d08020091 remove comment 2019-09-23 00:28:12 -04:00
Bryan MacFarlane
6926e6e8e0 update gitignore 2019-09-22 08:45:19 -04:00
13 changed files with 6627 additions and 2380 deletions

View File

@@ -2,6 +2,7 @@
"env": {
"commonjs": true,
"es6": true,
"jest": true,
"node": true
},
"extends": "eslint:recommended",

9
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,9 @@
version: 2
updates:
# Enable version updates for npm
- package-ecosystem: "npm"
# Look for `package.json` and `lock` files in the `root` directory
directory: "/"
# Check the npm registry for updates every day (weekdays)
schedule:
interval: "daily"

View File

@@ -1,19 +1,25 @@
name: "Run JavaScript Action"
name: "units-test"
on:
pull_request:
push:
branches:
- master
- 'releases/*' # only run in release distribution branches
- main
- 'releases/*'
jobs:
# unit tests
units:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm ci
- run: npm test
# test action works running from the graph
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: npm ci
- run: npm test
- uses: actions/checkout@v2
- uses: ./
with:
milliseconds: 1000

4
.gitignore vendored
View File

@@ -1,6 +1,8 @@
# comment this out distribution branches
node_modules/
# Editors
.vscode
# Logs
logs
*.log

View File

@@ -1,3 +1,8 @@
<p align="center">
<a href="https://github.com/actions/javascript-action/actions"><img alt="javscript-action status" src="https://github.com/actions/javascript-action/workflows/units-test/badge.svg"></a>
</p>
# Create a JavaScript Action
Use this template to bootstrap the creation of a JavaScript action.:rocket:
@@ -10,7 +15,7 @@ If you are new, there's also a simpler introduction. See the [Hello World JavaS
Click the `Use this Template` and provide the new repo details for your action
## Code in Master
## Code in Main
Install the dependencies
```bash
@@ -59,50 +64,51 @@ run()
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
## Publish to a distribution branch
## Package for distribution
Actions are run from GitHub repos. We will create a releases branch and only checkin production modules (core in this case).
GitHub Actions will run the entry point from the action.yml. Packaging assembles the code into one file that can be checked in to Git, enabling fast and reliable execution and preventing the need to check in node_modules.
Actions are run from GitHub repos. Packaging the action will create a packaged action in the dist folder.
Run prepare
Comment out node_modules in .gitignore and create a releases/v1 branch
```bash
# comment this out distribution branches
# node_modules/
npm run prepare
```
Since the packaged index.js is run from the dist folder.
```bash
git add dist
```
## Create a release branch
Users shouldn't consume the action from master since that would be latest code and actions can break compatibility between major versions.
Checkin to the v1 release branch
```bash
$ git checkout -b v1
$ git commit -a -m "v1 release"
```
```bash
$ git checkout -b releases/v1
$ git commit -a -m "prod dependencies"
```
```bash
$ npm prune --production
$ git add node_modules
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
$ git push origin v1
```
Your action is now published! :rocket:
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
## Validate
## Usage
You can now validate the action by referencing the releases/v1 branch
```yaml
uses: actions/javascript-action@releases/v1
with:
milliseconds: 1000
```
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:
## Usage:
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and tested action
You can now consume the action by referencing the v1 branch
```yaml
uses: actions/javascript-action@v1
with:
milliseconds: 1000
```
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:

View File

@@ -10,4 +10,4 @@ outputs:
description: 'The message to output'
runs:
using: 'node12'
main: 'index.js'
main: 'dist/index.js'

371
dist/index.js vendored Normal file
View File

@@ -0,0 +1,371 @@
require('./sourcemap-register.js');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
/******/ var threw = true;
/******/ try {
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ threw = false;
/******/ } finally {
/******/ if(threw) delete installedModules[moduleId];
/******/ }
/******/
/******/ // 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');
core.info(`Waiting ${ms} milliseconds ...`)
core.debug((new Date()).toTimeString()) // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
await wait(parseInt(ms));
core.info((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;
/***/ })
/******/ });
//# sourceMappingURL=index.js.map

1
dist/index.js.map vendored Normal file

File diff suppressed because one or more lines are too long

3912
dist/sourcemap-register.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -6,11 +6,11 @@ const wait = require('./wait');
async function run() {
try {
const ms = core.getInput('milliseconds');
console.log(`Waiting ${ms} milliseconds ...`)
core.info(`Waiting ${ms} milliseconds ...`)
core.debug((new Date()).toTimeString())
wait(parseInt(ms));
core.debug((new Date()).toTimeString())
core.debug((new Date()).toTimeString()) // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
await wait(parseInt(ms));
core.info((new Date()).toTimeString())
core.setOutput('time', new Date().toTimeString());
}

View File

@@ -19,5 +19,5 @@ test('wait 500 ms', async() => {
test('test runs', () => {
process.env['INPUT_MILLISECONDS'] = 500;
const ip = path.join(__dirname, 'index.js');
console.log(cp.execSync(`node ${ip}`).toString());
console.log(cp.execSync(`node ${ip}`, { env: process.env }).toString());
})

4580
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,9 @@
"main": "index.js",
"scripts": {
"lint": "eslint index.js",
"test": "eslint index.js && jest"
"prepare": "ncc build index.js -o dist --source-map",
"test": "jest",
"all": "npm run lint && npm run prepare && npm run test"
},
"repository": {
"type": "git",
@@ -16,7 +18,7 @@
"Actions",
"JavaScript"
],
"author": "GitHub",
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/actions/javascript-action/issues"
@@ -26,7 +28,8 @@
"@actions/core": "^1.1.1"
},
"devDependencies": {
"eslint": "^6.3.0",
"jest": "^24.9.0"
"@zeit/ncc": "^0.22.3",
"eslint": "^7.4.0",
"jest": "^26.1.0"
}
}