name: Build deb-bootupd Artifacts # Comprehensive workflow for building and uploading deb-bootupd artifacts # Based on patterns from: https://domaindrivenarchitecture.org/pages/dda-pallet/ on: push: branches: [ main ] pull_request: branches: [ main ] workflow_dispatch: env: DEBIAN_VERSION: "13 (Trixie)" RUST_VERSION: "1.89.0" jobs: build: runs-on: ubuntu-latest env: FORGEJO_URL: ${{ secrets.FORGEJO_URL || 'https://git.raines.xyz' }} FORGEJO_HOST: ${{ secrets.FORGEJO_HOST || 'git.raines.xyz' }} # Use actual IP if available, fallback to hostname FORGEJO_IP: ${{ secrets.FORGEJO_IP || '' }} container: image: 'rust:1.89' options: | --dns=8.8.8.8 --dns=8.8.4.4 --add-host=git.raines.xyz:host-gateway --add-host=forgejo:host-gateway --memory=4g --memory-swap=4g steps: - name: Checkout code and setup environment run: | apt update -y apt install -y git curl pkg-config libssl-dev libsystemd-dev build-essential file zip nodejs npm # Install required Rust components echo "Installing Rust components..." rustup component add clippy rustup component add rustfmt rustup component add rust-src # For better error messages rustup component add rust-analysis # For IDE support # Enhanced network diagnostics echo "=== NETWORK DIAGNOSTICS ===" echo "Container hostname: $(hostname)" echo "Container IP: $(hostname -i)" echo "Container DNS: $(cat /etc/resolv.conf)" echo "Container routing:" ip route show echo "=== HOSTNAME RESOLUTION TESTS ===" echo "Testing forgejo hostname:" nslookup forgejo || echo "❌ forgejo hostname not resolved" echo "Testing git.raines.xyz hostname:" nslookup git.raines.xyz || echo "❌ git.raines.xyz hostname not resolved" echo "Testing explicit FORGEJO_HOST ($FORGEJO_HOST):" nslookup $FORGEJO_HOST || echo "❌ FORGEJO_HOST not resolved" echo "Testing external DNS (google.com):" nslookup google.com || echo "❌ External DNS not working" echo "=== IP CONNECTIVITY TESTS ===" echo "Testing Google DNS (8.8.8.8):" ping -c 3 8.8.8.8 || echo "❌ Google DNS ping failed" echo "Testing Cloudflare DNS (1.1.1.1):" ping -c 3 1.1.1.1 || echo "❌ Cloudflare DNS ping failed" # Try to resolve Forgejo server IP if not provided if [ -z "$FORGEJO_IP" ]; then echo "=== RESOLVING FORGEJO SERVER IP ===" FORGEJO_IP=$(nslookup $FORGEJO_HOST | grep -A1 "Name:" | grep "Address:" | awk '{print $2}' | head -1) if [ -n "$FORGEJO_IP" ]; then echo "✅ Resolved $FORGEJO_HOST to IP: $FORGEJO_IP" echo "FORGEJO_IP=$FORGEJO_IP" >> $GITHUB_ENV else echo "❌ Could not resolve $FORGEJO_HOST to IP" fi fi # Test direct IP connectivity if available if [ -n "$FORGEJO_IP" ]; then echo "Testing direct IP connectivity to $FORGEJO_IP:" ping -c 3 $FORGEJO_IP || echo "❌ Direct IP ping failed" fi echo "=== RUST ENVIRONMENT ===" echo "Available Rust components:" rustup component list --installed echo "✅ Using pre-installed Rust from official image:" rustc --version cargo --version # Verify Rust toolchain health echo "=== RUST TOOLCHAIN VERIFICATION ===" echo "Testing rustc compilation..." echo 'fn main() { println!("Hello, Rust!"); }' > /tmp/test.rs rustc /tmp/test.rs -o /tmp/test || { echo "❌ Rust compiler test failed - toolchain may be corrupted" exit 1 } /tmp/test || { echo "❌ Rust binary execution test failed" exit 1 } echo "✅ Rust toolchain verification passed" # Test cargo operations echo "Testing cargo operations..." cargo new /tmp/test-project --bin || { echo "❌ Cargo project creation failed" exit 1 } cd /tmp/test-project cargo check || { echo "❌ Cargo check failed" exit 1 } echo "✅ Cargo operations test passed" cd /tmp/deb-bootupd # Clone repository git clone https://git.raines.xyz/robojerk/deb-bootupd.git /tmp/deb-bootupd cd /tmp/deb-bootupd echo "Repository: $(git remote get-url origin)" echo "Branch: $(git branch --show-current)" echo "Commit: $(git rev-parse --short HEAD)" # Verify Rust version meets requirements (need 1.84.1+) RUST_VERSION=$(rustc --version | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1) echo "Rust version: $RUST_VERSION" if [ "$(printf '%s\n' "1.84.1" "$RUST_VERSION" | sort -V | head -n1)" != "1.84.1" ]; then echo "❌ Rust version $RUST_VERSION is too old, need 1.84.1+" exit 1 else echo "✅ Rust version $RUST_VERSION meets requirement (1.84.1+)" fi # Rust environment is already set up in the container echo "Rust environment ready:" echo "RUSTUP_HOME: $RUSTUP_HOME" echo "CARGO_HOME: $CARGO_HOME" echo "PATH includes: $PATH" - name: Build Rust project run: | cd /tmp/deb-bootupd # Set Rust compilation safeguards export RUSTFLAGS="-C target-cpu=native -C target-feature=+crt-static" export CARGO_INCREMENTAL=0 export CARGO_NET_RETRY=3 # Set memory limits for compilation ulimit -v 3145728 # 3GB virtual memory limit echo "Building deb-bootupd in release mode..." echo "Rust flags: $RUSTFLAGS" echo "Memory limit: $(ulimit -v) KB" # Try building with increased verbosity RUST_BACKTRACE=1 cargo build --release --verbose || { echo "❌ Build failed, trying with debug mode..." RUST_BACKTRACE=1 cargo build --debug --verbose || { echo "❌ Debug build also failed, checking Rust installation..." rustc --version --verbose cargo --version --verbose exit 1 } } echo "Build artifacts:" ls -la target/release/ || ls -la target/debug/ # Show binary info if [ -f target/release/bootupd ]; then echo "bootupd binary info:" file target/release/bootupd elif [ -f target/debug/bootupd ]; then echo "bootupd binary info (debug):" file target/debug/bootupd fi - name: Run tests run: | cd /tmp/deb-bootupd echo "Running tests..." cargo test --release echo "Running clippy..." cargo clippy --release echo "Checking formatting..." cargo fmt --check - name: Create build artifacts run: | cd /tmp/deb-bootupd # Create artifacts directory mkdir -p build-artifacts # Copy compiled binaries cp target/release/bootupd build-artifacts/ cp target/release/bootupctl build-artifacts/ 2>/dev/null || echo "bootupctl not found (may be symlink)" # Copy source code for reference cp -r src/ build-artifacts/ cp Cargo.toml Cargo.lock build-artifacts/ # Copy Debian packaging files cp -r debian/ build-artifacts/ 2>/dev/null || echo "debian/ directory not found" cp -r systemd/ build-artifacts/ 2>/dev/null || echo "systemd/ directory not found" # Create build info file cat > build-artifacts/BUILD_INFO.txt << EOF deb-bootupd Build Information ============================= Build Date: $(date) Container Image: rust:1.89 Debian Version: ${DEBIAN_VERSION} Rust Version: $(rustc --version) Cargo Version: $(cargo --version) Git Commit: $(git rev-parse --short HEAD) Git Branch: $(git branch --show-current) Build Type: Release EOF # Show artifacts echo "Build artifacts created:" ls -la build-artifacts/ echo "" echo "Build info:" cat build-artifacts/BUILD_INFO.txt - name: Upload artifacts to Forgejo env: USER: robojerk TOKEN: ${{ secrets.ACCESS_TOKEN }} BASE_URL: "git.raines.xyz" run: | cd /tmp/deb-bootupd # Create zip archive of artifacts artifact_name="deb-bootupd-artifacts-$(git rev-parse --short HEAD).zip" zip -r "$artifact_name" build-artifacts/ echo "Created artifact archive: $artifact_name" ls -la "$artifact_name" # Upload to Forgejo generic package registry echo "Uploading artifacts to Forgejo Package Registry..." # Use the same upload pattern as bootc-deb path="api/packages/robojerk/generic/deb-bootupd/$(git rev-parse --short HEAD)" upload_url="https://${BASE_URL}/${path}/${artifact_name}" echo "Upload URL: $upload_url" # Upload with proper authentication http_code=$(curl -s -o /dev/null -w "%{http_code}" \ --user "${USER}:${TOKEN}" \ --upload-file "$artifact_name" \ "$upload_url") echo "HTTP Response Code: $http_code" if [ "$http_code" = "201" ]; then echo "✅ Artifacts uploaded successfully to Forgejo Package Registry" elif [ "$http_code" = "409" ]; then echo "➡️ INFO: Artifacts already exist (HTTP 409 Conflict)" else echo "❌ Upload failed with HTTP $http_code" # Show verbose output for debugging curl -v -i --user "${USER}:${TOKEN}" \ --upload-file "$artifact_name" \ "$upload_url" 2>&1 exit 1 fi - name: Create release assets run: | cd /tmp/deb-bootupd mkdir -p release-assets cp "$artifact_name" release-assets/ 2>/dev/null || echo "No artifact archive found" # Create a summary file cat > release-assets/BUILD_SUMMARY.txt << EOF deb-bootupd Build Summary ========================= Build Date: $(date) Debian Version: ${DEBIAN_VERSION} Container Image: rust:1.89 Rust Version: $(rustc --version) Git Commit: $(git rev-parse --short HEAD) Git Branch: $(git branch --show-current) Built Artifacts: - Rust binaries (release mode) - Source code - Debian packaging files - Systemd service files Artifact Archive: $artifact_name EOF echo "Release assets created:" ls -la release-assets/ - name: Success Summary run: | echo "=== Build Summary ===" echo "✅ deb-bootupd compiled successfully in release mode" echo "✅ All tests passed" echo "✅ Code formatting and linting passed" echo "✅ Build artifacts created and uploaded to Forgejo" echo "" echo "📦 Artifacts available at:" echo " https://git.raines.xyz/robojerk/deb-bootupd/packages" echo "" echo "🎯 Next steps:" echo " - Verify artifacts appear in repository packages page" echo " - Test binaries on Ubuntu Noble systems" echo " - Consider building .deb packages for distribution"