File tree Expand file tree Collapse file tree 4 files changed +626
-0
lines changed Expand file tree Collapse file tree 4 files changed +626
-0
lines changed Original file line number Diff line number Diff line change 1+ name : " API Timer"
2+ description : " Ensure your API endpoints respond within a certain timeframe."
3+ inputs :
4+ time-limit :
5+ description : " The amount of ms before the workflow fails."
6+ required : true;
7+ default : 750
8+ base :
9+ description : " The base URL of your requests."
10+ required : true
11+ default : " https://example.com"
12+ endpoints :
13+ description : " The endpoints to test the response time of."
14+ required : true
15+ default : [
16+ " /test"
17+ ]
18+
Original file line number Diff line number Diff line change 1+ const core = require ( '@actions/core' ) ;
2+ const github = require ( '@actions/github' ) ;
3+
4+ const fetch = ( ...args ) => import ( 'node-fetch' ) . then ( ( { default : fetch } ) => fetch ( ...args ) ) ;
5+
6+ ( async ( ) => {
7+ try {
8+ const timeLimit = core . getInput ( "time-limit" ) ;
9+ const base = core . getInput ( "base" ) ;
10+ const endpoints = core . getInput ( "endpoints" ) ;
11+
12+ for ( endpoint of endpoints ) {
13+ const time = Date . now ( ) ;
14+ await fetch ( `${ base } ${ endpoint } ` ) . then ( data => data . text ( ) ) ;
15+ const timeTaken = Date . now ( ) - time ;
16+ if ( timeTaken >= timeLimit ) {
17+ core . setFailed ( `The endpoint ${ endpoint } took ${ timeTaken } ms to respond when limit was set to ${ timeLimit } ms.` ) ;
18+ }
19+ }
20+ } catch ( err ) {
21+ core . setFailed ( err . message ) ;
22+ }
23+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments