Skip to content

Build Beszel Agent IPK/APK #10

Build Beszel Agent IPK/APK

Build Beszel Agent IPK/APK #10

Workflow file for this run

name: Build Beszel Agent IPK
on:
workflow_dispatch:
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 }}
latest_repo_tag: ${{ steps.validate.outputs.latest_repo_tag }}
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 $LATEST_UPSTREAM β†’ $LATEST_UPSTREAM"
echo "latest_upstream_version=$LATEST_UPSTREAM" >> $GITHUB_OUTPUT
echo "latest_repo_tag=$LATEST_UPSTREAM-${{ matrix.branch }}" >> $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 }}-${{ 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"
GOARCH=$(./scripts/arch-mapper.sh "${{ matrix.arch }}")
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: Download and prepare binary
env:
VERSION: ${{ steps.prepare.outputs.version }}
GOARCH: ${{ steps.prepare.outputs.goarch }}
run: |
set -euo pipefail
./scripts/download-binary.sh "$VERSION" "$GOARCH" "./beszel-agent/files/usr/bin"
- 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
cp -r $GITHUB_WORKSPACE/packaging/files/* package/beszel-agent/files/
cp $GITHUB_WORKSPACE/packaging/Makefile.prebuilt package/beszel-agent/Makefile
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_repo_tag }}
name: ${{ needs.validate-versions.outputs.latest_repo_tag }} for OpenWrt ${{ matrix.branch }}
target_commitish: gh-pages
body: |
### Beszel Agent ${{ needs.validate-versions.outputs.latest_repo_tag }} for OpenWrt ${{ matrix.branch }}
files: ./**/*.ipk