name: Build container and validate lint/tests

on:
  pull_request:
  workflow_dispatch:

env:
  GO_VERSION: '1.22'

jobs:
  lint-validation:
    name: Validate Go code linting
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Install Go
        uses: actions/setup-go@v3
        with:
          go-version: ${{ env.GO_VERSION }}
      - name: golangci-lint
        uses: golangci/golangci-lint-action@v6
        with:
          args: --timeout=240s
  unit-test-golang:
    needs: lint-validation
    name: Unit tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Install Go
        uses: actions/setup-go@v3
        with:
          go-version: ${{ env.GO_VERSION }}
      - name: Run unit static tests
        run: go test -v
  validate-prod-container-building:
    needs: unit-test-golang
    name: Validate that the container build for prod
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout code
        uses: actions/checkout@v4
      -
        name: Build the stack
        run: docker network create your_network || true
      -
        name: Build the stack
        run: docker compose -f docker-compose.yml.prod up -d --build --force-recreate --remove-orphans
      -
        name: Souin container healthceck
        run: docker compose -f docker-compose.yml.prod exec -T souin ls
