variables:
  TARGET_REPO_2021: "G:/CIV_CI/CivWebPublish2021_WebGIS/CivWebPublish2021/"
  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 install npm@6.14.14 -g
  - npm -v
  - npm run init
  #cache:
  #  key: ${CI_COMMIT_REF_SLUG}
  #  paths:
  #  - node_modules/
  only:
    - master
  when: manual

package:
  stage: package
  tags:
    - civ_manage_128
  script:
  - echo "${CI_PROJECT_DIR}"
  - git pull origin master
  - npm run build --releasepath=../CivWebPublish2021
  #cache:
  #  key: ${CI_COMMIT_REF_SLUG}
  #  paths:
  #  - node_modules/
  allow_failure: false
  only:
    - master
  when: manual

push:
  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'
    #- 'git rm -rf "${TARGET_REPO_2021}/civmanage"'
    #- 'git commit -m "chore: clear folder civmanage"'
    #- 'git push origin map'
    - 'robocopy "${CI_PROJECT_DIR}/../CivWebPublish2021/civmanage" "${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'
  allow_failure: false
  only:
    - master
  when: manual
