-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (57 loc) · 2.19 KB
/
index.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
71
72
73
const core = require('@actions/core');
const https = require('https');
const fs = require('fs');
const temp = require('temp');
const StreamZip = require('node-stream-zip');
temp.track();
async function extractZipFile(zipFilePath, onZipExtracted) {
const extractDirectory = fs.mkdtempSync('LP');
console.info(`Extracting Linqpad to '${extractDirectory}'`);
const zipFile = new StreamZip.async({ file: zipFilePath });
zipFile.extract(null, extractDirectory).then(function onExtractionFinished() {
onZipExtracted(fs.realpathSync(extractDirectory));
}).catch(function onExtractionFailed(error) {
console.error('Failed to extract Linqpad ZIP file.');
core.setFailed(error);
});
}
function getVersionFragment() {
const versionToDownload = core.getInput('version');
if (versionToDownload === '6.x') {
return '6';
}
if (versionToDownload === '5.x') {
return '5-AnyCPU';
}
throw new Error('Invalid version specified, it must be either \'5.x\' or \'6.x\'.');
}
function downloadZipFile(onZipFileDownloaded) {
const stream = temp.createWriteStream();
const requestUrl = `https://linqpad.azureedge.net/public/LINQPad${getVersionFragment()}.zip`;
console.info(`Downloading Linqpad from '${requestUrl}'`);
const request = https.get(requestUrl, function writeFile(response) {
response.pipe(stream);
response.on('end', function onDownloadFinished() {
stream.close();
console.info('Finished downloading the Linqpad ZIP file');
onZipFileDownloaded(stream.path);
});
}).on('error', function onDownloadFailed(error) {
console.error('Failed to download Linqpad ZIP file.');
core.setFailed(error);
});
}
function downloadAndExtractZipFile(onZipExtracted) {
const zipFilePath = downloadZipFile(function onZipFileDownloaded(zipFilePath) {
extractZipFile(zipFilePath, onZipExtracted);
});
}
function addDirectoryToPath(directoryPath) {
console.info(`Adding '${directoryPath}' to PATH for use`);
core.addPath(directoryPath);
}
try {
downloadAndExtractZipFile(addDirectoryToPath);
} catch (error) {
core.setFailed(error.message);
}