variables:
  - &golang_image 'golang:1.24'

steps:
  backend-lint:
    image: *golang_image
    commands:
      - go vet ./...
      - go fmt ./...
    when:
      event: [push, tag]

  frontend-lint:
    image: node:20
    commands:
      - cd web
      - npm ci
      - npm run lint

  frontend-build:
    image: node:20
    commands:
      - cd web
      - npm ci
      - npm run build
    depends_on:
      - frontend-lint
    when:
      event: [ push, tag ]

  backend-build:
    image: *golang_image
    commands:
      - go mod download
      - go generate ./...
      # Build with embedded frontend
      - go build -o inventory -ldflags="-s -w" .
    depends_on:
      - frontend-build
      - backend-lint
    when:
      event: [ push, tag ]
      
  # Create artifacts
  artifacts:
    image: alpine:latest
    commands:
      - mkdir -p artifacts
      - cp inventory artifacts/
      - tar -czvf artifacts/inventory.tar.gz inventory
    depends_on:
      - backend-build
    when:
      event: [ push, tag ]
      
  # Optional step for creating a Docker image
  #docker-build:
  #  image: plugins/docker
  #  settings:
  #    repo: ${DRONE_REPO_OWNER}/inventory
  #    tags:
  #      - latest
  #      - ${DRONE_TAG##v}
  #    dockerfile: Dockerfile
  #  depends_on:
  #    - backend-lint
  #    - frontend-lint
  #  when:
  #    branch: main
  #    event: [push, tag]