-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.js
61 lines (55 loc) · 2.53 KB
/
lib.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
const core = require('@actions/core');
const { exec } = require('child_process');
const axios = require('axios');
module.exports = async function () {
try {
const inputVersion = core.getInput('version');
let latestVersion;
let selectedVersion;
core.debug(`🔍 looking for the latest DuckDB version.`);
const headers = {'Accept': 'application/vnd.github+json', 'X-GitHub-Api-Version': '2022-11-28'}
const res = await axios.get('https://api.github.com/repos/duckdb/duckdb/releases/latest', {headers: headers});
if (res.status != 200) {
core.error(`❌ Failed to get latest DuckDB version`);
core.setFailed(res.statusText);
} else {
core.debug(`✔️ Latest DuckDB version found is ${res.data.tag_name}.`);
latestVersion = res.data.tag_name;
}
if (inputVersion === 'latest') {
core.info(`📦 DuckDb latest version requested : ${latestVersion} will be installed.`);
selectedVersion = latestVersion;
}
else {
selectedVersion = inputVersion;
core.info(`📦 DuckDb ${inputVersion} requested.`);
if (inputVersion != latestVersion)
core.warning(`🆕 DuckDb ${latestVersion} is available.`);
}
const regex = '^v[0-9]*.[0-9]*.[0-9]*$';
if(!selectedVersion.match(regex)) {
core.error("Version not valid.");
throw "Version not valid.";
}
core.info(`📥 Installing DuckDB version : ${selectedVersion}`);
const url = `https://github.com/duckdb/duckdb/releases/download/${selectedVersion}/duckdb_cli-linux-amd64.zip`
const wgetCmd = `wget ${url}`
const unzipCmd = `unzip duckdb_cli-linux-amd64.zip`
const installCmd = 'mkdir /opt/duckdb && mv duckdb /opt/duckdb && chmod +x /opt/duckdb/duckdb && sudo ln -s /opt/duckdb/duckdb /usr/bin/duckdb'
const checkVersionCmd = 'duckdb --version'
const cleanupCmd = 'rm duckdb_cli-linux-amd64.zip'
exec(`${wgetCmd} && ${unzipCmd} && ${installCmd} && ${cleanupCmd} && ${checkVersionCmd}`, (error, stdout, stderr) => {
if (error) {
core.error(`❌ ${error.message}`);
core.setFailed(error.message);
return;
}
if (stderr) {
core.debug(stderr);
}
core.info(`🚀 DuckDB ${selectedVersion} successfully installed.`);
});
} catch (error) {
core.setFailed(error.message);
}
}