Skip to content

Commit

Permalink
feat: add openWRT data fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Slava-Shchipunov committed Aug 13, 2024
1 parent 1c17d9b commit 226ae60
Show file tree
Hide file tree
Showing 6 changed files with 536 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-module.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Create Release on Tag
# on: [workflow_dispatch]
on:
push:
tags:
- "v*.*.*"
# on:
# push:
# tags:
# - "v*.*.*"

jobs:
build:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/tets-script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: OpenWRT Data Fetch

on:
push:
tags:
- 'v*.*.*'

jobs:
fetch-data:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.16.0'

- name: Get OpenWRT version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV

- name: Install dependencies
run: npm install

- name: Run script with version
run: node index.js ${{ env.VERSION }}

- name: Upload results.json
uses: actions/upload-artifact@v2
with:
name: results
path: results.json
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea/
node_modules/
results.json
84 changes: 84 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const axios = require('axios');
const cheerio = require('cheerio');
const fs = require('fs');

const version = process.argv[2]; // Получение версии OpenWRT из аргумента командной строки
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() {
const targets = await getTargets();
const results = [];

for (const target of targets) {
const subtargets = await getSubtargets(target);
for (const subtarget of subtargets) {
const { vermagic, pkgarch } = await getDetails(target, subtarget);
results.push({
tag: version,
target,
subtarget,
vermagic,
pkgarch,
});
}
}

fs.writeFileSync('results.json', JSON.stringify(results, null, 2), 'utf-8');
console.log('Results written to results.json');
}

main().catch(console.error);
Loading

0 comments on commit 226ae60

Please sign in to comment.