-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.js
70 lines (64 loc) · 2.12 KB
/
install.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const { binWrapper } = require('./index.js');
function sanitizeURL(inputURL) {
const parsedURL = new URL(inputURL);
// Remove the username and password (authentication) if present
parsedURL.username = '';
parsedURL.password = '';
// Convert the sanitized URL back to a string
return parsedURL.toString();
}
// install.js is executed during the npm installation step.
// To re-use BinWrapper logic, and limit changes, we force BinWrapper to
// execute "saucectl --version".
// So we are 100% sure that the saucectl binary will be available for the next
// execution.
async function install() {
if (process.env.SAUCE_VM) {
if (!process.env.SAUCECTL_FORCE_INSTALL) {
console.info('Skipping the installation of saucectl on Sauce Cloud.');
return;
}
}
console.info('Fetching saucectl binary');
const bw = binWrapper(
process.env.SAUCECTL_INSTALL_BINARY,
process.env.SAUCECTL_INSTALL_BINARY_MIRROR,
);
if (!bw) {
return;
}
bw.run(['--version'])
.then(() => {
console.info('Installation succeeded');
process.exit(0);
})
.catch((e) => {
console.error(`Installation failed: ${e}`);
if (e.message.includes('AxiosError')) {
const binarySource = process.env.SAUCECTL_INSTALL_BINARY;
const binarySourceMirror = process.env.SAUCECTL_INSTALL_BINARY_MIRROR;
if (binarySource) {
console.error(
`Please check that you have access to the URL provided by the SAUCECTL_INSTALL_BINARY environment variable: ${sanitizeURL(
binarySource,
)}\n\n`,
);
} else if (binarySourceMirror) {
console.error(
`Please check that you have access to the URL provided by the SAUCECTL_INSTALL_BINARY_MIRROR environment variable: ${sanitizeURL(
binarySourceMirror,
)}\n\n`,
);
} else {
console.error(
`Please check that you have access to https://github.com/saucelabs/saucectl/releases\n\n`,
);
}
}
process.exit(1);
});
}
if (require.main === module) {
install();
}
module.exports = install;