This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
90 lines (77 loc) · 2.44 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
const core = require('@actions/core');
const exec = require('@actions/exec');
const got = require('got');
const fs = require('fs');
const io = require('@actions/io')
async function run() {
// set constants
const url = 'https://raw.githubusercontent.com/dephell/dephell/master/install.py'
const file_name = '.dephell_install.py'
// get variables
const env = core.getInput('dephell-env') || process.env.GITHUB_JOB;
if (!env) {
core.setFailed("`dephell-env` is required")
}
console.log(`dephell-env: ${env}`);
let python = core.getInput('python-version');
if (!python) {
python = await io.which("python3", true)
}
console.log(`python-version: ${python}`);
const version = core.getInput('dephell-version');
if (version) {
console.log(`dephell-version: ${version}`);
}
const executable = 'python3'
console.log(`python executable for dephell: ${executable}`);
// download installation script
const file = fs.createWriteStream(file_name)
const response = await got(url);
file.write(response.body)
file.close()
// run installation script
let options = {
silent: true,
ignoreReturnCode: true,
};
let args = [file_name]
if (version) {
args.push('--version', version)
}
code = await exec.exec(executable, args, options)
if (code) {
core.setFailed("cannot execute installation script")
}
fs.unlinkSync(file_name)
// in all comands below we don't suppress stdout
// and don't fail on non-zero exit code
options = {
ignoreReturnCode: true,
};
// show dephell info
code = await exec.exec('dephell', ['inspect', 'self'], options)
if (code) {
core.setFailed("cannot run dephell")
}
// create venv, install dependencies, run the command
code = await exec.exec('dephell', ['venv', 'create', '--env', env, '--python', python], options)
if (code) {
core.setFailed("cannot create venv")
}
code = await exec.exec('dephell', ['deps', 'install', '--env', env, '--silent'], options)
if (code) {
core.setFailed("cannot install deps")
}
code = await exec.exec('dephell', ['venv', 'run', '--env', env, '--silent'], options)
if (code) {
core.setFailed("non-zero status code returned by the command")
}
}
async function main() {
try {
run();
} catch (error) {
core.setFailed(error);
}
}
main()