name: CI

on:
  push:
    branches: ['**']
    tags-ignore: ['v*']
  pull_request:
    branches: ['**']

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.26'

      - name: Cache Go modules
        uses: actions/cache@v4
        with:
          path: |
            ~/.cache/go-build
            ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-

      - name: Download dependencies
        run: go mod download

      - name: Tidy modules
        run: go mod tidy

      - name: Run tests
        run: go test ./...

      - name: Build amcs-server
        run: go build -o /dev/null ./cmd/amcs-server

      - name: Build amcs-cli
        run: go build -o /dev/null ./cmd/amcs-cli
