11const { execSync, spawn } = require ( 'child_process' )
22const https = require ( 'https' )
3+ const path = require ( 'path' )
34const fs = require ( 'fs' )
45const os = require ( "os" )
56
67async function go ( ) {
78 process . stdout . write ( "installing tea…\n" )
89
910 const PREFIX = process . env [ 'INPUT_PREFIX' ] || `${ os . homedir ( ) } /opt`
11+ const TEA_DIR = ( ( ) => {
12+ let TEA_DIR = process . env [ 'INPUT_SRCROOT' ]
13+ if ( ! TEA_DIR ) return
14+ TEA_DIR = TEA_DIR . trim ( )
15+ if ( ! TEA_DIR ) return
16+ if ( ! TEA_DIR . startsWith ( "/" ) ) {
17+ // for security this must be an absolute path
18+ TEA_DIR = `${ process . cwd ( ) } /${ TEA_DIR } `
19+ }
20+ return path . normalize ( TEA_DIR )
21+ } ) ( )
1022
1123 // we build to /opt and special case this action so people new to
1224 // building aren’t immediatelyt flumoxed
@@ -59,13 +71,9 @@ async function go() {
5971 fs . appendFileSync ( GITHUB_PATH , `${ bindir } \n` , { encoding : 'utf8' } )
6072
6173 const teafile = `${ bindir } /tea`
62- const TEA_DIR = process . cwd ( )
6374
6475 const env = {
6576 TEA_DIR ,
66- // ^^ if there's no git then the checkout action uses the GitHub API
67- // to check out the repo. So there won’t be a `.git` directory and tea
68- // won’t find the SRCROOT
6977 ...process . env
7078 }
7179
@@ -85,9 +93,10 @@ async function go() {
8593 fs . appendFileSync ( GITHUB_ENV , `VERSION=${ version } \n` , { encoding : 'utf8' } )
8694 }
8795
88- process . stdout . write ( `::set-output name=srcroot::${ TEA_DIR } \n` )
89- fs . appendFileSync ( GITHUB_ENV , `TEA_DIR=${ TEA_DIR } \n` , { encoding : 'utf8' } )
90-
96+ if ( TEA_DIR ) {
97+ process . stdout . write ( `::set-output name=srcroot::${ TEA_DIR } \n` )
98+ fs . appendFileSync ( GITHUB_ENV , `TEA_DIR=${ TEA_DIR } \n` , { encoding : 'utf8' } )
99+ }
91100 } catch {
92101 // `tea -Eds` returns exit code 1 if no SRCROOT is found
93102 //TODO a flag so it returns 0 so we can not just swallow all errors lol
0 commit comments