default:
  image: node:13.11.0
variables:
    USER: root  # 所有 Job 默认使用 root
before_script:
  - echo '====== 准备构建中 ========='
  - ln -sf /srv/node-v13.11.0-linux-x64/bin/node /bin/node  # 创建软链接到 bin 目录
stages:
  - deploy

# 发布
job_deploy:
  only:
    - 00.StaryEvo
  stage: deploy
  variables:
    USER: root  # 仅该 Job 使用 root
  tags:
  - staryEvo
  before_script:
    - echo '开始发布'
  script:
    - echo '当前用户：'$(whoami)  # 验证用户身份
    - ln -sf /srv/node-v13.11.0-linux-x64/bin/node /bin/node  # 创建软链接到 bin 目录
    - cd Assets/00.StaryEvo
     # 获取当前版本
    - CURRENT_VERSION=$(node -p "require('./package.json').version")
#    - echo " ProjectID ${CI_SERVER_HOST}"
#    - echo " ProjectID ${CI_PROJECT_ID}"
#    - echo " ProjectTOKEN ${CI_JOB_TOKEN}"
    - echo "registry=http://${SERVER_HOST}/npm" > .npmrc
    - echo "//${SERVER_HOST}/:_authToken=${AuthToken}" >> .npmrc
  # 版本存在检测
#    - if [[ "$REMOTE_VERSION" == *"$CURRENT_VERSION"* ]]; then
#        echo "版本 $CURRENT_VERSION 已存在，跳过发布";
#        exit 0;
#      fi
    - npm publish
    - echo '构建完成'
  when: 'on_success'
  retry: 0


after_script:
  - echo "====== 发布完成 ========="

