
variables:
  CONAN_VERSION: "1.53.0"
  PYTHON_VERSION: "3.6.13"

stages:
  - build
  - test
  - package

.build:
  stage: build
  script:
    # Install python 3
    - curl -s -L -o ${PYTHON_ROOT}.zip https://gitlab.synchrotron-soleil.fr/software-control-system/devtools/python3/-/jobs/artifacts/main/download?job=${PLATFORM}
    - unzip -q ${PYTHON_ROOT}.zip -d ${CI_PROJECT_DIR}
    - rm -f ${PYTHON_ROOT}.zip
    # Install conan
    - ${CI_PROJECT_DIR}/${PYTHON_ROOT}/bin/python -m pip install -q --no-cache-dir --prefix=${CI_PROJECT_DIR}/${CONAN_ROOT} conan==${CONAN_VERSION} conan-package-tools
    # Fix python shebang to make it independent of install path
    - grep -I -r -l  "^#\!${CI_PROJECT_DIR}/${PYTHON_ROOT}/bin/python.*$" ${CI_PROJECT_DIR}/${CONAN_ROOT} | xargs sed -i '1c\#\!/usr/bin/env python'
    # Clean pycache
    - find ${CI_PROJECT_DIR}/${CONAN_ROOT} -iname __pycache__ -print0 | xargs -0 rm -rf
  artifacts:
    name: ${CONAN_ROOT}
    paths:
      - ${CONAN_ROOT}

.test:
  stage: test
  script:
    # Install python 3
    - curl -s -L -o ${PYTHON_ROOT}.zip https://gitlab.synchrotron-soleil.fr/software-control-system/devtools/python3/-/jobs/artifacts/main/download?job=${PLATFORM}
    - unzip -q ${PYTHON_ROOT}.zip -d ${CI_PROJECT_DIR}
    - rm ${PYTHON_ROOT}.zip
    # Test 
    - export PATH=${CI_PROJECT_DIR}/${PYTHON_ROOT}/bin:$PATH
    - export PYTHONPATH=${CI_PROJECT_DIR}/${CONAN_ROOT}/lib/python3.6/site-packages
    - ${CI_PROJECT_DIR}/${CONAN_ROOT}/bin/conan --version | grep ${CONAN_VERSION}

.package:
  stage: package
  script:
    - cd ${CI_PROJECT_DIR}/${CONAN_ROOT}
    - zip -r --symlinks ../${CONAN_ROOT}.zip *
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ../${CONAN_ROOT}.zip "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/conan/${CONAN_VERSION}/${CONAN_ROOT}"'

linux-el6-x86_64:
  extends: [".build"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el6-gcc44
  variables:
    PLATFORM: "linux-el6-x86_64"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
    PYTHON_ROOT: "python-${PYTHON_VERSION}-${PLATFORM}"

test-el6-x86_64:
  extends: [".test"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el6-gcc44
  variables:
    PLATFORM: "linux-el6-x86_64"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
    PYTHON_ROOT: "python-${PYTHON_VERSION}-${PLATFORM}"
  needs:
    - linux-el6-x86_64

package-el6-x86_64:
  extends: [".package"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el6-gcc44
  variables:
    PLATFORM: "linux-el6-x86_64"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
  needs:
    - linux-el6-x86_64
    - test-el6-x86_64

linux-el6-i686:
  extends: [".build"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el6-gcc44-x86
  variables:
    PLATFORM: "linux-el6-i686"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
    PYTHON_ROOT: "python-${PYTHON_VERSION}-${PLATFORM}"

test-el6-i686:
  extends: [".test"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el6-gcc44-x86
  variables:
    PLATFORM: "linux-el6-i686"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
    PYTHON_ROOT: "python-${PYTHON_VERSION}-${PLATFORM}"
  needs:
    - linux-el6-i686

package-el6-i686:
  extends: [".package"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el6-gcc44-x86
  variables:
    PLATFORM: "linux-el6-i686"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
    PYTHON_ROOT: "python-${PYTHON_VERSION}-${PLATFORM}"
  needs:
    - linux-el6-i686
    - test-el6-i686

linux-el7-x86_64:
  extends: [".build"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el7-gcc48
  variables:
    PLATFORM: "linux-el7-x86_64"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
    PYTHON_ROOT: "python-${PYTHON_VERSION}-${PLATFORM}"

test-el7-x86_64:
  extends: [".test"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el7-gcc48
  variables:
    PLATFORM: "linux-el7-x86_64"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
    PYTHON_ROOT: "python-${PYTHON_VERSION}-${PLATFORM}"
  needs:
    - linux-el7-x86_64

package-el7-x86_64:
  extends: [".package"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el6-gcc44-x86
  variables:
    PLATFORM: "linux-el7-x86_64"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
    PYTHON_ROOT: "python-${PYTHON_VERSION}-${PLATFORM}"
  needs:
    - linux-el7-x86_64
    - test-el7-x86_64

linux-el7-i686:
  extends: [".build"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el7-gcc48-x86
  variables:
    PLATFORM: "linux-el7-i686"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
    PYTHON_ROOT: "python-${PYTHON_VERSION}-${PLATFORM}"

test-el7-i686:
  extends: [".test"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el7-gcc48-x86
  variables:
    PLATFORM: "linux-el7-i686"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
    PYTHON_ROOT: "python-${PYTHON_VERSION}-${PLATFORM}"
  needs:
    - linux-el7-i686

package-el7-i686:
  extends: [".package"]
  image: gitlab-registry.synchrotron-soleil.fr/software-control-system/containers/dev-docker-tools/dev-el7-gcc48-x86
  variables:
    PLATFORM: "linux-el7-i686"
    CONAN_ROOT: "conan-${CONAN_VERSION}-${PLATFORM}"
    PYTHON_ROOT: "python-${PYTHON_VERSION}-${PLATFORM}"
  needs:
    - linux-el7-i686
    - test-el7-i686