# Checks for installed dependencies that are not up to date.

python:pip:outdated:
  stage: test
  image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
  variables:
    CHECK_ALL: "false"  # Set to true if you also want to check default packages such as pip and setuptools
  script:
    - OUTDATED="$(pip list --outdated --format freeze)"
    - |
      if "$CHECK_ALL" = "true"; then
        if [ ! -z "$OUTDATED" ]; then
          echo "[!] Your image has outdated packages:"
          pip list --outdated
          exit 1
        fi
      else
        OUTDATED_NOT_REQUIRED="$(pip list --outdated --format freeze --not-required)"
        if [ ! "$OUTDATED" = "$OUTDATED_NOT_REQUIRED" ]; then
          echo "[!] Your image has outdated packages. This list also contains non-dependencies but these weren't checked.:"
          pip list --outdated
          exit 1
        fi
      fi
    - echo "[+] Well done! You're up to date."
