Co-authored-by: Frieder Bluemle <frieder.bluemle@gmail.com>
This commit is contained in:
parent
b447b178e1
commit
c0941600fa
|
@ -0,0 +1 @@
|
||||||
|
dist/
|
|
@ -15,4 +15,4 @@
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,4 @@ updates:
|
||||||
directory: "/"
|
directory: "/"
|
||||||
# Check the npm registry for updates every day (weekdays)
|
# Check the npm registry for updates every day (weekdays)
|
||||||
schedule:
|
schedule:
|
||||||
interval: "daily"
|
interval: "daily"
|
||||||
|
|
|
@ -15,7 +15,7 @@ jobs:
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm test
|
- run: npm test
|
||||||
|
|
||||||
# test action works running from the graph
|
# test action works running from the graph
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
# Editors
|
# Editors
|
||||||
.vscode
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
|
|
26
README.md
26
README.md
|
@ -1,13 +1,12 @@
|
||||||
|
# Create a JavaScript Action
|
||||||
|
|
||||||
<p align="center">
|
<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>
|
<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>
|
</p>
|
||||||
|
|
||||||
# Create a JavaScript Action
|
|
||||||
|
|
||||||
Use this template to bootstrap the creation of a JavaScript action.:rocket:
|
Use this template to bootstrap the creation of a JavaScript action.:rocket:
|
||||||
|
|
||||||
This template includes tests, linting, a validation workflow, publishing, and versioning guidance.
|
This template includes tests, linting, a validation workflow, publishing, and versioning guidance.
|
||||||
|
|
||||||
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
|
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
|
||||||
|
|
||||||
|
@ -17,12 +16,14 @@ Click the `Use this Template` and provide the new repo details for your action
|
||||||
|
|
||||||
## Code in Main
|
## Code in Main
|
||||||
|
|
||||||
Install the dependencies
|
Install the dependencies
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
Run the tests :heavy_check_mark:
|
Run the tests :heavy_check_mark:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm test
|
$ npm test
|
||||||
|
|
||||||
|
@ -30,7 +31,6 @@ $ npm test
|
||||||
✓ throws invalid number (3ms)
|
✓ throws invalid number (3ms)
|
||||||
✓ wait 500 ms (504ms)
|
✓ wait 500 ms (504ms)
|
||||||
✓ test runs (95ms)
|
✓ test runs (95ms)
|
||||||
|
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -51,9 +51,9 @@ const core = require('@actions/core');
|
||||||
...
|
...
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
|
@ -89,15 +89,15 @@ Users shouldn't consume the action from master since that would be latest code a
|
||||||
Checkin to the v1 release branch
|
Checkin to the v1 release branch
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ git checkout -b v1
|
git checkout -b v1
|
||||||
$ git commit -a -m "v1 release"
|
git commit -a -m "v1 release"
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ git push origin v1
|
git push origin v1
|
||||||
```
|
```
|
||||||
|
|
||||||
Your action is now published! :rocket:
|
Your action is now published! :rocket:
|
||||||
|
|
||||||
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
|
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ inputs:
|
||||||
required: true
|
required: true
|
||||||
default: '1000'
|
default: '1000'
|
||||||
outputs:
|
outputs:
|
||||||
time: # output will be available to future steps
|
time: # output will be available to future steps
|
||||||
description: 'The message to output'
|
description: 'The message to output'
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
|
|
|
@ -65,22 +65,21 @@ const wait = __webpack_require__(949);
|
||||||
|
|
||||||
// most @actions toolkit packages have async methods
|
// most @actions toolkit packages have async methods
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const ms = core.getInput('milliseconds');
|
const ms = core.getInput('milliseconds');
|
||||||
core.info(`Waiting ${ms} 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
|
core.debug((new Date()).toTimeString()); // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
|
||||||
await wait(parseInt(ms));
|
await wait(parseInt(ms));
|
||||||
core.info((new Date()).toTimeString())
|
core.info((new Date()).toTimeString());
|
||||||
|
|
||||||
core.setOutput('time', new Date().toTimeString());
|
core.setOutput('time', new Date().toTimeString());
|
||||||
}
|
} catch (error) {
|
||||||
catch (error) {
|
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run();
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -352,15 +351,14 @@ module.exports = require("path");
|
||||||
/***/ 949:
|
/***/ 949:
|
||||||
/***/ (function(module) {
|
/***/ (function(module) {
|
||||||
|
|
||||||
let wait = function(milliseconds) {
|
let wait = function (milliseconds) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve) => {
|
||||||
if (typeof(milliseconds) !== 'number') {
|
if (typeof milliseconds !== 'number') {
|
||||||
throw new Error('milleseconds not a number');
|
throw new Error('milliseconds not a number');
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => resolve("done!"), milliseconds)
|
setTimeout(() => resolve("done!"), milliseconds)
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = wait;
|
module.exports = wait;
|
||||||
|
|
||||||
|
|
13
index.js
13
index.js
|
@ -4,19 +4,18 @@ const wait = require('./wait');
|
||||||
|
|
||||||
// most @actions toolkit packages have async methods
|
// most @actions toolkit packages have async methods
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const ms = core.getInput('milliseconds');
|
const ms = core.getInput('milliseconds');
|
||||||
core.info(`Waiting ${ms} 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
|
core.debug((new Date()).toTimeString()); // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
|
||||||
await wait(parseInt(ms));
|
await wait(parseInt(ms));
|
||||||
core.info((new Date()).toTimeString())
|
core.info((new Date()).toTimeString());
|
||||||
|
|
||||||
core.setOutput('time', new Date().toTimeString());
|
core.setOutput('time', new Date().toTimeString());
|
||||||
}
|
} catch (error) {
|
||||||
catch (error) {
|
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run();
|
||||||
|
|
|
@ -3,21 +3,21 @@ const process = require('process');
|
||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
test('throws invalid number', async() => {
|
test('throws invalid number', async () => {
|
||||||
await expect(wait('foo')).rejects.toThrow('milleseconds not a number');
|
await expect(wait('foo')).rejects.toThrow('milliseconds not a number');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('wait 500 ms', async() => {
|
test('wait 500 ms', async () => {
|
||||||
const start = new Date();
|
const start = new Date();
|
||||||
await wait(500);
|
await wait(500);
|
||||||
const end = new Date();
|
const end = new Date();
|
||||||
var delta = Math.abs(end - start);
|
var delta = Math.abs(end - start);
|
||||||
expect(delta).toBeGreaterThan(450);
|
expect(delta).toBeGreaterThan(450);
|
||||||
});
|
});
|
||||||
|
|
||||||
// shows how the runner will run a javascript action with env / stdout protocol
|
// shows how the runner will run a javascript action with env / stdout protocol
|
||||||
test('test runs', () => {
|
test('test runs', () => {
|
||||||
process.env['INPUT_MILLISECONDS'] = 500;
|
process.env['INPUT_MILLISECONDS'] = 500;
|
||||||
const ip = path.join(__dirname, 'index.js');
|
const ip = path.join(__dirname, 'index.js');
|
||||||
console.log(cp.execSync(`node ${ip}`, { env: process.env }).toString());
|
console.log(cp.execSync(`node ${ip}`, {env: process.env}).toString());
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"description": "JavaScript Action Template",
|
"description": "JavaScript Action Template",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint index.js",
|
"lint": "eslint .",
|
||||||
"prepare": "ncc build index.js -o dist --source-map",
|
"prepare": "ncc build index.js -o dist --source-map",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"all": "npm run lint && npm run prepare && npm run test"
|
"all": "npm run lint && npm run prepare && npm run test"
|
||||||
|
|
11
wait.js
11
wait.js
|
@ -1,11 +1,10 @@
|
||||||
let wait = function(milliseconds) {
|
let wait = function (milliseconds) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve) => {
|
||||||
if (typeof(milliseconds) !== 'number') {
|
if (typeof milliseconds !== 'number') {
|
||||||
throw new Error('milleseconds not a number');
|
throw new Error('milliseconds not a number');
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => resolve("done!"), milliseconds)
|
setTimeout(() => resolve("done!"), milliseconds)
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = wait;
|
module.exports = wait;
|
||||||
|
|
Loading…
Reference in New Issue