image: ubuntu:22.04

stages:
#  - pull
#  - build
  - test
  - deploy

#.pullprivate:
#  stage: pull
#  script:
#    - echo "Cloning repos to set up a fresh build environment."
#    - cd ..
#    - if [ -d 02465private ];  then echo "Private repository exists";  else git clone https://oauth2:${GBAR_TOKEN}@gitlab.gbar.dtu.dk/02465material/02465private.git; fi
#    - if [ -d 02465students ]; then echo "Students repository exists"; else git clone https://oauth2:${GBAR_TOKEN}@gitlab.gbar.dtu.dk/02465material/02465students.git; fi
#    - rm -rf 02465students_complete
#    - cp -rf 02465students 02465students_complete

#setup_38:
#  extends: .pullprivate
#  image: python:3.8-buster
#
#setup_39:
#  extends: .pullprivate
#  image: python:3.9-buster
#
#setup_310:
#  extends: .pullprivate
#  image: python:3.10-buster

#.build:
#  stage: build
#  script:
#    - apt-get update
#    - apt install git
#    - apt install -y python-opengl xvfb # Virtual framebuffer for GL stuff.
#    - echo "Current working directory"
#    - pwd
#    - echo "Contents of cwd:"
#    - ls
#    - echo "Content of 02465material"
#    - ls /builds/02465material
#    - echo "Content of /builds/02465material/02465public"
#    - ls /builds/02465material/02465public
#    - cd pythontools
#    #- pip install -U setuptools #==58 # Required for unitgrade-devel because of python 2to3 is not in python 3.10... very hacky, and very bad. Need to change away from minifier.
#    - pip install -U -r requirements_full.txt --no-cache --upgrade
#    - cd tests
#    - echo "CURRENT WORKKING DIRECTORY"
#    - pwd
#    - xvfb-run -s "-screen 0 1400x900x24" python deploy_student_repos.py # > deploy_student_repos_log.txt


#build_38:
#  extends: .build
#  image: python:3.8-buster
#
#build_39:
#  extends: .build
#  image: python:3.9-buster

#build_310:
#  extends: .build
#  image: python:3.10-buster


.test_students:
  stage: test
  script:
    - echo "Testing student files"
    - apt-get update
    - apt install git
    - apt install -y xvfb # Virtual framebuffer for GL stuff.
    - pwd
#    - apt-get install -y software-properties-common
#    - apt-get -y update
#    - add-apt-repository universe
#    - sed -i "/^# deb.*multiverse/ s/^# //" /etc/apt/sources.list
#    - sed -i "/^# deb.*universe/ s/^# //" /etc/apt/sources.list
#    - add-apt-repository ppa:inkscape.dev/stable
    - apt install -y inkscape
    - pip install -U Pillow
    - pip install -e ./
#    - apt install -y swig # build-essential python-dev swig python-pygame # This is for swig. Remove when you go to a conda build system (and see what happens).
#    - pip install -U -r ../02465students/requirements_pip.txt  --no-cache --upgrade
#    - pip install -U -r ../02465students/requirements_conda.txt  --no-cache --upgrade
#    - cd ../02465public/pythontools/tests
#    - xvfb-run -s "-screen 0 1400x900x24" python test_student_code.py


test_39:
  extends: .test_students
  image: python:3.9-buster

#test_39:
#  extends: .test_students
#  image: python:3.9-buster
#
#test_310:
#  extends: .test_students
#  image: python:3.10-buster

pages:
  stage: deploy
  script:
    - echo "Building the documentation."
    - apt-get update
    - apt install git
    - apt install -y python-opengl xvfb # Virtual framebuffer for GL stuff.
#    - apt install -y python3-sphinx
    - pwd
    - ls
    - mkdir public
    - echo "hello" > public/index.html
#    - pip install -U -r pythontools/requirements_full.txt --no-cache --upgrade
#    - cd ../02465students_complete/docs/source
#    - sphinx-build -b html . ../../../02465public/public
#    - echo "> Changind directory to 02465public"
#    - cd ../../../02465public # Important for the artifact directory to be available.
#    - echo "> current working directory"
#    - pwd
#    - echo "Content of this directory is:"
#    - ls
#    - echo "Content of public directory is:"
#    - ls public
#    - echo "ci project dir {$CI_PROJECT_DIR}"
#    - cat public/index.html
  artifacts:
    paths:
    - public
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH


#- pip install -U setuptools #==58 Required for unitgrade-devel because of python 2to3 is not in python 3.10... very hacky, and very bad. Need to change away from minifier.
#    - xvfb-run -s "-screen 0 1400x900x24" python deploy_student_repos.py > deploy_student_repos_log.txt
#- echo "The public/docs/source/index.rst file is"
#- cat pythontools/docs/source/index.rst
#- echo "The 02465students/docs/source/index.rst file is"
#- cat ../02465students_complete/docs/source/index.rst