66 * @requires module:"@octokit/app"
77 * @requires module:"@octokit/request"
88 * @requires module:express
9+ * @requires module:localtunnel
910 * @requires module:github-webhook-handler
1011 */
1112const fs = require ( 'fs' ) ;
@@ -16,18 +17,22 @@ const queue = new (require('./queue.js'))()
1617const Coverage = require ( './coverage' ) ;
1718const { App } = require ( '@octokit/app' ) ;
1819const { request } = require ( "@octokit/request" ) ;
20+ const localtunnel = require ( 'localtunnel' ) ;
1921
2022const id = process . env . GITHUB_APP_IDENTIFIER ;
2123const secret = process . env . GITHUB_WEBHOOK_SECRET ;
2224
23- // Configure ssh tunnel
24- const cmd = 'ssh -tt -R gladius:80:localhost:3000 serveo.net' ;
25- const sh = String ( cp . execFileSync ( 'where' , [ 'git' ] ) ) . replace ( / c m d \\ g i t .e x e \s * / gi, 'bin\\sh.exe' ) ;
26- const tunnel = ( ) => {
27- let ssh = cp . spawn ( sh , [ '-c' , cmd ] )
28- ssh . stdout . on ( 'data' , ( data ) => { console . log ( `stdout: ${ data } ` ) ; } ) ;
29- ssh . on ( 'exit' , ( ) => { console . log ( 'Reconnecting to Serveo' ) ; tunnel ( ) ; } ) ;
30- ssh . on ( 'error' , ( e ) => { console . error ( e ) } ) ;
25+ // Configure a secure tunnel
26+ const openTunnel = async ( ) => {
27+ let args = {
28+ port : 3000 ,
29+ subdomain : process . env . TUNNEL_SUBDOMAIN ,
30+ host : process . env . TUNNEL_HOST
31+ } ;
32+ const tunnel = await localtunnel ( args ) ;
33+ console . log ( `Tunnel open on: ${ tunnel . url } ` ) ;
34+ tunnel . on ( 'close' , ( ) => { console . log ( 'Reconnecting' ) ; openTunnel ( ) ; } ) ;
35+ tunnel . on ( 'error' , ( e ) => { console . error ( e ) } ) ;
3136}
3237
3338// Create handler to verify posts signed with webhook secret. Content type must be application/json
@@ -288,9 +293,9 @@ queue.process(async (job, done) => {
288293 const timer = setTimeout ( function ( ) {
289294 console . log ( 'Max test time exceeded' )
290295 job . data [ 'status' ] = 'error' ;
291- job . data [ 'context' ] = 'Tests stalled after ~2 min' ;
296+ job . data [ 'context' ] = 'Tests stalled after ~8 min' ;
292297 runTests . kill ( ) ;
293- done ( new Error ( 'Job stalled' ) ) } , 5 * 60000 ) ;
298+ done ( new Error ( 'Job stalled' ) ) } , 8 * 60000 ) ;
294299 let args = [ '-r' , `runAllTests (""${ job . data . sha } "",""${ job . data . repo } "")` ,
295300 '-wait' , '-log' , '-nosplash' , '-logfile' , `.\\src\\matlab_tests-${ job . data . sha } .log` ] ;
296301 runTests = cp . execFile ( 'matlab' , args , ( error , stdout , stderr ) => {
@@ -467,8 +472,9 @@ var server = srv.listen(3000, function () {
467472
468473 console . log ( "Handler listening at http://%s:%s" , host , port )
469474} ) ;
475+
470476// Start tunnel
471- tunnel ( ) ;
477+ openTunnel ( ) ;
472478
473479// Log any unhandled errors
474480process . on ( 'unhandledRejection' , ( reason , p ) => {
0 commit comments