###############################################################################
stages:
  - build_and_test
  - deploy

before_script:  # TODO: how to reuse installation?
    - DEBIAN_FRONTEND=noninteractive apt update
    - DEBIAN_FRONTEND=noninteractive apt install -y gcc git make python3 python3 python3-pip python3-pycurl python3-setuptools sshpass software-properties-common libcurl4-openssl-dev libssl-dev wget
    - git submodule init
    - git submodule update
    - python3 -m pip install wheel pyang pyangbind
    - git clone https://osm.etsi.org/gerrit/osm/IM.git
    - pip3 install -r IM/requirements.txt
    - pip3 install IM/
    - git clone https://osm.etsi.org/gerrit/osm/osmclient.git
    - cd osmclient
    - git fetch origin refs/changes/78/11178/3 && git checkout FETCH_HEAD
    - cd ../
    - pip3 install -r osmclient/requirements.txt
    - pip3 install osmclient/
    - rm -rf osmclient/ IM/
    - declare -a PACKAGES_TO_REVIEW=("charm-packages" "nscharm_policy_vnf" "hackfest_vyos_vnf" "nscharm_ns" "several_volumes_vnf" "magma" "k8s_jujucontroller_vnf" "simple_nopassword_vnf" "slice_basic_nst" "nschram_user_vnf")
    - >
        for nfv in "${PACKAGES_TO_REVIEW[@]}"; do
          echo "Ignoring $nfv until it is revised"
          rm -rf $nfv
        done


###############################################################################
build-local-repository:
  # Builds the repository locally but does not push if this is a new MR that
  # is still in development
  image: ubuntu:18.04
  stage: build_and_test
  only:
    - merge_requests
  script:
    - echo "Using OSM CLI repo-index tool to validate packages"
    - export LC_ALL=C.UTF-8
    - export LANG=C.UTF-8
    - osm -vvv repo-index --origin . --destination vnf-catalog
    - echo "Packages validated"


# TODO: Create and push to FTP repo
#publish-repository:
#  # Builds the repository and pushes it to ftp site when a MR is accepted
#  image: ubuntu:18.04
#  stage: deploy
#  only:
#    - master
#  script:
#    - echo "Build OK"
    # - LC_ALL=C.UTF-8 oLANG=C.UTF-8 osm -vvv repo-index --origin . --destination vnf-catalog
    # - |
    #     sshpass -p "$VNF_CATALOG_CREDENTIALS" sftp -o "StrictHostKeyChecking no" -P 29419 osmsupport@vnf-catalog.etsi.org << EOF
    #       put -r vnf-catalog/* Testing
    #     EOF