variables:
  TARGET_REPO_2021: "G:/CIV_CI/CivWebPublish2021_CivManage/CivWebPublish2021/"
  TARGET_REPO_Solution: "G:/CIV_CI/PandaSolution/civmanage/"
  TEMP_DIR: "G:/CIV_CI/tempV1/civmanage/"
  GIT_STRATEGY: 'fetch'
  GIT_CHECKOUT: 'false'

before_script:
  - chcp 65001
  - 'git config core.autocrlf false'

stages:
  - checkout
  - install
  - package
  - push
  
checkout:
  stage: checkout
  tags:
    - civ_manage_128
  variables:
    GIT_CHECKOUT: 'true'
  script:
  - echo "Got a clean git copy."
  only:
    - master
  when: manual

install:
  stage: install
  tags:
    - civ_manage_128
  script:
  - npm -v
  - npm run init
  only:
    - master
  when: manual

package:
  stage: package
  tags:
    - civ_manage_128
  script:
  - echo "${CI_PROJECT_DIR}"
  - git pull origin master
  - npm run build --releasepath=G:\\CIV_CI\\tempV1
  #- npm run build --releasepath=../CivWebPublish2021
  
  allow_failure: false
  only:
    - master
  when: manual

push_2021:
  variables:
    GIT_STRATEGY: none
  stage: push
  tags:
    - civ_manage_128
  script:
    - 'cd "${TARGET_REPO_2021}"'
    - 'git reset --hard head'
    - 'git clean -fd'
    - 'git remote set-url origin "https://${GIT_ACCESS_USER}:${GIT_ACCESS_PASSWORD}@g.civnet.cn:8443/CivPublish/CivWebPublish2021.git"'
    - 'git pull origin map'
    #- 'robocopy "${CI_PROJECT_DIR}/../CivWebPublish2021/civmanage" "${TARGET_REPO_2021}/civmanage" /S ;
    - 'robocopy "${TEMP_DIR}/" "${TARGET_REPO_2021}/civmanage" /S ;
        IF ((${LASTEXITCODE} -le 8)) {cmd /c "exit /b 0"}'
    - 'git add . ; git reset HEAD Web.config CityInterface/Web.config CityWebFW/Web.config ; git commit --allow-empty -m "auto package civmanage."'
    - 'git push origin map'
  only:
    - master
  when: on_success

push_solution:
  variables:
    GIT_STRATEGY: none
  stage: push
  tags:
    - civ_manage_128
  script:
    - 'cd "${TARGET_REPO_Solution}"'
    - 'git reset --hard head'
    - 'git clean -fd'
    - 'git remote set-url origin "https://${GIT_ACCESS_USER}:${GIT_ACCESS_PASSWORD}@g.civnet.cn:8443/PandaSolution/civmanage.git"'
    - 'git pull origin'
    #- 'robocopy "${CI_PROJECT_DIR}/../CivWebPublish2021/civmanage" "${TARGET_REPO_Solution}" /S ;
    - 'robocopy "${TEMP_DIR}/" "${TARGET_REPO_Solution}/" /S ;
        IF ((${LASTEXITCODE} -le 8)) {cmd /c "exit /b 0"}'
    - 'git add . ; git commit --allow-empty -m "auto package PandaSolution/civmanage."'
    - 'git push origin'
  only:
    - master
