Skip to content
This repository was archived by the owner on Jun 3, 2023. It is now read-only.

Commit 337a488

Browse files
author
Victor Navarro
committed
feat: install with npm fallback with bash
1 parent 4852f06 commit 337a488

File tree

3 files changed

+78
-13
lines changed

3 files changed

+78
-13
lines changed

dist/index.js

Lines changed: 36 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@ import * as core from '@actions/core';
22
import * as exec from '@actions/exec';
33
import 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+
529
const 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

3065
run()
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

Comments
 (0)