diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5d8ba27 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,231 @@ +name: build + +on: + workflow_dispatch: + push: + tags: + - v[0-9]+* + +env: + REPO_URL: https://github.com/openwrt-xiaomi/openwrt.git + REPO_BRANCH: xq-24.10 + BUILD_ROOT: ${{ github.workspace }} + DEPENDENCIES: ${{ github.workspace }}/dependencies-ubuntu.txt + CUSTOM_FEEDS_SH: ${{ github.workspace }}/custom-feeds.sh + CUSTOM_PACKAGES_SH: ${{ github.workspace }}/custom-packages.sh + CUSTOM_CONFIG_SH: ${{ github.workspace }}/custom-config.sh + TZ: UTC + DEVICE_NAME: unknown + FILE_DATE: unknown + FIRMWARE: unknown + +jobs: + check: + runs-on: ubuntu-24.04 + outputs: + tag: ${{ steps.gh.outputs.tag }} + date: ${{ steps.gh.outputs.date }} + sha: ${{ steps.gh.outputs.sha }} + url: ${{ steps.gh.outputs.url }} + message: ${{ steps.gh.outputs.message }} + is_active: ${{ steps.activity.outputs.is_active }} + steps: + - name: Get repo data via GH API + id: gh + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: 'openwrt-xiaomi/openwrt' + run: | + echo "Tag name from GITHUB_REF_NAME: $GITHUB_REF_NAME" + echo "Tag name from github.ref_name: ${{ github.ref_name }}" + BRANCH=$(gh api repos/$REPO --jq '.default_branch') + DATE=$(gh api repos/$REPO/commits/$BRANCH --jq '.commit.committer.date') + { + echo "tag=$GITHUB_REF_NAME" + echo "date=$(date --utc -d $DATE +%Y%m%d)" + echo "sha=$(gh api repos/$REPO/commits/$BRANCH --jq '.sha[0:7]')" + echo "url=$(gh api repos/$REPO/commits/$BRANCH --jq '.html_url')" + echo "message<> $GITHUB_OUTPUT + echo "DATE=$DATE" >> $GITHUB_ENV + + - name: Check for repo activity + id: activity + env: + DATE: ${{ env.DATE }} + URL: ${{ steps.gh.outputs.url }} + run: | + TIMESTAMP=$(date --utc -d $DATE +%s) + DAYS=$(( ( $(date --utc +%s) - $TIMESTAMP ) / 86400 )) + echo "Repository activity: $(date --utc -d $DATE)" + echo "Commit: $URL" + if [ "${{ github.event_name }}" != "schedule" ]; then + is_active=true + elif [[ $DAYS -lt 1 ]] ; then + is_active=true + else + echo "Repository not updated within last 24 hours." + is_active=false + fi + echo "is_active=$is_active" >> $GITHUB_OUTPUT + + build: + needs: check + #if: needs.check.outputs.is_active == 'true' + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + target: + - rd03 + steps: + - name: Initialization environment + env: + DEBIAN_FRONTEND: noninteractive + run: | + sudo apt-get -qq update && sudo apt-get -qq upgrade + sudo apt-get -qq install $(cat $DEPENDENCIES) + sudo apt-get -qq autoremove --purge + sudo apt-get -qq clean + sudo timedatectl set-timezone "$TZ" + + - name: Maximize build disk space + uses: easimon/maximize-build-space@master + with: + remove-dotnet: true + remove-android: true + remove-haskell: true + remove-codeql: true + remove-docker-images: true + + #- name: Checkout builder + # uses: actions/checkout@main + + - name: Download OpenWrt sources + run: git clone --branch $REPO_BRANCH $REPO_URL $BUILD_ROOT + + - name: Info + shell: bash + run: | + echo "---------------------------" + ls -la + echo "---------------------------" + ls -la $BUILD_ROOT + echo "---------------------------" + exit 1 + + - name: Setup ccache + uses: actions/cache@v4 + with: + path: ${{ matrix.branch == 'openwrt-19.07' && '/home/build/openwrt/.ccache' || '/builder/.ccache' }} + key: ccache-${{ matrix.arch }}-${{ matrix.branch }}-${{ github.run_id }} + restore-keys: | + ccache-${{ matrix.arch }}-${{ matrix.branch }}- + + - name: Build packages + id: build + working-directory: ${{ matrix.branch == 'openwrt-19.07' && '/home/build/openwrt' || '/builder' }} + env: + DATE: ${{ needs.check.outputs.date }} + SHA: ${{ needs.check.outputs.sha }} + ARCH: ${{ matrix.arch }} + BRANCH: ${{ matrix.branch }} + SIGN_KEY: ${{ secrets.SIGN_PRIVATE_KEY }} + CCACHE_DIR: ${{ matrix.branch == 'openwrt-19.07' && '/home/build/openwrt/.ccache' || '/builder/.ccache' }} + shell: bash + run: | + #export PKG_VERSION=$(date --utc -d $DATE +%Y%m%d) + #find $GITHUB_WORKSPACE/zapret-openwrt -type d -path '*/package/zapret' -exec cp -vr {} ./package \; + cp -vr $GITHUB_WORKSPACE/zapret-openwrt ./package/zapret-openwrt/ + + mv feeds.conf.default feeds.conf + sed -i -e 's|base.*\.git|base https://github.com/openwrt/openwrt.git|' feeds.conf + sed -i -e 's|packages.*\.git|packages https://github.com/openwrt/packages.git|' feeds.conf + sed -i -e 's|luci.*\.git|luci https://github.com/openwrt/luci.git|' feeds.conf + + ./scripts/feeds update base packages luci + ./scripts/feeds install -a + + make defconfig + echo "------------- .config BEG -------------------" + cat .config + echo "------------- .config END -------------------" + + PKGLIST=`echo package/zapret-openwrt/{zapret,zapret-tpws,zapret-mdig,zapret-ip2net,luci-app-zapret}/compile` + make $PKGLIST V=s CONFIG_CCACHE=1 BUILD_LOG=1 + + find ./bin/packages/*/base -type f ! -regex ".*\(zapret\).*\.[ai]pk$" -delete + + #echo ">>>>>>> build a repository index to make the output directory usable as local OPKG source" + #ln -s `which usign` staging_dir/host/bin/usign + #echo "$SIGN_KEY" | base64 -d > key-build + #make package/index + + tar -C ./bin/packages/*/base -cvf $GITHUB_WORKSPACE/pkg-$BRANCH-$ARCH.tar --transform "s|^\./|${BRANCH/openwrt-}/$ARCH/|" --show-transformed-names . + ./staging_dir/host/bin/ccache --max-size=10M --show-stats + + - name: Compress build logs + if: always() + env: + ARCH: ${{ matrix.arch }} + BRANCH: ${{ matrix.branch }} + LOGS_DIR: ${{ matrix.branch == 'openwrt-19.07' && '/home/build/openwrt/logs' || '/builder/logs' }} + run: | + tar -cJvf logs-$BRANCH-$ARCH.tar.xz $LOGS_DIR + + - name: Upload packages + if: steps.build.outcome == 'success' + uses: actions/upload-artifact@v4 + with: + name: pkg-${{ matrix.branch }}-${{ matrix.arch }} + path: pkg-*.tar + if-no-files-found: error + + - name: Upload build logs + if: always() + uses: actions/upload-artifact@v4 + with: + name: logs-${{ matrix.branch }}-${{ matrix.arch }} + path: logs-*.tar.xz + + release: + needs: [ check, build ] + permissions: + contents: write + runs-on: ubuntu-latest + strategy: + max-parallel: 1 + matrix: + branch: [ 'SNAPSHOT', '23.05' ] + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + pattern: pkg-* + + - name: Put packages into zip + env: + BRANCH: ${{ matrix.branch }} + TAG: ${{ needs.check.outputs.tag }} + DATE: ${{ needs.check.outputs.date }} + run: | + mkdir -p public + find . -name "*-$BRANCH-*.tar" -exec tar -xvf {} --wildcards '*.*pk' \; + find $BRANCH -mindepth 1 -type d -exec sh -c 'zip -0 ./public/zapret_${TAG}_$(basename {}).zip -j {} {}/*' \; + ls -lh ./public/*.zip + + - name: Upload assets + uses: andelf/nightly-release@main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: ${{ matrix.branch }} + TAG: ${{ needs.check.outputs.tag }} + with: + prerelease: false + tag_name: ${{ needs.check.outputs.tag }}-${{ matrix.branch }} + name: '${{ needs.check.outputs.tag }} for OpenWrt ${{ matrix.branch }}' + body: | + ${{ needs.check.outputs.url }}: ${{ needs.check.outputs.message }} + files: ./public/*.zip diff --git a/dependencies-ubuntu.txt b/dependencies-ubuntu.txt new file mode 100644 index 0000000..d9c60f3 --- /dev/null +++ b/dependencies-ubuntu.txt @@ -0,0 +1 @@ +build-essential clang flex bison g++ gawk gcc-multilib g++-multilib gettext git libncurses5-dev libssl-dev python3-setuptools rsync swig unzip zlib1g-dev file wget \ No newline at end of file