-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
121 lines (98 loc) · 4.05 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const core = require('@actions/core');
const exec = require('@actions/exec');
const fs = require('fs');
const tmp = require('tmp');
const path = require('path');
const io = require('@actions/io');
const platform = process.platform;
async function run() {
try {
const osVersion = core.getInput('version');
const ovmVersion = core.getInput('ovm_version');
console.log('OS: ' + platform);
if (!(platform == 'win32' || platform == 'linux' || platform == 'darwin')) {
throw new Error('OS not support');
}
if (core.isDebug()) {
core.exportVariable('LOGOS_CONFIG', "logger.rootLogger=DEBUG");
}
let pathToOVM = 'ovm.exe';
if (platform == 'win32') {
pathToOVM = path.dirname(__dirname) + '/' + 'ovm.exe';
}
if (ovmVersion == 'latest') {
await exec.exec('curl -L https://github.com/oscript-library/ovm/releases/latest/download/ovm.exe --output ' + pathToOVM);
} else {
await exec.exec('curl -L https://github.com/oscript-library/ovm/releases/download/v'+ ovmVersion + '/ovm.exe --output ' + pathToOVM);
}
if (platform == 'win32') {
let pathToOVM = path.dirname(__dirname);
console.log("dir: " + pathToOVM);
core.addPath(pathToOVM);
}
if (platform == 'linux') {
var tmpFile = tmp.fileSync();
fs.writeFileSync(tmpFile.name, installLinux());
await exec.exec('bash ' + tmpFile.name);
fs.unlinkSync(tmpFile.name);
}
if (platform == 'darwin') {
var tmpFile = tmp.fileSync();
fs.writeFileSync(tmpFile.name, installMacOs());
await exec.exec('bash ' + tmpFile.name);
fs.unlinkSync(tmpFile.name);
}
await exec.exec('ovm install ' + osVersion);
await exec.exec('ovm use ' + osVersion);
let output = '';
const options = {};
options.listeners = {
stdout: (data) => {
if (data.toString().includes('ovm')) {
output += data.toString();
}
}
};
await exec.exec('ovm', ['which', 'current'], options);
let pathOscript = path.dirname(output);
core.addPath(pathOscript);
if (platform != 'win32') {
core.exportVariable('OSCRIPTBIN', pathOscript);
core.exportVariable('PATH', '$OSCRIPTBIN:' + process.env.PATH);
}
if (platform == 'linux') {
await exec.exec('curl -L https://github.com/oscript-library/opm/releases/download/v0.16.2/opm-0.16.2.ospx --output opm.ospx');
if (osVersion == '1.2.0') {
await exec.exec('mkdir tmp');
await exec.exec('unzip opm.ospx -d tmp');
await exec.exec('unzip -o ./tmp/content.zip -d /home/runner/.local/share/ovm/current/lib/opm');
}
await exec.exec('opm install -f opm.ospx');
}
} catch (error) {
core.setFailed(error.message);
}
}
function installLinux() {
var value = [];
value.push('#!/bin/bash');
value.push('sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF');
value.push('echo "deb http://download.mono-project.com/repo/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/mono-official.list');
value.push('sudo apt-get update');
value.push('sudo apt-get install mono-complete mono-devel');
value.push('sudo mv ovm.exe /usr/local/bin/');
let cmd = 'mono /usr/local/bin/ovm.exe "$@"';
value.push("echo '" + cmd + "' | sudo tee /usr/local/bin/ovm");
value.push('sudo chmod +x /usr/local/bin/ovm');
return value.join('\n');
}
function installMacOs() {
var value = [];
value.push('#!/bin/bash');
value.push('mv ovm.exe /usr/local/bin/');
let cmd = 'mono /usr/local/bin/ovm.exe "$@"';
value.push("echo '" + cmd + "' | tee /usr/local/bin/ovm");
value.push('sudo chmod +x /usr/local/bin/ovm');
return value.join('\n');
}
run()