name: Publish
on:
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
  build:
    runs-on: ubuntu-latest
    container: golang:1.24-bookworm
    steps:
      - name: Install dependencies
        run: apt update && apt -y install nodejs bash
      - name: Setup SSH
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan gitea-ssh.engen.priv.no >> ~/.ssh/known_hosts
      - name: Check out repository code
        uses: actions/checkout@v4
      - name: ssh repo
        run: git config --global url.git@gitea-ssh.engen.priv.no:.insteadOf https://gitea.engen.priv.no/
      - name: Install ko
        run: go install github.com/google/ko@latest
      - name: Extract tag (outside container)
        shell: bash
        run: |
          echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
          env
      - name: Build
        env:
          KO_DOCKER_REPO: registry.engen.priv.no/unifi-network-operator-controller
        run: |
          ko publish ./cmd --tags "$TAG,latest" --bare
