name: Go

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

permissions:
  contents: read
  actions: write

jobs:
  go_tests:
    #runs-on: alrest-techarohq
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          persist-credentials: false

      - name: build essential
        run: |
          sudo apt-get update
          sudo apt-get install -y build-essential

      - uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
        with:
          node-version: '24.11.0'
      - uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
        with:
          go-version: '1.25.4'

      - name: Cache playwright binaries
        uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
        id: playwright-cache
        with:
          path: |
            ~/.cache/ms-playwright
          key: ${{ runner.os }}-playwright-${{ hashFiles('**/go.sum') }}

      - name: install node deps
        run: |
          npm ci

      - name: install playwright browsers
        run: |
          npx --no-install playwright@1.52.0 install --with-deps
          npx --no-install playwright@1.52.0 run-server --port 9001 &

      - name: Build
        run: npm run build

      - name: Test
        run: npm run test

      - name: Lint with staticcheck
        uses: dominikh/staticcheck-action@024238d2898c874f26d723e7d0ff4308c35589a2 # v1.4.0
        with:
          version: "latest"

      - name: Govulncheck
        run: |
          go tool govulncheck ./...
