image: docker:23.0.5

variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: "/certs"
  DOCKER_HOST: tcp://docker:2376
  OUTLIERS_DOCKER_SHA: $CI_REGISTRY_IMAGE/outliers:$CI_COMMIT_SHA
  OUTLIERS_DOCKER_BRANCH: $CI_REGISTRY_IMAGE/outliers:$CI_COMMIT_REF_NAME
  OUTLIERS_DOCKER_TAG: $CI_REGISTRY_IMAGE/outliers:$CI_COMMIT_TAG
  OUTLIERS_DOCKER_LATEST: $CI_REGISTRY_IMAGE/outliers:latest

services:
  - docker:23.0.5-dind

stages:
  - build
  - release

before_script:
  - docker info
  - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

build-outliers:
  stage: build
  script:
    - docker pull $OUTLIERS_DOCKER_BRANCH || true
    - docker build --cache-from $OUTLIERS_DOCKER_BRANCH -f ./tools/typeOperations/Dockerfile --tag $OUTLIERS_DOCKER_BRANCH ./tools/typeOperations
    - docker push $OUTLIERS_DOCKER_BRANCH
  rules:
    - if: $CI_COMMIT_TAG || $CI_COMMIT_BRANCH == "main"
    - if: $CI_PIPELINE_SOURCE == "push" || $CI_COMMIT_BRANCH == "dev"
      when: manual
      allow_failure: true

build-tagged-outliers:
  stage: build
  script:
    # Create container tagged as 'latest'
    - docker pull $OUTLIERS_DOCKER_BRANCH || true
    - docker tag $OUTLIERS_DOCKER_BRANCH $OUTLIERS_DOCKER_LATEST
    - docker push $OUTLIERS_DOCKER_LATEST
    # Create image tagged with tag
    - docker tag $OUTLIERS_DOCKER_BRANCH $OUTLIERS_DOCKER_TAG
    - docker push $OUTLIERS_DOCKER_TAG
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_PIPELINE_SOURCE == "push" || $CI_COMMIT_BRANCH == "dev"
      when: manual
      allow_failure: true

build-ontology:
  image: gradle:8.1.1
  stage: build
  before_script:
    - ''
  script:
    - TOP="$(pwd)"
    - GRADLE_USER_HOME="$(pwd)/.gradle"
    - export GRADLE_USER_HOME
    - echo $TOP
    - echo $GRADLE_USER_HOME
    - apt-get update && apt-get -y install python3-pip && rm -rf /var/lib/apt/lists/*
    - python3 -m pip install bikeshed pyshacl
    - cd examples/oml/SystemDesignOntology2Layers
    - gradle build
    #- gradle startFuseki
    #- gradle owlQuery
    #- gradle owlReason
    #- gradle owlShacl
    #- gradle generateDocs
    #- gradle stopFuseki
    #- gradle publishToMavenLocal
    #- gradle publish
    #- cd $TOP/examples/oml/Drivetrain
    #- gradle build
    #- gradle publishToMavenLocal
    #- gradle publish
  cache:
    key: "$CI_COMMIT_REF_NAME"
    policy: push
    paths:
      - examples/oml/SystemDesignOntology2Layers/build
      #- examples/oml/Drivetrain/build
      - .gradle
  artifacts:
    paths:
      - examples/oml/SystemDesignOntology2Layers/build
      #- examples/oml/Drivetrain/build
      - ~/.m2
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
    - if: $CI_PIPELINE_SOURCE == "push" || $CI_COMMIT_BRANCH == "dev"
      when: manual
      allow_failure: true
