Skip to content

Commit

Permalink
Merge pull request #4 from Slava-Shchipunov/feat/build-for-all-devices
Browse files Browse the repository at this point in the history
Feat/build for all devices
  • Loading branch information
Slava-Shchipunov authored Sep 18, 2024
2 parents 6c69a94 + 9adc89c commit 4bc84d4
Show file tree
Hide file tree
Showing 5 changed files with 595 additions and 11 deletions.
41 changes: 30 additions & 11 deletions .github/workflows/build-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,39 @@ on:
- "v*.*.*"

jobs:
generate-config:
runs-on: ubuntu-latest
outputs:
job-config: ${{ steps.generate-config.outputs.job-config }}
steps:
- name: Checkout code
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: Generate Job Config
id: generate-config
run: node index.js ${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build:
name: "v${{ matrix.build_env.tag }} - ${{ matrix.build_env.pkgarch}} :: ${{ matrix.build_env.target}}/${{ matrix.build_env.subtarget}} build"
runs-on: ubuntu-latest
needs: generate-config
strategy:
matrix:
build_env:
- tag: "23.05.4"
pkgarch: aarch64_cortex-a53
target: mediatek
subtarget: filogic
vermagic: "03ba5b5fee47f2232a088e3cd9832aec"
build_env: ${{ fromJson(needs.generate-config.outputs.job-config) }}

steps:
- uses: actions/checkout@v4
Expand All @@ -33,8 +55,6 @@ jobs:
with:
path: "**"
key: ${{ runner.os }}-build-vm4-${{ env.cache-name }}
restore-keys: |
${{ runner.os }}-build-vm4-cache-tools-kernel-${{ matrix.build_env.tag }}-${{ matrix.build_env.pkgarch}}-

- name: Building kernel and tools
#if: ${{ steps.cache-tools-kernel.outputs.cache-hit != 'true' }}
Expand All @@ -43,7 +63,7 @@ jobs:
# Setup & install feeds
wget https://downloads.openwrt.org/releases/${{ matrix.build_env.tag }}/targets/${{ matrix.build_env.target}}/${{ matrix.build_env.subtarget}}/feeds.buildinfo -O feeds.conf
echo "src-git awgopenwrt https://github.com/yury-sannikov/awg-openwrt.git" >> ./feeds.conf
echo "src-git awgopenwrt https://github.com/Slava-Shchipunov/awg-openwrt.git" >> ./feeds.conf
./scripts/feeds update && ./scripts/feeds install -a
# Setup config with AWG and dependencies
Expand Down Expand Up @@ -105,7 +125,7 @@ jobs:
run: |
tag_name=${{ github.ref_name }}
mkdir -p awgrelease
postfix="${tag_name}_v${{ matrix.build_env.tag }}_${{ matrix.build_env.pkgarch}}_${{ matrix.build_env.target}}_${{ matrix.build_env.subtarget}}"
postfix="v${{ matrix.build_env.tag }}_${{ matrix.build_env.pkgarch}}_${{ matrix.build_env.target}}_${{ matrix.build_env.subtarget}}"
cp bin/packages/${{ matrix.build_env.pkgarch }}/awgopenwrt/amneziawg-tools_*.ipk awgrelease/amneziawg-tools_${postfix}.ipk
cp bin/packages/${{ matrix.build_env.pkgarch }}/awgopenwrt/luci-app-amneziawg_*.ipk awgrelease/luci-app-amneziawg_${postfix}.ipk
cp bin/targets/${{ matrix.build_env.target}}/${{ matrix.build_env.subtarget}}/packages/kmod-amneziawg_*.ipk awgrelease/kmod-amneziawg_${postfix}.ipk
Expand All @@ -114,4 +134,3 @@ jobs:
uses: softprops/action-gh-release@v1
with:
files: awgrelease/*.ipk

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
node_modules/
92 changes: 92 additions & 0 deletions index.js
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();
Loading

0 comments on commit 4bc84d4

Please sign in to comment.