Skip to content

Commit a242340

Browse files
committed
Поддержка lunix + macos. Так же полечен opm для версии 1.2.0 на linux
1 parent 4757a1f commit a242340

2 files changed

Lines changed: 174 additions & 92 deletions

File tree

dist/index.js

Lines changed: 87 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,72 +1967,113 @@ const core = __webpack_require__(470);
19671967
const exec = __webpack_require__(986);
19681968
const fs = __webpack_require__(747);
19691969
const tmp = __webpack_require__(150);
1970+
const path = __webpack_require__(622);
1971+
const io = __webpack_require__(1);
19701972

1971-
const patform = process.platform;
1973+
const platform = process.platform;
19721974

19731975
async function run() {
19741976
try {
1977+
19751978
const osVersion = core.getInput('version');
1976-
var osVersionStr = getVersionString(osVersion);
1977-
console.log('Версия: ' + osVersionStr);
1978-
console.log('Платформа: ' + patform)
1979-
if (patform == 'win32') {
1980-
console.log('Загрузка');
1981-
await exec.exec('curl -v https://oscript.io/downloads/' + osVersionStr + '/exe?bitness=x64 --output oscript.exe');
1982-
console.log('Установка');
1983-
await exec.exec('./oscript.exe /verysilent /norestart /log=oscript.log');
1984-
1985-
console.log('Лог установки');
1986-
await exec.exec('powershell Get-Content -Path oscript.log');
1987-
console.log('Обновление Path');
1988-
updatePath();
1989-
1990-
console.log('Удаление временного файла');
1991-
fs.unlinkSync('./oscript.exe');
1992-
1993-
} else if (patform == 'linux') {
1979+
1980+
console.log('OS: ' + platform);
1981+
1982+
if (!(platform == 'win32' || platform == 'linux' || platform == 'darwin')) {
1983+
throw new Error('OS not support');
1984+
}
1985+
1986+
if (core.isDebug()) {
1987+
core.exportVariable('LOGOS_CONFIG', "logger.rootLogger=DEBUG");
1988+
}
1989+
1990+
let pathToOVM = 'ovm.exe';
1991+
if (platform == 'win32') {
1992+
pathToOVM = path.dirname(__dirname) + '/' + 'ovm.exe';
1993+
}
1994+
await exec.exec('curl -L https://github.com/oscript-library/ovm/releases/download/v1.0.0-RC15/ovm.exe --output ' + pathToOVM);
1995+
1996+
if (platform == 'win32') {
1997+
let pathToOVM = path.dirname(__dirname);
1998+
console.log("dir: " + pathToOVM);
1999+
core.addPath(pathToOVM);
2000+
}
2001+
2002+
if (platform == 'linux') {
2003+
19942004
var tmpFile = tmp.fileSync();
1995-
fs.writeFileSync(tmpFile.name, installLinux(osVersionStr, 'x64'));
2005+
fs.writeFileSync(tmpFile.name, installLinux());
2006+
await exec.exec('bash ' + tmpFile.name);
2007+
fs.unlinkSync(tmpFile.name);
2008+
2009+
}
19962010

2011+
if (platform == 'darwin') {
2012+
var tmpFile = tmp.fileSync();
2013+
fs.writeFileSync(tmpFile.name, installMacOs());
19972014
await exec.exec('bash ' + tmpFile.name);
19982015
fs.unlinkSync(tmpFile.name);
1999-
await exec.exec('curl -v https://hub.oscript.io/download/opm/opm.ospx --output opm.ospx');
2000-
await exec.exec('sudo opm install -f opm.ospx');
2001-
fs.unlinkSync('opm.ospx');
2002-
2003-
await exec.exec('oscript --version');
2016+
}
2017+
2018+
await exec.exec('ovm install ' + osVersion);
2019+
await exec.exec('ovm use ' + osVersion);
2020+
2021+
let output = '';
2022+
const options = {};
2023+
options.listeners = {
2024+
stdout: (data) => {
2025+
output += data.toString();
2026+
}
2027+
};
2028+
await exec.exec('ovm', ['which', 'current'], options);
2029+
let pathOscript = path.dirname(output);
2030+
2031+
core.addPath(pathOscript);
2032+
2033+
if (platform != 'win32') {
2034+
core.exportVariable('OSCRIPTBIN', pathOscript);
2035+
core.exportVariable('PATH', '$OSCRIPTBIN:' + process.env.PATH);
2036+
}
20042037

2005-
} else {
2006-
throw new Error('OS not support');
2038+
if (platform == 'linux') {
2039+
await exec.exec('curl -L https://github.com/oscript-library/opm/releases/download/v0.16.2/opm-0.16.2.ospx --output opm.ospx');
2040+
if (osVersion == '1.2.0') {
2041+
await exec.exec('mkdir tmp');
2042+
await exec.exec('unzip opm.ospx -d tmp');
2043+
await exec.exec('unzip -o ./tmp/content.zip -d /home/runner/.local/share/ovm/current/lib/opm');
2044+
}
2045+
await exec.exec('opm install -f opm.ospx');
20072046
}
20082047
}
20092048
catch (error) {
20102049
core.setFailed(error.message);
20112050
}
20122051
}
20132052

2014-
function getVersionString(value) {
2015-
var version = value.split('.').join('_');
2016-
return version;
2017-
}
2053+
function installLinux() {
2054+
var value = [];
2055+
value.push('#!/bin/bash');
2056+
value.push('sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF');
2057+
value.push('echo "deb http://download.mono-project.com/repo/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/mono-official.list');
2058+
value.push('sudo apt-get update');
2059+
value.push('sudo apt-get install mono-complete mono-devel');
2060+
value.push('sudo mv ovm.exe /usr/local/bin/');
2061+
2062+
let cmd = 'mono /usr/local/bin/ovm.exe "$@"';
2063+
value.push("echo '" + cmd + "' | sudo tee /usr/local/bin/ovm");
20182064

2019-
function updatePath() {
2020-
const OLD_PATH = process.env.PATH;
2021-
PATH = OLD_PATH + ";C:\/Program Files\/OneScript\/bin;";
2022-
core.exportVariable('Path', PATH);
2065+
value.push('sudo chmod +x /usr/local/bin/ovm');
2066+
return value.join('\n');
20232067
}
20242068

2025-
function installLinux(version, bitness) {
2026-
var value = [];
2027-
value.push('#!/bin/bash');
2028-
value.push('sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF');
2029-
value.push('echo "deb http://download.mono-project.com/repo/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/mono-official.list');
2030-
value.push('sudo apt-get update');
2031-
value.push('sudo apt-get install mono-complete mono-devel');
2032-
value.push('curl -v https://oscript.io/downloads/' + version + '/deb?bitness=' + bitness + ' --output os.deb');
2033-
value.push('sudo dpkg -i os.deb');
2034-
value.push('sudo apt install -f');
2035-
return value.join('\n');
2069+
function installMacOs() {
2070+
var value = [];
2071+
value.push('#!/bin/bash');
2072+
value.push('mv ovm.exe /usr/local/bin/');
2073+
let cmd = 'mono /usr/local/bin/ovm.exe "$@"';
2074+
value.push("echo '" + cmd + "' | tee /usr/local/bin/ovm");
2075+
value.push('sudo chmod +x /usr/local/bin/ovm');
2076+
return value.join('\n');
20362077
}
20372078

20382079
run()

index.js

Lines changed: 87 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,113 @@ const core = require('@actions/core');
22
const exec = require('@actions/exec');
33
const fs = require('fs');
44
const tmp = require('tmp');
5+
const path = require('path');
6+
const io = require('@actions/io');
57

6-
const patform = process.platform;
8+
const platform = process.platform;
79

810
async function run() {
911
try {
12+
1013
const osVersion = core.getInput('version');
11-
var osVersionStr = getVersionString(osVersion);
12-
console.log('Версия: ' + osVersionStr);
13-
console.log('Платформа: ' + patform)
14-
if (patform == 'win32') {
15-
console.log('Загрузка');
16-
await exec.exec('curl -v https://oscript.io/downloads/' + osVersionStr + '/exe?bitness=x64 --output oscript.exe');
17-
console.log('Установка');
18-
await exec.exec('./oscript.exe /verysilent /norestart /log=oscript.log');
19-
20-
console.log('Лог установки');
21-
await exec.exec('powershell Get-Content -Path oscript.log');
22-
console.log('Обновление Path');
23-
updatePath();
24-
25-
console.log('Удаление временного файла');
26-
fs.unlinkSync('./oscript.exe');
27-
28-
} else if (patform == 'linux') {
14+
15+
console.log('OS: ' + platform);
16+
17+
if (!(platform == 'win32' || platform == 'linux' || platform == 'darwin')) {
18+
throw new Error('OS not support');
19+
}
20+
21+
if (core.isDebug()) {
22+
core.exportVariable('LOGOS_CONFIG', "logger.rootLogger=DEBUG");
23+
}
24+
25+
let pathToOVM = 'ovm.exe';
26+
if (platform == 'win32') {
27+
pathToOVM = path.dirname(__dirname) + '/' + 'ovm.exe';
28+
}
29+
await exec.exec('curl -L https://github.com/oscript-library/ovm/releases/download/v1.0.0-RC15/ovm.exe --output ' + pathToOVM);
30+
31+
if (platform == 'win32') {
32+
let pathToOVM = path.dirname(__dirname);
33+
console.log("dir: " + pathToOVM);
34+
core.addPath(pathToOVM);
35+
}
36+
37+
if (platform == 'linux') {
38+
2939
var tmpFile = tmp.fileSync();
30-
fs.writeFileSync(tmpFile.name, installLinux(osVersionStr, 'x64'));
40+
fs.writeFileSync(tmpFile.name, installLinux());
41+
await exec.exec('bash ' + tmpFile.name);
42+
fs.unlinkSync(tmpFile.name);
43+
44+
}
3145

46+
if (platform == 'darwin') {
47+
var tmpFile = tmp.fileSync();
48+
fs.writeFileSync(tmpFile.name, installMacOs());
3249
await exec.exec('bash ' + tmpFile.name);
3350
fs.unlinkSync(tmpFile.name);
34-
await exec.exec('curl -v https://hub.oscript.io/download/opm/opm.ospx --output opm.ospx');
35-
await exec.exec('sudo opm install -f opm.ospx');
36-
fs.unlinkSync('opm.ospx');
37-
38-
await exec.exec('oscript --version');
51+
}
52+
53+
await exec.exec('ovm install ' + osVersion);
54+
await exec.exec('ovm use ' + osVersion);
55+
56+
let output = '';
57+
const options = {};
58+
options.listeners = {
59+
stdout: (data) => {
60+
output += data.toString();
61+
}
62+
};
63+
await exec.exec('ovm', ['which', 'current'], options);
64+
let pathOscript = path.dirname(output);
65+
66+
core.addPath(pathOscript);
67+
68+
if (platform != 'win32') {
69+
core.exportVariable('OSCRIPTBIN', pathOscript);
70+
core.exportVariable('PATH', '$OSCRIPTBIN:' + process.env.PATH);
71+
}
3972

40-
} else {
41-
throw new Error('OS not support');
73+
if (platform == 'linux') {
74+
await exec.exec('curl -L https://github.com/oscript-library/opm/releases/download/v0.16.2/opm-0.16.2.ospx --output opm.ospx');
75+
if (osVersion == '1.2.0') {
76+
await exec.exec('mkdir tmp');
77+
await exec.exec('unzip opm.ospx -d tmp');
78+
await exec.exec('unzip -o ./tmp/content.zip -d /home/runner/.local/share/ovm/current/lib/opm');
79+
}
80+
await exec.exec('opm install -f opm.ospx');
4281
}
4382
}
4483
catch (error) {
4584
core.setFailed(error.message);
4685
}
4786
}
4887

49-
function getVersionString(value) {
50-
var version = value.split('.').join('_');
51-
return version;
52-
}
88+
function installLinux() {
89+
var value = [];
90+
value.push('#!/bin/bash');
91+
value.push('sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF');
92+
value.push('echo "deb http://download.mono-project.com/repo/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/mono-official.list');
93+
value.push('sudo apt-get update');
94+
value.push('sudo apt-get install mono-complete mono-devel');
95+
value.push('sudo mv ovm.exe /usr/local/bin/');
96+
97+
let cmd = 'mono /usr/local/bin/ovm.exe "$@"';
98+
value.push("echo '" + cmd + "' | sudo tee /usr/local/bin/ovm");
5399

54-
function updatePath() {
55-
const OLD_PATH = process.env.PATH;
56-
PATH = OLD_PATH + ";C:\/Program Files\/OneScript\/bin;";
57-
core.exportVariable('Path', PATH);
100+
value.push('sudo chmod +x /usr/local/bin/ovm');
101+
return value.join('\n');
58102
}
59103

60-
function installLinux(version, bitness) {
61-
var value = [];
62-
value.push('#!/bin/bash');
63-
value.push('sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF');
64-
value.push('echo "deb http://download.mono-project.com/repo/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/mono-official.list');
65-
value.push('sudo apt-get update');
66-
value.push('sudo apt-get install mono-complete mono-devel');
67-
value.push('curl -v https://oscript.io/downloads/' + version + '/deb?bitness=' + bitness + ' --output os.deb');
68-
value.push('sudo dpkg -i os.deb');
69-
value.push('sudo apt install -f');
70-
return value.join('\n');
104+
function installMacOs() {
105+
var value = [];
106+
value.push('#!/bin/bash');
107+
value.push('mv ovm.exe /usr/local/bin/');
108+
let cmd = 'mono /usr/local/bin/ovm.exe "$@"';
109+
value.push("echo '" + cmd + "' | tee /usr/local/bin/ovm");
110+
value.push('sudo chmod +x /usr/local/bin/ovm');
111+
return value.join('\n');
71112
}
72113

73114
run()

0 commit comments

Comments
 (0)