Files
agent-builds/.gitea/workflows/build.yml
zeb f116aa82b1
Some checks failed
build-agent / build (push) Failing after 15m34s
agent-builds: initial pipeline (scan & publish upstream rmmagent tags)
2026-11-14 22:07:23 -08:00

130 lines
5.6 KiB
YAML

name: build-agent
# Builds the TacticalRMM agent (github.com/amidaware/rmmagent) and publishes the
# binaries into this public repo under dist/<tag>/. The TRMM update shim 302s
# agents to the raw file URLs; agents fetch them anonymously.
#
# Every trigger runs the same idempotent "scan & publish" job:
# - hourly cron : picks up a new upstream release automatically
# - workflow_dispatch : manual run from the Gitea UI
# - push to 'publish' : on-demand check (git push origin main:publish)
#
# A version already tagged in this repo is never rebuilt (idempotent).
# Only the newest upstream semver tag is ever auto-published; the TRMM server
# always tells agents to fetch the newest version, so older ones are not served.
on:
push:
branches: [publish]
schedule:
- cron: '17 * * * *'
workflow_dispatch:
jobs:
build:
runs-on: agentbuilds
permissions:
contents: write
steps:
- name: Scan, build, publish
shell: sh
run: |
set -eu
API="https://git.izebra.net"
REPO="izebra_projects/agent-builds"
UP="https://github.com/amidaware/rmmagent"
TOK="$(cat /data/releases-token)"
# token via git's env config, not argv (house pattern)
authgit() { GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraHeader \
GIT_CONFIG_VALUE_0="Authorization: token ***" git "$@"; }
W="$(mktemp -d /tmp/agentbuilds.XXXXXX)"
trap 'st=$(cat /tmp/agentbuilds-status 2>/dev/null); [ -n "$st" ] || echo failed > /tmp/agentbuilds-status; rm -rf "$W"' EXIT
rm -f /tmp/agentbuilds-status /tmp/agentbuilds-published
# --- newest upstream semver tag ---
VER="$(git ls-remote --tags "$UP" | awk '{print $2}' \
| grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -uV | tail -1 || true)"
if [ -z "$VER" ]; then
echo "noop" > /tmp/agentbuilds-status
echo "no upstream version found; nothing to do"
exit 0
fi
echo "newest upstream version: $VER"
# --- idempotency: already published here? ---
if authgit ls-remote --tags "$API/$REPO.git" | grep -qE "refs/tags/${VER}\$"; then
echo "noop" > /tmp/agentbuilds-status
echo "$VER already published (tag present) - nothing to do"
exit 0
fi
# --- build every target (CGO off: pure cross-compile, no qemu) ---
mkdir -p "$W/dist"
git clone --quiet --depth 1 --branch "$VER" "$UP" "$W/src"
(
cd "$W/src"
for t in linux/amd64 linux/arm64 linux/arm linux/386 \
darwin/amd64 darwin/arm64 windows/amd64 windows/386; do
GOOS="${t%%/*}"; GOARCH="${t##*/}"
EXE=""; [ "$GOOS" = "windows" ] && EXE=".exe"
echo "=== go build $GOOS/$GOARCH ==="
CGO_ENABLED=0 GOOS="$GOOS" GOARCH="$GOARCH" \
go build -ldflags "-s -w" \
-o "$W/dist/tacticalagent-$VER-$GOOS-$GOARCH$EXE" .
done
)
( cd "$W/dist" && sha256sum tacticalagent-* > SHA256SUMS )
# --- publish into this repo (public; agents fetch the raw URLs) ---
authgit clone --quiet "$API/$REPO.git" "$W/repo"
cd "$W/repo"
git config user.name "agent-builds"
git config user.email "agent-builds@izebra.net"
mkdir -p "dist/$VER"
cp "$W/dist"/tacticalagent-* "dist/$VER"/
cp "$W/dist/SHA256SUMS" "dist/$VER/"
{
echo "# agent-builds: published versions (the tag is the git ref used in raw URLs)"
[ -f dist/INDEX ] && grep -v '^#' dist/INDEX
printf '%s %s\n' "$VER" "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
} > dist/INDEX
git add -A
git commit -m "publish $VER (built from upstream amidaware/rmmagent at that tag)"
git tag "$VER"
authgit push origin main
authgit push origin "$VER"
# --- verify exactly what agents will do: anonymous raw fetch ---
for f in "$W/dist"/tacticalagent-*; do
n="$(basename "$f")"
code="$(curl -s -o /dev/null -w '%{http_code}' "$API/$REPO/raw/branch/$VER/dist/$VER/$n")"
if [ "$code" != "200" ]; then
echo "RAW FETCH FAILED: $n -> HTTP $code"
exit 1
fi
done
echo "published" > /tmp/agentbuilds-status
echo "$VER" > /tmp/agentbuilds-published
echo "PUBLISHED $VER: $(ls "$W/dist" | grep -c '^tacticalagent-') binaries + SHA256SUMS; raw URLs verified 200"
- name: Announce
shell: sh
run: |
if [ -f /tmp/agentbuilds-published ]; then
VER="$(cat /tmp/agentbuilds-published)"
curl -s -m 5 "http://10.2.1.10/izebra" \
-H "X-Title: agent-builds: $VER published" \
-H 'X-Priority: 3' -H 'X-Tag: rocket' \
--data "Published TacticalRMM agent $VER (8 targets) to git.izebra.net/izebra_projects/agent-builds. RMM2 LATEST_AGENT_VER is 2.12.0; bump it to $VER when the rollout is ready." || true
fi
- name: Alert
shell: sh
run: |
st="$(cat /tmp/agentbuilds-status 2>/dev/null || echo failed)"
if [ "$st" = "failed" ]; then
curl -s -m 5 "http://10.2.1.10/izebra" \
-H 'X-Title: agent-builds pipeline FAILED' \
-H 'X-Priority: 4' -H 'X-Tag: red_circle' \
--data "Build/publish job failed on git.izebra.net/izebra_projects/agent-builds - check the run log (runner: agentbuilds on DKR4)." || true
fi