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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false

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

      - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
        with:
          node-version: "24.11.0"
      - uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
        with:
          go-version: "1.25.4"

      - name: Cache playwright binaries
        uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
        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 ./...
