Files
tcptop/.gitea/workflows/build.yml
Zachary D. Rowitsch 23f34c0586
All checks were successful
Build & Package / build (push) Successful in 8m50s
fix(ci): add error output to release step and support GITEA_TOKEN
- Add set -euo pipefail and verbose error output on failure
- Support GITEA_TOKEN secret as fallback (GITHUB_TOKEN may lack
  release permissions in Gitea)
- Add ?name= param to asset upload URL

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 10:42:46 -04:00

161 lines
5.2 KiB
YAML

name: Build & Package
# Build tcptop binary and produce .deb/.rpm packages
on:
push:
branches: ["*"]
tags: ["v*"]
jobs:
build:
runs-on: linux
# Run in a Debian container so bpf-linker can load the LLVM shared lib
# from the Rust toolchain (Alpine/musl statically links LLVM, breaking
# aya-rustc-llvm-proxy's dlopen).
container:
image: debian:bookworm
env:
CARGO_TERM_COLOR: always
DEBIAN_FRONTEND: noninteractive
steps:
- name: Install system dependencies
run: |
apt-get update
apt-get install -y \
build-essential \
pkg-config \
linux-headers-amd64 \
libelf-dev \
clang \
llvm \
rpm \
curl \
git \
nodejs
# build-essential: gcc, make, etc. for native compilation
# pkg-config: locates system libraries during cargo build
# linux-headers-amd64: kernel headers for eBPF program compilation
# libelf-dev: ELF parsing library required by eBPF toolchain
# clang + llvm: LLVM backend used by bpf-linker to compile eBPF bytecode
# rpm: needed by cargo-generate-rpm to build .rpm packages
shell: bash
- name: Checkout code
run: |
git clone --depth=1 --branch="${GITHUB_REF_NAME}" \
"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" .
shell: bash
- name: Install Rust toolchain
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none
. "$HOME/.cargo/env"
# Install the pinned nightly from rust-toolchain.toml
rustup toolchain install nightly-2026-03-20 --component rust-src,rustfmt,clippy
# aya-build invokes `cargo +nightly` to compile eBPF programs
rustup toolchain install nightly --component rust-src
rustc --version
cargo --version
shell: bash
- name: Install bpf-linker
run: |
. "$HOME/.cargo/env"
if ! command -v bpf-linker &> /dev/null; then
cargo install bpf-linker
fi
bpf-linker --version || true
shell: bash
- name: Install packaging tools
run: |
. "$HOME/.cargo/env"
if ! command -v cargo-deb &> /dev/null; then
cargo install cargo-deb
fi
if ! command -v cargo-generate-rpm &> /dev/null; then
cargo install cargo-generate-rpm
fi
shell: bash
- name: Build release binary
run: |
. "$HOME/.cargo/env"
# build.rs auto-compiles the eBPF program via aya-build
cargo build --release -p tcptop
shell: bash
- name: Build .deb package
run: |
. "$HOME/.cargo/env"
# --no-build: binary already compiled in the previous step
cargo deb -p tcptop --no-build
shell: bash
- name: Build .rpm package
run: |
. "$HOME/.cargo/env"
cargo generate-rpm -p tcptop
shell: bash
- name: Collect packages
run: |
mkdir -p dist
cp target/debian/tcptop_*.deb dist/
cp target/generate-rpm/tcptop-*.rpm dist/
echo "=== Built packages ==="
ls -lh dist/
shell: bash
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: tcptop-packages
path: dist/*
- name: Create release
if: startsWith(github.ref, 'refs/tags/v')
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME}"
API_URL="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
# Use GITEA_TOKEN secret if available, fall back to GITHUB_TOKEN
TOKEN="${GITEA_TOKEN:-${GITHUB_TOKEN}}"
echo "Creating release for ${TAG}..."
RESPONSE=$(curl -sf -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\": \"${TAG}\", \"name\": \"${TAG}\", \"body\": \"tcptop ${TAG}\"}" \
"${API_URL}/releases") || {
echo "Failed to create release. Response:"
curl -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\": \"${TAG}\", \"name\": \"${TAG}\", \"body\": \"tcptop ${TAG}\"}" \
"${API_URL}/releases"
exit 1
}
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
echo "Release created with ID: ${RELEASE_ID}"
# Attach packages to the release
for f in dist/*; do
echo "Uploading $(basename "$f")..."
curl -sf -X POST \
-H "Authorization: token ${TOKEN}" \
-F "attachment=@${f}" \
"${API_URL}/releases/${RELEASE_ID}/assets?name=$(basename "$f")" || {
echo "Failed to upload $(basename "$f")"
exit 1
}
done
echo "Release ${TAG} created with packages attached"
shell: bash