forked from yury-sannikov/awg-openwrt
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Slava-Shchipunov/feat/build-for-all-devices
Feat/build for all devices
- Loading branch information
Showing
5 changed files
with
595 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.idea/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
const axios = require('axios'); | ||
const cheerio = require('cheerio'); | ||
const core = require('@actions/core'); | ||
|
||
const version = process.argv[2]; // Получение версии OpenWRT из аргумента командной строки | ||
|
||
if (!version) { | ||
core.setFailed('Version argument is required'); | ||
process.exit(1); | ||
} | ||
|
||
const url = `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_5\.\d+\.\d+-\d+-([a-f0-9]+)_([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); | ||
jobConfig.push({ | ||
tag: version, | ||
target, | ||
subtarget, | ||
vermagic, | ||
pkgarch, | ||
}); | ||
} | ||
} | ||
core.setOutput('job-config', JSON.stringify(jobConfig)); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
main(); |
Oops, something went wrong.