stages:
  - lint
  # - build
  - deploy

deploy:
  stage: deploy
  only:
    - sst_main
  script:
    - cd /home/toren332/sst_postamates/
    - sudo docker-compose down
    - sudo git fetch
    - sudo git reset --hard origin/sst_main
    - sudo git submodule foreach git pull origin sst_main
    - sudo docker-compose up -d
  tags:
    - deploy-remote

flake8:
  stage: lint
  before_script: 
    - pip install flake8_formatter_junit_xml
    - export PATH="$HOME/.local/bin:$PATH"
  script:
    - set -x
    - FLIST=$(git --no-pager diff --diff-filter=d --name-only $(git merge-base --fork-point origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME) $CI_COMMIT_SHA  | egrep ".py$" | grep -v ".docker/"|| true)
    - >
      if [ ! -z "$FLIST" ];
      then
        mkdir -p build/reports;
        flake8 --format junit-xml $FLIST > build/reports/flake8-junit.xml || flake8 $FLIST;
      else
        echo "No files to lint"
        true;
      fi
  only:
    refs:
      - merge_requests
    changes:
      - "*.py"
      - "**/*.py"
  tags:
    - deploy-remote
  artifacts:
    reports:
      junit: ./build/reports/flake8-junit.xml
    expire_in: 7 days
  allow_failure: false

  
