From 226ae606a8b6f7f4858d7334ddcefd3f5553e173 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Tue, 13 Aug 2024 21:27:15 +0700 Subject: [PATCH 1/6] feat: add openWRT data fetch --- .github/workflows/build-module.yml | 8 +- .github/workflows/tets-script.yml | 35 +++ .gitignore | 2 + index.js | 84 +++++++ package-lock.json | 388 +++++++++++++++++++++++++++++ package.json | 23 ++ 6 files changed, 536 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/tets-script.yml create mode 100644 index.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.github/workflows/build-module.yml b/.github/workflows/build-module.yml index 73e0f65..5d96662 100644 --- a/.github/workflows/build-module.yml +++ b/.github/workflows/build-module.yml @@ -1,9 +1,9 @@ name: Create Release on Tag # on: [workflow_dispatch] -on: - push: - tags: - - "v*.*.*" +# on: +# push: +# tags: +# - "v*.*.*" jobs: build: diff --git a/.github/workflows/tets-script.yml b/.github/workflows/tets-script.yml new file mode 100644 index 0000000..041c524 --- /dev/null +++ b/.github/workflows/tets-script.yml @@ -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 diff --git a/.gitignore b/.gitignore index 9f11b75..7abe83f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .idea/ +node_modules/ +results.json diff --git a/index.js b/index.js new file mode 100644 index 0000000..9219686 --- /dev/null +++ b/index.js @@ -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); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..1e57323 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,388 @@ +{ + "name": "awg-openwrt", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "awg-openwrt", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "axios": "^1.3.1", + "cheerio": "^1.0.0" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, + "node_modules/axios": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz", + "integrity": "sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/boolbase": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", + "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==", + "license": "ISC" + }, + "node_modules/cheerio": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0.tgz", + "integrity": "sha512-quS9HgjQpdaXOvsZz82Oz7uxtXiy6UIsIQcpBj7HRw2M63Skasm9qlDocAM7jNuaxdhpPU7c4kJN+gA5MCu4ww==", + "license": "MIT", + "dependencies": { + "cheerio-select": "^2.1.0", + "dom-serializer": "^2.0.0", + "domhandler": "^5.0.3", + "domutils": "^3.1.0", + "encoding-sniffer": "^0.2.0", + "htmlparser2": "^9.1.0", + "parse5": "^7.1.2", + "parse5-htmlparser2-tree-adapter": "^7.0.0", + "parse5-parser-stream": "^7.1.2", + "undici": "^6.19.5", + "whatwg-mimetype": "^4.0.0" + }, + "engines": { + "node": ">=18.17" + }, + "funding": { + "url": "https://github.com/cheeriojs/cheerio?sponsor=1" + } + }, + "node_modules/cheerio-select": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cheerio-select/-/cheerio-select-2.1.0.tgz", + "integrity": "sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==", + "license": "BSD-2-Clause", + "dependencies": { + "boolbase": "^1.0.0", + "css-select": "^5.1.0", + "css-what": "^6.1.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3", + "domutils": "^3.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/css-select": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", + "integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==", + "license": "BSD-2-Clause", + "dependencies": { + "boolbase": "^1.0.0", + "css-what": "^6.1.0", + "domhandler": "^5.0.2", + "domutils": "^3.0.1", + "nth-check": "^2.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/css-what": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", + "integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==", + "license": "BSD-2-Clause", + "engines": { + "node": ">= 6" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/dom-serializer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", + "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", + "license": "MIT", + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "entities": "^4.2.0" + }, + "funding": { + "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" + } + }, + "node_modules/domelementtype": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", + "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ], + "license": "BSD-2-Clause" + }, + "node_modules/domhandler": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", + "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", + "license": "BSD-2-Clause", + "dependencies": { + "domelementtype": "^2.3.0" + }, + "engines": { + "node": ">= 4" + }, + "funding": { + "url": "https://github.com/fb55/domhandler?sponsor=1" + } + }, + "node_modules/domutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.1.0.tgz", + "integrity": "sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==", + "license": "BSD-2-Clause", + "dependencies": { + "dom-serializer": "^2.0.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3" + }, + "funding": { + "url": "https://github.com/fb55/domutils?sponsor=1" + } + }, + "node_modules/encoding-sniffer": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/encoding-sniffer/-/encoding-sniffer-0.2.0.tgz", + "integrity": "sha512-ju7Wq1kg04I3HtiYIOrUrdfdDvkyO9s5XM8QAj/bN61Yo/Vb4vgJxy5vi4Yxk01gWHbrofpPtpxM8bKger9jhg==", + "license": "MIT", + "dependencies": { + "iconv-lite": "^0.6.3", + "whatwg-encoding": "^3.1.1" + }, + "funding": { + "url": "https://github.com/fb55/encoding-sniffer?sponsor=1" + } + }, + "node_modules/entities": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/htmlparser2": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-9.1.0.tgz", + "integrity": "sha512-5zfg6mHUoaer/97TxnGpxmbR7zJtPwIYFMZ/H5ucTlPZhKvtum05yiPK3Mgai3a0DyVxv7qYqoweaEd2nrYQzQ==", + "funding": [ + "https://github.com/fb55/htmlparser2?sponsor=1", + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ], + "license": "MIT", + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3", + "domutils": "^3.1.0", + "entities": "^4.5.0" + } + }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/nth-check": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", + "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", + "license": "BSD-2-Clause", + "dependencies": { + "boolbase": "^1.0.0" + }, + "funding": { + "url": "https://github.com/fb55/nth-check?sponsor=1" + } + }, + "node_modules/parse5": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", + "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==", + "license": "MIT", + "dependencies": { + "entities": "^4.4.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, + "node_modules/parse5-htmlparser2-tree-adapter": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-7.0.0.tgz", + "integrity": "sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==", + "license": "MIT", + "dependencies": { + "domhandler": "^5.0.2", + "parse5": "^7.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, + "node_modules/parse5-parser-stream": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/parse5-parser-stream/-/parse5-parser-stream-7.1.2.tgz", + "integrity": "sha512-JyeQc9iwFLn5TbvvqACIF/VXG6abODeB3Fwmv/TGdLk2LfbWkaySGY72at4+Ty7EkPZj854u4CrICqNk2qIbow==", + "license": "MIT", + "dependencies": { + "parse5": "^7.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/undici": { + "version": "6.19.7", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.7.tgz", + "integrity": "sha512-HR3W/bMGPSr90i8AAp2C4DM3wChFdJPLrWYpIS++LxS8K+W535qftjt+4MyjNYHeWabMj1nvtmLIi7l++iq91A==", + "license": "MIT", + "engines": { + "node": ">=18.17" + } + }, + "node_modules/whatwg-encoding": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", + "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", + "license": "MIT", + "dependencies": { + "iconv-lite": "0.6.3" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-mimetype": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", + "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "license": "MIT", + "engines": { + "node": ">=18" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..cccdca0 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "awg-openwrt", + "version": "1.0.0", + "description": "Amnezia Wireguard packages for OpenWRT", + "main": "index.js", + "scripts": { + "get-build-envs": "node index.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Slava-Shchipunov/awg-openwrt.git" + }, + "author": "Slava Shchipunov", + "license": "ISC", + "bugs": { + "url": "https://github.com/Slava-Shchipunov/awg-openwrt/issues" + }, + "homepage": "https://github.com/Slava-Shchipunov/awg-openwrt#readme", + "dependencies": { + "axios": "^1.3.1", + "cheerio": "^1.0.0" + } +} From 4505effac571f234f88a1552de693a2b1d9b2328 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Tue, 13 Aug 2024 22:24:06 +0700 Subject: [PATCH 2/6] feat: upgrade workflow --- .github/workflows/build-module.yml | 42 ++++++++++++++++----- .github/workflows/tets-script.yml | 35 ----------------- .gitignore | 1 - index.js | 44 +++++++++++++--------- package-lock.json | 60 ++++++++++++++++++++++++++++++ package.json | 1 + 6 files changed, 119 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/tets-script.yml diff --git a/.github/workflows/build-module.yml b/.github/workflows/build-module.yml index 5d96662..d267a95 100644 --- a/.github/workflows/build-module.yml +++ b/.github/workflows/build-module.yml @@ -1,22 +1,44 @@ name: Create Release on Tag # on: [workflow_dispatch] -# on: -# push: -# tags: -# - "v*.*.*" +on: + push: + tags: + - "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 diff --git a/.github/workflows/tets-script.yml b/.github/workflows/tets-script.yml deleted file mode 100644 index 041c524..0000000 --- a/.github/workflows/tets-script.yml +++ /dev/null @@ -1,35 +0,0 @@ -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 diff --git a/.gitignore b/.gitignore index 7abe83f..1fe1b00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .idea/ node_modules/ -results.json diff --git a/index.js b/index.js index 9219686..3db329e 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,14 @@ const axios = require('axios'); const cheerio = require('cheerio'); -const fs = require('fs'); +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) { @@ -60,25 +66,27 @@ async function getDetails(target, subtarget) { } async function main() { - const targets = await getTargets(); - const results = []; + 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); - results.push({ - tag: version, - target, - subtarget, - vermagic, - pkgarch, - }); + 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); } - - fs.writeFileSync('results.json', JSON.stringify(results, null, 2), 'utf-8'); - console.log('Results written to results.json'); } -main().catch(console.error); +main(); diff --git a/package-lock.json b/package-lock.json index 1e57323..a4e25e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,52 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@actions/core": "^1.10.1", "axios": "^1.3.1", "cheerio": "^1.0.0" } }, + "node_modules/@actions/core": { + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.1.tgz", + "integrity": "sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==", + "license": "MIT", + "dependencies": { + "@actions/http-client": "^2.0.1", + "uuid": "^8.3.2" + } + }, + "node_modules/@actions/http-client": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.1.tgz", + "integrity": "sha512-KhC/cZsq7f8I4LfZSJKgCvEwfkE8o1538VoBeoGzokVLLnbFDEAdFD3UhoMklxo2un9NJVBdANOresx7vTHlHw==", + "license": "MIT", + "dependencies": { + "tunnel": "^0.0.6", + "undici": "^5.25.4" + } + }, + "node_modules/@actions/http-client/node_modules/undici": { + "version": "5.28.4", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz", + "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", + "license": "MIT", + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, + "engines": { + "node": ">=14.0" + } + }, + "node_modules/@fastify/busboy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", + "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -354,6 +396,15 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "license": "MIT" }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "license": "MIT", + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, "node_modules/undici": { "version": "6.19.7", "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.7.tgz", @@ -363,6 +414,15 @@ "node": ">=18.17" } }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/whatwg-encoding": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", diff --git a/package.json b/package.json index cccdca0..00692e1 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ }, "homepage": "https://github.com/Slava-Shchipunov/awg-openwrt#readme", "dependencies": { + "@actions/core": "^1.10.1", "axios": "^1.3.1", "cheerio": "^1.0.0" } From 8625a24b2e2f23ba43ac37e24a4bd77d4433b720 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Wed, 14 Aug 2024 09:56:00 +0700 Subject: [PATCH 3/6] fix: clear workspace before build --- .github/workflows/build-module.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-module.yml b/.github/workflows/build-module.yml index d267a95..e38af1e 100644 --- a/.github/workflows/build-module.yml +++ b/.github/workflows/build-module.yml @@ -41,6 +41,9 @@ jobs: build_env: ${{ fromJson(needs.generate-config.outputs.job-config) }} steps: + - name: Clear Workspace + run: git clean -fdx + - uses: actions/checkout@v4 with: repository: openwrt/openwrt @@ -127,7 +130,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 @@ -136,4 +139,3 @@ jobs: uses: softprops/action-gh-release@v1 with: files: awgrelease/*.ipk - From 96f91d8a615c6fccc2d27a06958399a0dbf4936b Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Wed, 14 Aug 2024 10:53:06 +0700 Subject: [PATCH 4/6] refactor: change repo url --- .github/workflows/build-module.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-module.yml b/.github/workflows/build-module.yml index e38af1e..096c68b 100644 --- a/.github/workflows/build-module.yml +++ b/.github/workflows/build-module.yml @@ -68,7 +68,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 From 847bcfbe77670aeffb6c7445a7e6000e41de2e7f Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Wed, 14 Aug 2024 11:19:56 +0700 Subject: [PATCH 5/6] fix: clear workspace before build --- .github/workflows/build-module.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-module.yml b/.github/workflows/build-module.yml index 096c68b..a2745e3 100644 --- a/.github/workflows/build-module.yml +++ b/.github/workflows/build-module.yml @@ -41,8 +41,14 @@ jobs: build_env: ${{ fromJson(needs.generate-config.outputs.job-config) }} steps: - - name: Clear Workspace - run: git clean -fdx + - name: Clean previous build artifacts + run: | + rm -rf bin/packages/* + rm -rf bin/targets/* + rm -rf build_dir/* + rm -rf dl/* + rm -rf tmp/* + rm -rf tools/* - uses: actions/checkout@v4 with: From 9adc89c272a1ee3c831a28e54e65ad208231750a Mon Sep 17 00:00:00 2001 From: Svyatoslav Shchipunov Date: Wed, 14 Aug 2024 12:14:09 +0700 Subject: [PATCH 6/6] fix: fix use cache --- .github/workflows/build-module.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/build-module.yml b/.github/workflows/build-module.yml index a2745e3..01dcb68 100644 --- a/.github/workflows/build-module.yml +++ b/.github/workflows/build-module.yml @@ -41,15 +41,6 @@ jobs: build_env: ${{ fromJson(needs.generate-config.outputs.job-config) }} steps: - - name: Clean previous build artifacts - run: | - rm -rf bin/packages/* - rm -rf bin/targets/* - rm -rf build_dir/* - rm -rf dl/* - rm -rf tmp/* - rm -rf tools/* - - uses: actions/checkout@v4 with: repository: openwrt/openwrt @@ -64,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' }}