Files
rmm-openwrt/.github/workflows/build.yml
T

292 lines
12 KiB
YAML

name: Build and test
on:
push:
branches: [main]
tags: ["agent-v*"]
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: build-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/agent-v') }}
jobs:
quality:
name: Tests and license checks
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- uses: actions/setup-node@v4
with:
node-version: 22
- run: go test ./...
- run: go vet ./...
- run: npm run check:web
- name: Verify license copies and package metadata
shell: bash
run: |
set -euo pipefail
cmp LICENSES/AGPL-3.0-only.txt web/licenses/AGPL-3.0-only.txt
for file in \
agent/LICENSE \
agent/package/rmm-agent/LICENSE \
agent/package/rmm-agent-go/LICENSE \
agent/package/rmm-agent-go-production/LICENSE \
agent/package/luci-app-rmm-agent/LICENSE \
web/licenses/MIT.txt; do
cmp LICENSES/MIT.txt "$file"
done
missing_license="$(grep -L 'PKG_LICENSE:=MIT' agent/package/*/Makefile || true)"
missing_file="$(grep -L 'PKG_LICENSE_FILES:=LICENSE' agent/package/*/Makefile || true)"
test -z "$missing_license"
test -z "$missing_file"
openwrt-packages:
name: OpenWrt ${{ matrix.release }} · ${{ matrix.label }}
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/agent-v')
needs: quality
runs-on: ubuntu-24.04
timeout-minutes: 90
strategy:
fail-fast: false
max-parallel: 4
matrix:
include:
# The matrix covers the common CPU families: amd64, mipsel, mips,
# ARMv7 and ARM64. Add a target/subtarget row when another device
# family needs an architecture-specific package.
- { release: "21.02.7", target: x86, subtarget: "64", label: x86-64, goarch: amd64 }
- { release: "21.02.7", target: ramips, subtarget: mt7621, label: ramips-mt7621, goarch: mipsle, gomips: softfloat }
- { release: "21.02.7", target: ath79, subtarget: generic, label: ath79-generic, goarch: mips, gomips: softfloat }
- { release: "21.02.7", target: ipq40xx, subtarget: generic, label: ipq40xx-generic, goarch: arm, goarm: "7" }
- { release: "21.02.7", target: bcm27xx, subtarget: bcm2711, label: bcm27xx-bcm2711, goarch: arm64 }
- { release: "22.03.7", target: x86, subtarget: "64", label: x86-64, goarch: amd64 }
- { release: "22.03.7", target: ramips, subtarget: mt7621, label: ramips-mt7621, goarch: mipsle, gomips: softfloat }
- { release: "22.03.7", target: ath79, subtarget: generic, label: ath79-generic, goarch: mips, gomips: softfloat }
- { release: "22.03.7", target: ipq40xx, subtarget: generic, label: ipq40xx-generic, goarch: arm, goarm: "7" }
- { release: "22.03.7", target: bcm27xx, subtarget: bcm2711, label: bcm27xx-bcm2711, goarch: arm64 }
- { release: "23.05.5", target: x86, subtarget: "64", label: x86-64, goarch: amd64 }
- { release: "23.05.5", target: ramips, subtarget: mt7621, label: ramips-mt7621, goarch: mipsle, gomips: softfloat }
- { release: "23.05.5", target: ath79, subtarget: generic, label: ath79-generic, goarch: mips, gomips: softfloat }
- { release: "23.05.5", target: ipq40xx, subtarget: generic, label: ipq40xx-generic, goarch: arm, goarm: "7" }
- { release: "23.05.5", target: bcm27xx, subtarget: bcm2711, label: bcm27xx-bcm2711, goarch: arm64 }
- { release: "23.05.5", target: mediatek, subtarget: filogic, label: mediatek-filogic, goarch: arm64 }
- { release: "24.10.7", target: x86, subtarget: "64", label: x86-64, goarch: amd64 }
- { release: "24.10.7", target: ramips, subtarget: mt7621, label: ramips-mt7621, goarch: mipsle, gomips: softfloat }
- { release: "24.10.7", target: ath79, subtarget: generic, label: ath79-generic, goarch: mips, gomips: softfloat }
- { release: "24.10.7", target: ipq40xx, subtarget: generic, label: ipq40xx-generic, goarch: arm, goarm: "7" }
- { release: "24.10.7", target: bcm27xx, subtarget: bcm2711, label: bcm27xx-bcm2711, goarch: arm64 }
- { release: "24.10.7", target: mediatek, subtarget: filogic, label: mediatek-filogic, goarch: arm64 }
- { release: "25.12.4", target: x86, subtarget: "64", label: x86-64, goarch: amd64 }
- { release: "25.12.4", target: ramips, subtarget: mt7621, label: ramips-mt7621, goarch: mipsle, gomips: softfloat }
- { release: "25.12.4", target: ath79, subtarget: generic, label: ath79-generic, goarch: mips, gomips: softfloat }
- { release: "25.12.4", target: ipq40xx, subtarget: generic, label: ipq40xx-generic, goarch: arm, goarm: "7" }
- { release: "25.12.4", target: bcm27xx, subtarget: bcm2711, label: bcm27xx-bcm2711, goarch: arm64 }
- { release: "25.12.4", target: mediatek, subtarget: filogic, label: mediatek-filogic, goarch: arm64 }
steps:
- uses: actions/checkout@v4
- name: Verify agent release version
if: startsWith(github.ref, 'refs/tags/agent-v')
shell: bash
run: |
set -euo pipefail
expected="${GITHUB_REF_NAME#agent-v}"
source_version="$(sed -n 's/^const agentVersion = "\([^"]*\)"/\1/p' agent/go/cmd/rmm-agent/main.go)"
package_version="$(sed -n 's/^PKG_VERSION:=//p' agent/package/rmm-agent-go-production/Makefile)"
test "$source_version" = "$expected"
test "$package_version" = "$expected"
- name: Resolve official OpenWrt SDK
id: sdk
shell: bash
env:
RELEASE: ${{ matrix.release }}
TARGET: ${{ matrix.target }}
SUBTARGET: ${{ matrix.subtarget }}
run: |
set -euo pipefail
record="$(awk -F '\t' \
-v release="$RELEASE" \
-v target="$TARGET" \
-v subtarget="$SUBTARGET" \
'$1 == release && $2 == target && $3 == subtarget { print $4 " " $5; exit }' \
.github/openwrt-sdk-lock.tsv)"
if [ -z "$record" ]; then
echo "No locked SDK found for OpenWrt ${RELEASE} ${TARGET}/${SUBTARGET}" >&2
exit 1
fi
read -r sha256 url <<<"$record"
echo "url=${url}" >> "$GITHUB_OUTPUT"
echo "sha256=${sha256}" >> "$GITHUB_OUTPUT"
echo "Using locked SDK ${url}"
- uses: docker/setup-buildx-action@v3
- name: Build agent and LuCI packages
uses: docker/build-push-action@v6
env:
OPENWRT_USIGN_SECRET_B64: ${{ secrets.OPENWRT_USIGN_SECRET_B64 }}
OPENWRT_APK_SECRET_B64: ${{ secrets.OPENWRT_APK_SECRET_B64 }}
with:
context: .
file: deploy/luci-builder/Dockerfile
target: artifacts
push: false
outputs: type=local,dest=artifacts
build-args: |
OPENWRT_SDK_URL=${{ steps.sdk.outputs.url }}
OPENWRT_SDK_SHA256=${{ steps.sdk.outputs.sha256 }}
RMM_GOARCH=${{ matrix.goarch }}
RMM_GOARM=${{ matrix.goarm || '7' }}
RMM_GOMIPS=${{ matrix.gomips || 'softfloat' }}
RMM_GOAMD64=v1
REQUIRE_NATIVE_SIGNATURE=${{ startsWith(github.ref, 'refs/tags/agent-v') }}
REPOSITORY_INDEX_REVISION=${{ github.run_id }}
secret-envs: |
openwrt_usign_secret_b64=OPENWRT_USIGN_SECRET_B64
openwrt_apk_secret_b64=OPENWRT_APK_SECRET_B64
cache-from: type=gha,scope=openwrt-${{ matrix.release }}-${{ matrix.label }}
cache-to: type=gha,mode=max,scope=openwrt-${{ matrix.release }}-${{ matrix.label }}
- name: Verify package artifacts
shell: bash
run: |
set -euo pipefail
find artifacts -maxdepth 1 -type f -print
test -f artifacts/SHA256SUMS
(cd artifacts && sha256sum --check SHA256SUMS)
find artifacts -maxdepth 1 -type f \( -name '*.ipk' -o -name '*.apk' \) -print -quit | grep -q .
if find artifacts -maxdepth 1 -type f -name '*.ipk' -print -quit | grep -q .; then
test -f artifacts/Packages
test -f artifacts/Packages.gz
if [[ "$GITHUB_REF" == refs/tags/agent-v* ]]; then
test -f artifacts/Packages.sig
public_key="$(find artifacts -maxdepth 1 -type f -regextype posix-extended -regex '.*/[0-9a-f]{16}' -print -quit)"
test -n "$public_key"
fi
else
test -f artifacts/packages.adb
if [[ "$GITHUB_REF" == refs/tags/agent-v* ]]; then
test -f artifacts/rmm-openwrt.pem
fi
fi
- uses: actions/upload-artifact@v4
with:
name: openwrt-${{ matrix.release }}-${{ matrix.label }}
path: artifacts/*
if-no-files-found: error
retention-days: 30
release:
name: Publish agent GitHub release assets
if: startsWith(github.ref, 'refs/tags/agent-v')
needs: openwrt-packages
runs-on: ubuntu-24.04
permissions:
contents: write
id-token: write
attestations: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: openwrt-*
path: release-assets
- name: Prepare release assets
shell: bash
run: |
set -euo pipefail
mkdir publish
while IFS= read -r file; do
artifact="$(basename "$(dirname "$file")")"
cp "$file" "publish/${artifact}-$(basename "$file")"
done < <(find release-assets -type f ! -name 'SHA256SUMS' -print | sort)
(cd publish && sha256sum ./* > SHA256SUMS)
- name: Prepare signed package repository
shell: bash
run: |
set -euo pipefail
bash scripts/prepare-package-repository.sh \
release-assets \
package-repository \
"${GITHUB_REF_NAME#agent-v}"
- uses: actions/upload-artifact@v4
with:
name: package-repository-site
path: package-repository
if-no-files-found: error
retention-days: 7
- name: Attest agent release assets
uses: actions/attest-build-provenance@v2
with:
subject-path: publish/*
- uses: sigstore/cosign-installer@v3
- name: Sign release checksums with GitHub OIDC
shell: bash
run: |
set -euo pipefail
cosign sign-blob --yes \
--bundle publish/SHA256SUMS.sigstore.json \
publish/SHA256SUMS
- name: Create release and upload packages
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
mapfile -t files < <(find publish -type f -print | sort)
if gh release view "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then
gh release upload "${GITHUB_REF_NAME}" "${files[@]}" \
--repo "${GITHUB_REPOSITORY}" \
--clobber
else
gh release create "${GITHUB_REF_NAME}" "${files[@]}" \
--repo "${GITHUB_REPOSITORY}" \
--generate-notes \
--title "OpenWrt RMM Agent ${GITHUB_REF_NAME#agent-v}"
fi
package-repository:
name: Publish signed package repository
if: startsWith(github.ref, 'refs/tags/agent-v')
needs: release
runs-on: ubuntu-24.04
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/download-artifact@v4
with:
name: package-repository-site
path: package-repository
- uses: actions/upload-pages-artifact@v3
with:
path: package-repository
- name: Deploy package repository to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4