---
name: 'main'

on:
  push:
  workflow_dispatch:

jobs:
  test:
    runs-on: 'self-hosted'
    steps:
      - uses: 'actions/checkout@v4'
      - uses: 'actions/setup-go@v5'
        with:
          go-version-file: 'go.mod'
      - name: 'fmt'
        run: |
          make tidy no-dirty
      - name: 'check'
        run: |
          make check no-dirty
  main:
    if: "${{ startsWith(github.ref, 'refs/tags/') }}"
    needs:
      - 'test'
    runs-on: 'self-hosted'
    steps:
      - uses: 'actions/checkout@v4'
      - uses: 'actions/setup-go@v5'
        with:
          go-version-file: 'go.mod'
      - name: 'build'
        run: |
          printf '%s' "$GIT_CRYPT_SECRET" | base64 -d > secret
          git-crypt unlock secret
          make build
        env:
          GIT_CRYPT_SECRET: '${{ secrets.GIT_CRYPT }}'
      - name: 'deploy'
        run: |
          make deploy
        env:
          SSH_PRIVATE_KEY: '${{ secrets.SSH_PRIVATE_KEY }}'
