stages:
  - check
  - compile
  - test

default:
  image: gumjoe/wacc-ci-scala:slim
  cache:
    - key:
        files:
          - project.scala
      paths:
        - .coursier-cache/

variables:
  SCALA_CACHE: --cache=.coursier-cache/

check_format:
  stage: check
  needs: []
  before_script:
    - cs install scalafmt
  script:
    - scalafmt --check .

check_commits:
  stage: check
  needs: []
  image: node:lts-alpine
  before_script:
    - apk add git
    - npm install -g @commitlint/cli @commitlint/config-conventional
    - git checkout origin/master
  script:
    - git checkout ${CI_COMMIT_SHA}
    - npx commitlint --from origin/master --to ${CI_COMMIT_SHA} --verbose

compile_jvm:
  stage: compile
  needs: []
  script:
    - scala compile -Werror --server=false $SCALA_CACHE .
  artifacts:
    paths:
      - .bsp/
      - .scala-build/

test_jvm:
  image: gumjoe/wacc-ci-scala:x86
  stage: test
  # Use our own runner (not cloud VM or shared) to ensure we have multiple cores.
  tags: [large]
  # This is expensive, so do use `dependencies` instead of `needs` to
  # ensure all previous stages pass.
  dependencies: [compile_jvm]
  before_script:
    - git clone https://$EXAMPLES_AUTH@gitlab.doc.ic.ac.uk/lab2425_spring/wacc-examples.git
  script:
    - scala test --server=false $SCALA_CACHE .