Build Beszel Agent IPK/APK #23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Beszel Agent IPK | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - 'beszel-agent/**' | |
| pull_request: | |
| branches: | |
| - master | |
| paths: | |
| - 'beszel-agent/**' | |
| schedule: | |
| - cron: '0 2 * * 0' | |
| env: | |
| UPSTREAM_REPO: 'henrygd/beszel' | |
| PACKAGE_NAME: 'beszel-agent' | |
| jobs: | |
| validate-versions: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| latest_upstream_version: ${{ steps.validate.outputs.latest_upstream_version }} | |
| should_build: ${{ steps.validate.outputs.should_build }} | |
| steps: | |
| - name: Validate versions | |
| id: validate | |
| run: | | |
| set -euo pipefail | |
| LATEST_UPSTREAM=$(curl -s "https://api.github.com/repos/$UPSTREAM_REPO/releases/latest" | jq -r .tag_name) | |
| echo "Latest upstream Beszel: $LATEST_UPSTREAM" | |
| LATEST_REPO=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r .tag_name) | |
| echo "Latest repo release: $LATEST_REPO" | |
| REPO_VERSION=${LATEST_REPO%%-*} | |
| echo "Repo base version: $REPO_VERSION" | |
| if [ "$LATEST_UPSTREAM" != "$REPO_VERSION" ]; then | |
| echo "New version detected! Building $REPO_VERSION -> $LATEST_UPSTREAM" | |
| echo "latest_upstream_version=$LATEST_UPSTREAM" >> $GITHUB_OUTPUT | |
| echo "should_build=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "Versions match: $LATEST_UPSTREAM == $REPO_VERSION. No build needed." | |
| echo "should_build=false" >> $GITHUB_OUTPUT | |
| fi | |
| build: | |
| needs: validate-versions | |
| if: needs.validate-versions.outputs.should_build == 'true' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag: ${{ steps.prepare.outputs.tag }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| branch: | |
| - openwrt-24.10 | |
| arch: | |
| - aarch64_cortex-a53 | |
| - aarch64_cortex-a72 | |
| - aarch64_generic | |
| - arm_cortex-a7_neon-vfpv4 | |
| - arm_cortex-a9 | |
| - mipsel_24kc | |
| - x86_64 | |
| container: | |
| image: openwrt/sdk:${{ matrix.arch }}-${{ matrix.branch }} | |
| options: --user root | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Cache SDK downloads | |
| uses: actions/cache@v4 | |
| with: | |
| path: /builder/dl | |
| key: openwrt-dl-${{ matrix.branch }}-${{ matrix.arch }}-${{ needs.validate-versions.outputs.latest_upstream_version }}-${{ hashFiles('beszel-agent/Makefile') }} | |
| restore-keys: | | |
| openwrt-dl-${{ matrix.branch }}-${{ matrix.arch }}- | |
| openwrt-dl-${{ matrix.branch }}- | |
| - name: Setup SDK | |
| working-directory: /builder | |
| run: HOME=/builder ./setup.sh | |
| - name: Prepare build | |
| id: prepare | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| TAG="${{ needs.validate-versions.outputs.latest_upstream_version }}" | |
| echo "Latest version: $TAG" | |
| case "${{ matrix.arch }}" in | |
| aarch64_*) GOARCH="arm64" ;; | |
| arm_*) GOARCH="arm" ;; | |
| mipsel_*) GOARCH="mipsle" ;; | |
| mips_*) GOARCH="mips" ;; | |
| x86_64) GOARCH="amd64" ;; | |
| *) | |
| echo "Unknown architecture: ${{ matrix.arch }}" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| echo "Go architecture: $GOARCH" | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "goarch=$GOARCH" >> $GITHUB_OUTPUT | |
| echo "version=${TAG#v}" >> $GITHUB_OUTPUT | |
| echo "Building version: $TAG for arch: $GOARCH" | |
| - name: Install dependencies | |
| working-directory: /builder | |
| run: | | |
| apt update && apt install -y upx-ucl | |
| - name: Prepare package structure | |
| working-directory: /builder | |
| env: | |
| VERSION: ${{ steps.prepare.outputs.version }} | |
| run: | | |
| set -euo pipefail | |
| cp -r $GITHUB_WORKSPACE/beszel-agent package/beszel-agent | |
| echo "=== Package structure ===" | |
| ls -laR package/beszel-agent/files/ | |
| - name: Build IPK | |
| working-directory: /builder | |
| env: | |
| VERSION: ${{ steps.prepare.outputs.version }} | |
| run: | | |
| set -euo pipefail | |
| echo "CONFIG_PACKAGE_beszel-agent=m" >> .config | |
| make defconfig | |
| make package/beszel-agent/compile V=s -j$(nproc) BUILD_LOG=1 \ | |
| BESZEL_VERSION="$VERSION" | |
| - name: Collect artifacts | |
| env: | |
| ARCH: ${{ matrix.arch }} | |
| BRANCH: ${{ matrix.branch }} | |
| run: | | |
| set -euo pipefail | |
| echo "=== Searching for IPK files ===" | |
| find /builder/bin/packages -name "beszel-agent*.ipk" -ls || true | |
| mkdir -p $GITHUB_WORKSPACE/ipk-output | |
| find /builder/bin/packages -name "beszel-agent*.ipk" -exec cp {} $GITHUB_WORKSPACE/ipk-output/ \; | |
| cd $GITHUB_WORKSPACE/ipk-output | |
| echo "=== Files in ipk-output ===" | |
| ls -la | |
| IPK_COUNT=$(ls beszel-agent*.ipk 2>/dev/null | wc -l) | |
| if [[ $IPK_COUNT -eq 0 ]]; then | |
| echo "ERROR: No IPK file found!" >&2 | |
| exit 1 | |
| fi | |
| echo "Found $IPK_COUNT IPK file(s)" | |
| VERSION_DIR="${BRANCH/openwrt-}/$ARCH" | |
| mkdir -p "$VERSION_DIR" | |
| mv *.ipk "$VERSION_DIR/" | |
| cd "$VERSION_DIR" | |
| sha256sum *.ipk > SHA256SUMS | |
| cd $GITHUB_WORKSPACE/ipk-output | |
| tar -cvf $GITHUB_WORKSPACE/ipk-$BRANCH-$ARCH.tar "$VERSION_DIR" | |
| - name: Validate IPK package | |
| env: | |
| ARCH: ${{ matrix.arch }} | |
| BRANCH: ${{ matrix.branch }} | |
| run: | | |
| set -euo pipefail | |
| VERSION_DIR="${BRANCH/openwrt-}/$ARCH" | |
| cd ipk-output/$VERSION_DIR | |
| echo "=== Validating packages in $VERSION_DIR ===" | |
| for ipk in *.ipk; do | |
| size=$(stat -f%z "$ipk" 2>/dev/null || stat -c%s "$ipk") | |
| if [[ $size -lt 10000 ]]; then | |
| echo "ERROR: IPK file $ipk is too small ($size bytes)" >&2 | |
| exit 1 | |
| fi | |
| echo "β $ipk size: $size bytes" | |
| done | |
| sha256sum -c SHA256SUMS | |
| echo "β Package validation passed" | |
| - name: Upload packages | |
| if: success() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ipk-${{ matrix.branch }}-${{ matrix.arch }} | |
| path: | | |
| ipk-output/**/*.ipk | |
| ipk-output/**/SHA256SUMS | |
| if-no-files-found: error | |
| retention-days: 30 | |
| gh-pages: | |
| needs: [validate-versions, build] | |
| if: needs.validate-versions.outputs.should_build == 'true' | |
| permissions: | |
| contents: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: ipk-* | |
| - name: Prepare files | |
| run: | | |
| mkdir public | |
| find . -name 'ipk-*.tar' -exec tar -C ./public -xvf {} \; | |
| - name: Deploy to GH pages | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| user_name: 'github-actions[bot]' | |
| user_email: 'github-actions[bot]@users.noreply.github.com' | |
| full_commit_message: 'Beszel Agent ${{ needs.build.outputs.tag }}' | |
| force_orphan: true | |
| release: | |
| needs: [validate-versions, build, gh-pages] | |
| if: needs.validate-versions.outputs.should_build == 'true' | |
| permissions: | |
| contents: write | |
| runs-on: ubuntu-latest | |
| strategy: | |
| max-parallel: 1 | |
| matrix: | |
| branch: | |
| - '24.10' | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: ipk-* | |
| - name: Prepare files | |
| env: | |
| BRANCH: ${{ matrix.branch }} | |
| run: | | |
| find . -name "ipk-openwrt-$BRANCH-*.tar" -exec tar -xvf {} --wildcards '*.ipk' \; | |
| - name: Upload release assets | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| fail_on_unmatched_files: true | |
| tag_name: ${{ needs.validate-versions.outputs.latest_upstream_version }}-${{ matrix.branch }} | |
| name: ${{ needs.validate-versions.outputs.latest_upstream_version }} for OpenWrt ${{ matrix.branch }} | |
| target_commitish: gh-pages | |
| body: | | |
| ### Beszel Agent ${{ needs.validate-versions.outputs.latest_upstream_version }} for OpenWrt ${{ matrix.branch }} | |
| files: ./**/*.ipk |