@@ -2,6 +2,30 @@ import * as core from '@actions/core';
22import * as exec from '@actions/exec' ;
33import commandExists from 'command-exists' ;
44
5+ const installWithBash = async ( ) => {
6+ let output = '' ;
7+ let error = '' ;
8+
9+ const options = {
10+ listeners : {
11+ stdout : ( data : Buffer ) => {
12+ output += data . toString ( ) ;
13+ } ,
14+ stderr : ( data : Buffer ) => {
15+ error += data . toString ( ) ;
16+ } ,
17+ } ,
18+ } ;
19+
20+ await exec . exec ( 'curl' , [ '-sL' , 'https://firebase.tools' ] , options ) ;
21+
22+ if ( error ) {
23+ throw new Error ( error ) ;
24+ }
25+
26+ await exec . exec ( 'bash' , [ output ] ) ;
27+ } ;
28+
529const run = async ( ) => {
630 core . info (
731 ` Available environment variables:\n -> ${ Object . keys ( process . env )
@@ -18,15 +42,26 @@ const run = async () => {
1842 }
1943
2044 core . exportVariable ( 'FIREBASE_TOKEN' , token ) ;
45+ core . info ( 'Exported environment variable FIREBASE_TOKEN' ) ;
46+
2147 if ( await commandExists ( 'npm' ) ) {
22- await exec . exec ( 'npm' , [ 'install' , '-g' , 'firebase-tools' ] ) ;
23- } else if ( os === 'Linux' ) {
24- await exec . exec ( 'curl' , [ '-sL' , 'https://firebase.tools' , '|' , 'bash' ] ) ;
25- } else {
26- throw new Error ( 'On windows you need to setup node before' ) ;
48+ core . info ( 'Detected NPM installation' ) ;
49+ try {
50+ core . info ( 'Trying to install firebase-tools using NPM' ) ;
51+ await exec . exec ( 'npm' , [ 'install' , '-g' , 'firebase-tools' ] ) ;
52+ } catch ( e ) {
53+ core . info ( 'Installation failed through NPM (maybe you forgot actions/setup-node before this action)' ) ;
54+ core . info ( 'Trying BASH instead' ) ;
55+ await installWithBash ( ) ;
56+ }
57+ } else if ( os === 'Linux' || os === 'macOS' ) {
58+ core . info ( 'Trying to install firebase-tools using BASH' ) ;
59+ await installWithBash ( ) ;
60+ } else if ( os === 'Windows' ) {
61+ throw new Error ( 'On windows you must setup node before running this action' ) ;
2762 }
2863} ;
2964
3065run ( )
31- . then ( ( ) => core . info ( 'Updated files version successfully ' ) )
66+ . then ( ( ) => core . info ( 'Successfully installed firebase-tools CLI ' ) )
3267 . catch ( error => core . setFailed ( error . message ) ) ;
0 commit comments