Skip to content

Commit 198d21c

Browse files
starting...
1 parent 331b42d commit 198d21c

7 files changed

Lines changed: 4936 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: "Run JavaScript Action"
2+
on: [pull_request, push]
3+
4+
jobs:
5+
test:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v1
9+
10+
- run: npm ci
11+
- run: npm test
12+
- uses: .
13+
with:
14+
milliseconds: 1000

actions.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'Wait'
2+
description: 'Wait a designated number of milliseconds'
3+
inputs:
4+
milliseconds: # id of input
5+
description: 'number of milliseconds to wait'
6+
required: true
7+
default: '1000'
8+
outputs:
9+
time: # output will be available to future steps
10+
description: 'The message to output'
11+
runs:
12+
using: 'node12'
13+
main: 'index.js'

index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const core = require('@actions/core');
2+
const wait = require('./wait');
3+
4+
async function run() {
5+
try {
6+
const ms = core.getInput('milliseconds');
7+
console.log(`Waiting ${ms} milliseconds ...`)
8+
9+
core.debug((new Date()).toTimeString())
10+
wait(parseInt(ms));
11+
core.debug((new Date()).toTimeString())
12+
13+
core.setOutput('time', new Date().toTimeString());
14+
}
15+
catch (error) {
16+
core.setFailed(error.message);
17+
}
18+
}
19+
20+
run()

index.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const wait = require('./wait');
2+
const process = require('process');
3+
const cp = require('child_process');
4+
const path = require('path');
5+
6+
test('throws invalid number', async() => {
7+
await expect(wait('foo')).rejects.toThrow('milleseconds not a number');
8+
});
9+
10+
test('wait 500 ms', async() => {
11+
const start = new Date();
12+
await wait(500);
13+
const end = new Date();
14+
var delta = Math.abs(end - start);
15+
expect(delta).toBeGreaterThan(450);
16+
});
17+
18+
// shows how the runner will run a javascript action with env / stdout protocol
19+
test('test runs', () => {
20+
process.env['INPUT_MILLISECONDS'] = 500;
21+
const ip = path.join(__dirname, 'index.js');
22+
console.log(cp.execSync(`node ${ip}`).toString());
23+
})

0 commit comments

Comments
 (0)