name: Main

on:
  push:
    branches:
      - master
  pull_request:

jobs:

  main:
    name: Main Process
    runs-on: ubuntu-latest
    env:
      GO_VERSION: stable
      GOLANGCI_LINT_VERSION: v2.7.1
      HUGO_VERSION: 0.148.2
      CGO_ENABLED: 0
      LEGO_E2E_TESTS: CI
      MEMCACHED_HOSTS: localhost:11211

    steps:

      - uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - uses: actions/setup-go@v6
        with:
          go-version: ${{ env.GO_VERSION }}

      - name: Check and get dependencies
        run: |
          go mod tidy --diff

      - name: Generate and Check generated elements
        run: |
          make generate-dns
          git diff --exit-code

      - uses: golangci/golangci-lint-action@v9
        with:
          version: ${{ env.GOLANGCI_LINT_VERSION }}
          install-only: true

      - name: Install Pebble
        run: go install github.com/letsencrypt/pebble/v2/cmd/pebble@v2.8.0

      - name: Install challtestsrv
        run: go install github.com/letsencrypt/pebble/v2/cmd/pebble-challtestsrv@v2.8.0

      - name: Set up a Memcached server
        uses: niden/actions-memcached@v7

      - name: Make
        run: |
          make
          make clean

      - name: Install Hugo
        run: |
          wget -O /tmp/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-amd64.deb
          sudo dpkg -i /tmp/hugo.deb

      - name: Build Documentation
        run: make docs-build
