---
.update-check:
  stage: .post
  image: docker:git
  variables:
    GIT_STRATEGY: none
  script:
    - echo "Checking latest version of ${UPDATE_CHECK_REPOSITORY}"
    - LATEST_VERSION=$(git ls-remote --tags ${UPDATE_CHECK_REPOSITORY} | cut -d/
      -f3 | grep -E 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n1)
    - |
      printf "Your ${UPDATE_CHECK_NAME:-repository} version ${UPDATE_CHECK_CURRENT_VERSION} is "
      if [ "${UPDATE_CHECK_CURRENT_VERSION}" == "${LATEST_VERSION}" ]; then
        echo "up to date."
      else
        echo "different than the latest ${LATEST_VERSION}."
        exit 1
      fi
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
  allow_failure: true
  needs: []
