diff --git a/.github/workflows/build-module.yml b/.github/workflows/build-module.yml index 01dcb68f..aaa3d9a1 100644 --- a/.github/workflows/build-module.yml +++ b/.github/workflows/build-module.yml @@ -39,6 +39,7 @@ jobs: strategy: matrix: build_env: ${{ fromJson(needs.generate-config.outputs.job-config) }} + fail-fast: false steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/build-to-all-latest-snapshots.yml b/.github/workflows/build-to-all-latest-snapshots.yml new file mode 100644 index 00000000..e56f1299 --- /dev/null +++ b/.github/workflows/build-to-all-latest-snapshots.yml @@ -0,0 +1,184 @@ +name: Build AmneziaWG for snapshot OpenWRT + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +on: + push: + tags: + - "SNAPSHOT" + schedule: + - cron: '0 */4 * * *' + +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: Install dependencies + run: npm install + + - name: Generate Job Config + id: generate-config + run: node index.js SNAPSHOT + + build: + name: "${{ 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: ${{ fromJson(needs.generate-config.outputs.job-config) }} + fail-fast: false + + steps: + - name: Check if release file exists + id: check_release + run: | + postfix="${{ matrix.build_env.tag }}_${{ matrix.build_env.vermagic }}_${{ matrix.build_env.pkgarch}}_${{ matrix.build_env.target}}_${{ matrix.build_env.subtarget}}" + RELEASE_FILE="kmod-amneziawg_${postfix}.ipk" + + echo "Checking for release file: $RELEASE_FILE" + + # Используем GitHub CLI для проверки наличия файла в релизе + if gh release view $matrix.build_env.tag --repo Slava-Shchipunov/awg-openwrt --json assets --jq ".assets | .[].name" | grep -q "$RELEASE_FILE"; then + echo "Release file $RELEASE_FILE already exists. Skipping job." + echo "FILE_EXISTS=true" >> $GITHUB_ENV + else + echo "FILE_EXISTS=false" >> $GITHUB_ENV + fi + + # Прерываем job'у, если файл уже существует + - name: Skip job if release file exists + if: env.FILE_EXISTS == 'true' + run: | + echo "Skipping job as release file already exists." + exit 0 + + - name: Get snapshot commit SHA and device ARCH + if: env.FILE_EXISTS == 'false' + run: | + PROFILE_URL="https://downloads.openwrt.org/snapshots/targets/${{ matrix.build_env.target}}/${{ matrix.build_env.subtarget}}/profiles.json" + SNAPSHOT_COMMIT_SHA=$(wget -q $PROFILE_URL -O- | tr ',' '\n' | grep "version_code"| awk -F: '{print $2}' | tr -d '"' | awk -F- '{print $2}') + echo "Snapshot commit sha: $SNAPSHOT_COMMIT_SHA" + echo "SNAPSHOT_COMMIT_SHA=$SNAPSHOT_COMMIT_SHA" >> $GITHUB_ENV + + DEVICE_ARCH=$(wget -q $PROFILE_URL -O- | tr ',' '\n' | grep "arch_packages"| awk -F: '{print $2}' | tr -d '"') + echo "Device ARCH: $DEVICE_ARCH" + echo "DEVICE_ARCH=$DEVICE_ARCH" >> $GITHUB_ENV + + - uses: actions/checkout@v4 + if: env.FILE_EXISTS == 'false' + with: + repository: openwrt/openwrt + fetch-depth: 0 + + - name: Checkout snapshot commit in openwrt repo + if: env.FILE_EXISTS == 'false' + run: git checkout ${{ env.SNAPSHOT_COMMIT_SHA}} + + - name: Building kernel and tools + if: env.FILE_EXISTS == 'false' + run: | + echo "pkgarch: ${{ matrix.build_env.pkgarch}}, target:${{ matrix.build_env.target}}, subtarget: ${{ matrix.build_env.subtarget}}" + + # Setup & install feeds + wget https://downloads.openwrt.org/snapshots/targets/${{ matrix.build_env.target}}/${{ matrix.build_env.subtarget}}/feeds.buildinfo -O 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 + wget https://downloads.openwrt.org/snapshots/targets/${{ matrix.build_env.target}}/${{ matrix.build_env.subtarget}}/config.buildinfo -O .config + echo "CONFIG_PACKAGE_kmod-amneziawg=m" >> .config + echo "CONFIG_PACKAGE_amneziawg-tools=y" >> .config + echo "CONFIG_PACKAGE_luci-app-amneziawg=y" >> .config + echo "CONFIG_PACKAGE_kmod-crypto-lib-chacha20=m" >> .config + echo "CONFIG_PACKAGE_kmod-crypto-lib-chacha20poly1305=m" >> .config + echo "CONFIG_PACKAGE_kmod-crypto-chacha20poly1305=m" >> .config + + make defconfig + + echo " > make tools/install" + make tools/install -i -j `nproc` + + cat ./build_dir/target-*/linux-*/linux-*/.vermagic || true + + echo " > make toolchain/install" + make toolchain/install -i -j `nproc` + + cat ./build_dir/target-*/linux-*/linux-*/.vermagic || true + + # compile kernel module + echo " > make target/linux/compile" + make target/linux/compile -i -j `nproc` V=s + + VERMAGIC=`cat ./build_dir/target-*/linux-*/linux-*/.vermagic` + VERMAGIC_EXPECTED=${{ matrix.build_env.vermagic }} + + if [ "$VERMAGIC" != "$VERMAGIC_EXPECTED" ]; then + echo Vermagic mismatch: $VERMAGIC, expected $VERMAGIC_EXPECTED + exit 1 + fi + + - name: Build AmneziaWG + if: env.FILE_EXISTS == 'false' + run: | + VERMAGIC=`cat ./build_dir/target-*/linux-*/linux-*/.vermagic` + echo "Vermagic: $VERMAGIC" + + VERMAGIC_EXPECTED=${{ matrix.build_env.vermagic }} + + if [ "$VERMAGIC" != "$VERMAGIC_EXPECTED" ]; then + echo Vermagic mismatch: $VERMAGIC, expected $VERMAGIC_EXPECTED + exit 1 + fi + + # Ignore kmod build for some targets, replace with the awg-go + make package/kmod-amneziawg/{clean,download,prepare} V=s || true + make package/kmod-amneziawg/compile V=s || true + + make package/luci-app-amneziawg/{clean,download,prepare} + make package/luci-app-amneziawg/compile V=s + + make V=s package/amneziawg-tools/{clean,download,prepare} + make V=s package/amneziawg-tools/compile + + - name: Prepare artifacts + if: env.FILE_EXISTS == 'false' + run: | + tag_name=${{ github.ref_name }} + mkdir -p awgrelease + postfix="${{ matrix.build_env.tag }}_${{ matrix.build_env.vermagic }}_${{ 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 + + - name: Delete old release assets + if: env.FILE_EXISTS == 'false' + run: | + postfix="${{ matrix.build_env.pkgarch}}_${{ matrix.build_env.target}}_${{ matrix.build_env.subtarget}}" + echo "Looking for old release files ending with: ${postfix}" + + # Получаем список всех артефактов релиза + assets=$(gh release view "${{ matrix.build_env.tag }}" --repo Slava-Shchipunov/awg-openwrt --json assets --jq ".assets | .[] | select(.name | endswith(\"$postfix.ipk\")) | .id") + + # Удаляем найденные артефакты + for asset_id in $assets; do + echo "Deleting asset with ID: $asset_id" + gh release delete-asset "${{ matrix.build_env.tag }}" "$asset_id" --repo Slava-Shchipunov/awg-openwrt + done + + - name: Release + if: env.FILE_EXISTS == 'false' + uses: softprops/action-gh-release@v1 + with: + files: awgrelease/*.ipk diff --git a/README.md b/README.md index 02748fc1..c899848f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Для автоматической настройки рекомендую использовать [скрипт](https://github.com/itdoginfo/domain-routing-openwrt) от пользователя itdog. Этот скрипт позволяет автоматически скачать нужные пакеты из собранных здесь и настроить [точечный обход блокировок по доменам](https://habr.com/ru/articles/767464/). # Сборка пакетов для всех устройств, поддерживающих OpenWRT -В репозиторий в ветку `feat/build-for-all-devices` добавлен скрипт, который парсит данные о поддерживаемых платформах со страницы OpenWRT и автоматически запускает сборку пакетов AmneziaWG для всех устройств. +В репозиторий добавлен скрипт, который парсит данные о поддерживаемых платформах со страницы OpenWRT и автоматически запускает сборку пакетов AmneziaWG для всех устройств. На данный момент я собрал пакеты для всех устройств для OpenWRT версий: 1) [23.05.0](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v23.05.0) 2) [23.05.1](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v23.05.1) @@ -10,8 +10,7 @@ 4) [23.05.3](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v23.05.3) 5) [23.05.4](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v23.05.4) -Также запускал сборку для версии [22.03.7](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v22.03.7), но там для двух платформ сборка завершилась ошибкой. Так как это достаточно старая версия OpenWRT, -я не стал разбираться, в чем проблема. +Также запускал сборку для версии [22.03.7](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v22.03.7), но там для двух платформ сборка завершилась ошибкой. Так как это достаточно старая версия OpenWRT, я не стал разбираться, в чем проблема. ## Выбор пакетов для своего устройства В соответствии с пунктом [Указываем переменные для сборки](https://github.com/itdoginfo/domain-routing-openwrt/wiki/Amnezia-WG-Build#%D1%83%D0%BA%D0%B0%D0%B7%D1%8B%D0%B2%D0%B0%D0%B5%D0%BC-%D0%BF%D0%B5%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D1%8B%D0%B5-%D0%B4%D0%BB%D1%8F-%D1%81%D0%B1%D0%BE%D1%80%D0%BA%D0%B8) @@ -22,7 +21,7 @@ 2) Переключиться на вкладку Actions и включить Github actions (по умолчанию для форков они выключены) 3) Затем перейти на вкладку Code => Releases (в правой части экрана) => Draft a new release 4) Нажать Choose a tag и создать новый тег формата vX.X.X, где вместо X.X.X нужно подставить требуемую версию OpenWRT, например, v23.05.4 -5) Выбрать в качестве target ветку `feat/build-for-all-devices` +5) Выбрать в качестве target ветку `master` 6) Ввести Release title 7) Нажать внизу зеленую кнопку Publish release @@ -36,7 +35,7 @@ For automatic configuration, I recommend using the [script](https://github.com/itdoginfo/domain-routing-openwrt) from the user itdog. This script allows you to automatically download the necessary packages from those collected here and configure [point-by-point bypass of blocking by domains](https://habr.com/ru/articles/767464/) (instructions in Russian). # Building packages for all devices that support OpenWRT -A script has been added to the repository in the `feat/build-for-all-devices` branch that parses data on supported platforms from the OpenWRT page and automatically starts building AmneziaWG packages for all devices. +A script has been added to the repository that parses data on supported platforms from the OpenWRT page and automatically starts building AmneziaWG packages for all devices. At the moment I have collected packages for all devices for OpenWRT versions: 1) [23.05.0](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v23.05.0) 2) [23.05.1](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v23.05.1) @@ -44,8 +43,7 @@ At the moment I have collected packages for all devices for OpenWRT versions: 4) [23.05.3](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v23.05.3) 5) [23.05.4](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v23.05.4) -I also ran the build for version [22.03.7](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v22.03.7), but the build ended with an error for two platforms. Since this is a fairly old version of OpenWRT, -I did not bother to figure out what the problem was. +I also ran the build for version [22.03.7](https://github.com/Slava-Shchipunov/awg-openwrt/releases/tag/v22.03.7), but the build ended with an error for two platforms. Since this is a fairly old version of OpenWRT, I did not bother to figure out what the problem was. ## Selecting packages for your device In accordance with the paragraph [Specify variables for builds](https://github.com/itdoginfo/domain-routing-openwrt/wiki/Amnezia-WG-Build#%D1%83%D0%BA%D0%B0%D0%B7%D1%8B%D0%B2%D0%B0%D0%B5%D0%BC-%D0%BF%D0%B5%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D1%8B%D0%B5-%D0%B4%D0%BB%D1%8F-%D1%81%D0%B1%D0%BE%D1%80%D0%BA%D0%B8) (instructions in Russian) determine `target` and `subtarget` of your device. Then go to the release page corresponding to your OpenWRT version, then search the page (Ctrl+F) to find 3 packages whose names end in `target_subtarget.ipk` corresponding to your device. @@ -55,7 +53,7 @@ In accordance with the paragraph [Specify variables for builds](https://github.c 2) Switch to the Actions tab and enable Github actions (they are disabled for forks by default) 3) Then go to the Code tab => Releases (on the right side of the screen) => Draft a new release 4) Click Choose a tag and create a new tag in the vX.X.X format, where you need to substitute the required OpenWRT version for X.X.X, for example, v23.05.4 -5) Select the `feat/build-for-all-devices` branch as the target +5) Select the `master` branch as the target 6) Enter Release title 7) Click the green Publish release button at the bottom diff --git a/index.js b/index.js index 3db329e3..592c1eac 100644 --- a/index.js +++ b/index.js @@ -4,12 +4,15 @@ const core = require('@actions/core'); const version = process.argv[2]; // Получение версии OpenWRT из аргумента командной строки +// mediatek, ramips +const SNAPSHOT_SUBTARGETS_TO_BUILD = ['filogic', 'mt7622', 'mt7623', 'mt7629', 'mt7620', 'mt7621', 'mt76x8']; + if (!version) { core.setFailed('Version argument is required'); process.exit(1); } -const url = `https://downloads.openwrt.org/releases/${version}/targets/`; +const url = version === 'SNAPSHOT' ? 'https://downloads.openwrt.org/snapshots/targets/' : `https://downloads.openwrt.org/releases/${version}/targets/`; async function fetchHTML(url) { try { @@ -54,7 +57,7 @@ async function getDetails(target, subtarget) { $('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$/); + 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]; @@ -74,15 +77,19 @@ async function main() { 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, - }); + + if (version !== 'SNAPSHOT' || SNAPSHOT_SUBTARGETS_TO_BUILD.includes(subtarget)) { + jobConfig.push({ + tag: version, + target, + subtarget, + vermagic, + pkgarch, + }); + } } } + core.setOutput('job-config', JSON.stringify(jobConfig)); } catch (error) { core.setFailed(error.message);