name: build image
on:
  push:
    branches:
      - dev
      - main
  workflow_dispatch:
  pull_request_review:
    types: [submitted]

jobs:
  build:
    runs-on: ubuntu-latest
    name: Build
    if: github.event_name != 'pull_request_review' || github.event.review.state == 'approved'
    steps:
      - name: Checkout
        uses: actions/checkout@v5
      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "22"
          cache: "npm"
          cache-dependency-path: "**/package-lock.json"
      - name: Set up Golang
        uses: actions/setup-go@v5.5.0
        with:
          go-version: "1.24.4"
      - name: Build frontend
        run: |
          make frontend
      - name: Build application
        run: |
          make build_dev
      - name: Run tests
        run: |
          go test ./... -json > testreport.json
      - name: Make test cases
        run: |
          make build_dev_test
      - name: Golang Test Report
        uses: becheran/go-testreport@v0.3.2
        with:
          input: "testreport.json"
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: jetkvm-app
          path: |
            bin/jetkvm_app
            device-tests.tar.gz