cirun-agent 0.8.0

Cirun on-prem agent: provisions and manages CI/CD runners via Docker, Meda (Linux KVM VMs), and Lume (macOS VMs).
name: Test Service Installation

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test-install:
    name: Test Install on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
      fail-fast: false

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable

      - name: Build cirun-agent
        run: cargo build --release

      - name: Run linting
        run: |
          cargo fmt --check
          cargo clippy --release -- -D warnings

      - name: Test install command
        run: |
          if [ "$RUNNER_OS" == "Linux" ]; then
            sudo ./target/release/cirun-agent --api-token test-token-123 --install-service
          else
            ./target/release/cirun-agent --api-token test-token-123 --install-service
          fi

      - name: Verify service installation
        run: |
          if [ "$RUNNER_OS" == "Linux" ]; then
            test -f /etc/systemd/system/cirun-agent.service || exit 1
            systemctl is-enabled cirun-agent || exit 1
            systemctl is-active cirun-agent || exit 1
            echo "✅ Ubuntu service installation test passed"
          else
            test -f "$HOME/Library/LaunchAgents/io.cirun.agent.plist" || exit 1
            launchctl list | grep io.cirun.agent || exit 1
            echo "✅ macOS service installation test passed"
          fi

      - name: Show service logs
        run: |
          echo "Waiting for service to start..."
          sleep 5

          if [ "$RUNNER_OS" == "Linux" ]; then
            echo "=== Systemd service logs ==="
            sudo journalctl -u cirun-agent --no-pager -n 50
          else
            echo "=== Launchd service logs ==="
            if [ -f "$HOME/Library/Logs/cirun-agent.log" ]; then
              cat "$HOME/Library/Logs/cirun-agent.log"
            else
              echo "Log file not found yet"
            fi
            if [ -f "$HOME/Library/Logs/cirun-agent.error.log" ]; then
              echo "=== Error logs ==="
              cat "$HOME/Library/Logs/cirun-agent.error.log"
            fi
          fi

      - name: Test reinstall (should handle existing service)
        run: |
          echo "Testing reinstall with different interval..."
          if [ "$RUNNER_OS" == "Linux" ]; then
            sudo ./target/release/cirun-agent --api-token test-token-456 --interval 10 --install-service
          else
            ./target/release/cirun-agent --api-token test-token-456 --interval 10 --install-service
          fi

      - name: Verify service is still running after reinstall
        run: |
          sleep 3
          if [ "$RUNNER_OS" == "Linux" ]; then
            systemctl is-active cirun-agent || exit 1
            echo "✅ Service still running after reinstall"
          else
            launchctl list | grep io.cirun.agent || exit 1
            echo "✅ Service still running after reinstall"
          fi

      - name: Test uninstall service command
        run: |
          if [ "$RUNNER_OS" == "Linux" ]; then
            sudo ./target/release/cirun-agent --uninstall-service
          else
            ./target/release/cirun-agent --uninstall-service
          fi

      - name: Verify service was uninstalled
        run: |
          if [ "$RUNNER_OS" == "Linux" ]; then
            if [ -f /etc/systemd/system/cirun-agent.service ]; then
              echo "[ERROR] Service file still exists"
              exit 1
            fi
            if systemctl is-enabled cirun-agent 2>/dev/null; then
              echo "[ERROR] Service is still enabled"
              exit 1
            fi
            echo "[OK] Service successfully uninstalled on Linux"
          else
            if [ -f "$HOME/Library/LaunchAgents/io.cirun.agent.plist" ]; then
              echo "[ERROR] Plist file still exists"
              exit 1
            fi
            if launchctl list | grep io.cirun.agent 2>/dev/null; then
              echo "[ERROR] Service is still loaded"
              exit 1
            fi
            echo "[OK] Service successfully uninstalled on macOS"
          fi

      - name: Test uninstall when service not installed
        run: |
          # This should fail with exit code 1
          if [ "$RUNNER_OS" == "Linux" ]; then
            if sudo ./target/release/cirun-agent --uninstall-service; then
              echo "[ERROR] Uninstall should have failed when service not installed"
              exit 1
            fi
          else
            if ./target/release/cirun-agent --uninstall-service; then
              echo "[ERROR] Uninstall should have failed when service not installed"
              exit 1
            fi
          fi
          echo "[OK] Uninstall correctly failed when service not installed"

      - name: Test help command
        run: ./target/release/cirun-agent --help