-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
111 lines (87 loc) · 2.81 KB
/
main.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
const core = require('@actions/core');
const exec = require('@actions/exec');
const fs = require('fs');
const os = require('os');
const path = require('path');
const ini = require('ini');
function get_env(name) { return (process.env[name] || '').trim(); }
async function get_output(command, ...args) {
let output = '';
const opts = {
listeners: { stdout: (data) => { output += data.toString(); } }
};
await exec.exec(command, args, opts);
output = output.trim();
return 'None' != output ? output : '' ;
}
async function inspect_pkg(attr) {
return await get_output('conan', 'inspect', '.', '--raw', attr);
}
async function get_input_or_pkg_attr(attr) {
let result = core.getInput(attr);
if (!result) { result = await inspect_pkg(attr); }
return result;
}
async function get_pkg_user() {
let result = core.getInput('user');
if (!result) { result = get_env('CONAN_USERNAME'); }
if (!result) { result = await inspect_pkg('default_user'); }
if (!result) {
const repo = get_env('GITHUB_REPOSITORY');
result = (repo.split('/', 1) || [ '' ])[0].trim();
}
return result;
}
async function get_pkg_channel() {
let result = core.getInput('channel');
if (!result) { result = get_env('CONAN_CHANNEL'); }
if (!result) { result = await inspect_pkg('default_channel'); }
if (!result) { result = 'testing'; }
return result;
}
async function get_pkg_reference() {
let result = core.getInput('reference');
if (!result) {
const name = await get_input_or_pkg_attr('name');
const version = await get_input_or_pkg_attr('version');
const user = await get_pkg_user();
const channel = await get_pkg_channel();
result = `${name}/${version}@${user}/${channel}`
}
return result;
}
function info_to_profile(input) {
const allowed_sections = ['settings', 'options', 'env', 'build_requires']
let source = ini.parse(input);
let destination = {};
for (let section in source) {
if (!allowed_sections.includes(section)) { continue; }
destination[section] = source[section];
}
return 'include(default)\n\n' + ini.encode(destination);
}
async function run() {
const pkg_reference = await get_pkg_reference();
console.log()
console.log(`Using full package reference ${pkg_reference}`);
const parent = core.getInput('path');
fs.readdirSync(parent).forEach(async function(subdir) {
const package_dir = path.join(parent, subdir);
const input
= fs.readFileSync(path.join(package_dir, 'conaninfo.txt'), 'utf-8');
const profile_path = path.join(os.tmpdir(), subdir);
fs.writeFileSync(profile_path, info_to_profile(input));
console.log(`Exporting package from ${package_dir}`);
await exec.exec(
'conan',
[
'export-pkg',
'-pr', profile_path,
'-pf', package_dir,
'.',
pkg_reference
]
);
});
}
run()