---

.build:
  stage: build
  image: golang:1-alpine
  before_script:
    - export GOPATH="$CI_PROJECT_DIR/.go"
    - mkdir -p .go
  variables:
    CGO_ENABLED: 0

build-qa-ui:
  stage: build
  image: node:21-alpine
  before_script:
  script:
    - cd qa/ui
    - npm install --network-timeout=100000
    - npm run build
  artifacts:
    paths:
      - qa/ui/build/
    when: on_success

build-checker:
  extends:
    - .build
  script:
    - go build -v -buildvcs=false -o deploy/checker srs.epita.fr/fic-server/checker

build-generator:
  extends:
    - .build
  script:
    - go build -v -buildvcs=false -o deploy/generator srs.epita.fr/fic-server/generator

build-receiver:
  extends:
    - .build
  script:
    - go build -v -buildvcs=false -o deploy/receiver srs.epita.fr/fic-server/receiver

build-admin:
  extends:
    - .build
  script:
    - go build -v -buildvcs=false -tags gitgo -o deploy/admin-gitgo srs.epita.fr/fic-server/admin
    - go build -v -buildvcs=false -o deploy/admin srs.epita.fr/fic-server/admin

build-evdist:
  extends:
    - .build
  script:
    - go build -v -buildvcs=false -o deploy/evdist srs.epita.fr/fic-server/evdist

build-frontend-ui:
  stage: build
  image: node:21-alpine
  before_script:
  script:
    - cd frontend/fic
    - npm install --network-timeout=100000
    - npm run build

build-dashboard:
  extends:
    - .build
  script:
    - go build -v -buildvcs=false -o deploy/dashboard srs.epita.fr/fic-server/dashboard

build-repochecker:
  extends:
    - .build
  variables:
    CGO_ENABLED: 1
  script:
    - apk --no-cache add build-base
    - go build -buildvcs=false --tags checkupdate -v -o deploy/repochecker srs.epita.fr/fic-server/repochecker
    - go build -buildvcs=false -buildmode=plugin -v -o deploy/repochecker-epita-rules.so srs.epita.fr/fic-server/repochecker/epita
    - go build -buildvcs=false -buildmode=plugin -v -o deploy/repochecker-file-inspector-rules.so srs.epita.fr/fic-server/repochecker/file-inspector
    - go build -buildvcs=false -buildmode=plugin -v -o deploy/repochecker-grammalecte-rules.so srs.epita.fr/fic-server/repochecker/grammalecte
    - go build -buildvcs=false -buildmode=plugin -v -o deploy/repochecker-pcap-inspector-rules.so srs.epita.fr/fic-server/repochecker/pcap-inspector
    - go build -buildvcs=false -buildmode=plugin -v -o deploy/repochecker-videos-rules.so srs.epita.fr/fic-server/repochecker/videos
    - grep "const version" repochecker/update.go | sed -r 's/^.*=\s*(\S.*)$/\1/' > deploy/repochecker.version

build-qa:
  extends:
    - .build
  needs: ["build-qa-ui"]
  dependencies:
    - build-qa-ui
  script:
    - go build -v -buildvcs=false -o deploy/qa srs.epita.fr/fic-server/qa
