stages:
  - prep
  - build

fetch-versions:
  image: busybox:latest
  stage: prep
  script:
    - apk add git curl jq
    - git clone https://gitlab.com/gitlab-org/omnibus-gitlab /tmp/gitlab
    - cd /tmp/gitlab
    - "HALIA_VER=$(curl --request GET -L --header 'Accept: application/json' --header 'Content-Type: application/json' https://git.halia.dev/api/v4/projects/24/registry/repositories/6/tags | jq -r '.[].location' | grep -v latest | cut -d ':' -f2 | sort -V | tail -1)"
    - "GITLAB_VER=$(git tag | sort -V | grep ce | tail -1 | cut -d '+' -f1)"
    - if [ $HALIA_VER != GITLAB_VER ]; then echo "1" >> /tmp/update; fi
  artifacts:
    paths:
      - /tmp/update
    expire_in: 1 hour

build-image:
  image: docker:latest
  stage: build
  services:
    - docker:dind
  script:
    - docker --version
    - cat /tmp/update
  dependencies:
    - fetch-versions