starting...

This commit is contained in:
Bryan MacFarlane 2019-09-11 01:44:28 -04:00
parent 331b42dfcc
commit 198d21cc29
7 changed files with 4936 additions and 0 deletions

14
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,14 @@
name: "Run JavaScript Action"
on: [pull_request, push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: npm ci
- run: npm test
- uses: .
with:
milliseconds: 1000

13
actions.yml Normal file
View File

@ -0,0 +1,13 @@
name: 'Wait'
description: 'Wait a designated number of milliseconds'
inputs:
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: 'index.js'

20
index.js Normal file
View File

@ -0,0 +1,20 @@
const core = require('@actions/core');
const wait = require('./wait');
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
View 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());
})

4825
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

30
package.json Normal file
View File

@ -0,0 +1,30 @@
{
"name": "javascript-action",
"version": "1.0.0",
"description": "JavaScript Action Template",
"main": "index.js",
"scripts": {
"test": "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.0"
},
"devDependencies": {
"jest": "^24.9.0"
}
}

11
wait.js Normal file
View 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;