---
stages:
  - test
  - lint
  - build
  - upload

unit_tests:
  stage: test
  image: quay.orus.io/cc/golang:1.17.6
  cache:
    key: tooling
    paths:
      - .gopath/pkg/mod
      - .gopath/golangci-cache
      - .cache/gocache
      - tools/bin
  script:
    - sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b tools/bin
    - tools/bin/task test

lint:
  stage: lint
  image: quay.orus.io/cc/golang:1.17.6
  cache:
    key: tooling
    paths:
      - .gopath/pkg/mod
      - .gopath/golangci-cache
      - .cache/gocache
      - tools/bin
  script:
    - GOLANGCI_LINT_ARGS="-j 4" GOLANGCI_LINT_CACHE=$CI_PROJECT_DIR/.gopath/golangci-cache tools/bin/task lint

build:
  stage: build
  image: quay.orus.io/cc/golang:1.17.6
  artifacts:
    paths:
      - build
  cache:
    key: tooling
    paths:
      - .gopath/pkg/mod
      - .gopath/golangci-cache
      - .cache/gocache
      - tools/bin
      - build
  script:
    - tools/bin/task build

upload:
  image: curlimages/curl:latest
  stage: upload
  cache:
    key: tooling
    paths:
      - build
  script:
    - apk add curl
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file build/beaver "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/beaver/latest/beaver"'
