File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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'
Original file line number Diff line number Diff line change 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 ( )
Original file line number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments