forked from Slava-Shchipunov/awg-openwrt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
99 lines (84 loc) · 2.81 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
const axios = require('axios');
const cheerio = require('cheerio');
const core = require('@actions/core');
const version = process.argv[2]; // Получение версии OpenWRT из аргумента командной строки
const SNAPSHOT_TARGETS_TO_BUILD = ['mediatek', 'ramips', 'x86', 'armsr'];
const SNAPSHOT_SUBTARGETS_TO_BUILD = ['filogic', 'mt7622', 'mt7623', 'mt7629', 'mt7620', 'mt7621', 'mt76x8', '64', 'generic', 'armv8'];
if (!version) {
core.setFailed('Version argument is required');
process.exit(1);
}
const url = version === 'SNAPSHOT' ? 'https://downloads.openwrt.org/snapshots/targets/' : `https://downloads.openwrt.org/releases/${version}/targets/`;
async function fetchHTML(url) {
try {
const { data } = await axios.get(url);
return cheerio.load(data);
} catch (error) {
console.error(`Error fetching HTML for ${url}: ${error}`);
throw error;
}
}
async function getTargets() {
const $ = await fetchHTML(url);
const targets = [];
$('table tr td.n a').each((index, element) => {
const name = $(element).attr('href');
if (name && name.endsWith('/')) {
targets.push(name.slice(0, -1));
}
});
return targets;
}
async function getSubtargets(target) {
const $ = await fetchHTML(`${url}${target}/`);
const subtargets = [];
$('table tr td.n a').each((index, element) => {
const name = $(element).attr('href');
if (name && name.endsWith('/')) {
subtargets.push(name.slice(0, -1));
}
});
return subtargets;
}
async function getDetails(target, subtarget) {
const packagesUrl = `${url}${target}/${subtarget}/packages/`;
const $ = await fetchHTML(packagesUrl);
let vermagic = '';
let pkgarch = '';
$('a').each((index, element) => {
const name = $(element).attr('href');
if (name && name.startsWith('kernel_')) {
const vermagicMatch = name.match(/kernel_\d+\.\d+\.\d+(?:-\d+)?[-~]([a-f0-9]+)(?:-r\d+)?_([a-zA-Z0-9_-]+)\.ipk$/);
if (vermagicMatch) {
vermagic = vermagicMatch[1];
pkgarch = vermagicMatch[2];
}
}
});
return { vermagic, pkgarch };
}
async function main() {
try {
const targets = await getTargets();
const jobConfig = [];
for (const target of targets) {
const subtargets = await getSubtargets(target);
for (const subtarget of subtargets) {
const { vermagic, pkgarch } = await getDetails(target, subtarget);
if (version !== 'SNAPSHOT' || (SNAPSHOT_SUBTARGETS_TO_BUILD.includes(subtarget) && SNAPSHOT_TARGETS_TO_BUILD.includes(target))) {
jobConfig.push({
tag: version,
target,
subtarget,
vermagic,
pkgarch,
});
}
}
}
core.setOutput('job-config', JSON.stringify(jobConfig));
} catch (error) {
core.setFailed(error.message);
}
}
main();