.codechina-ci.yml 1.6 KB
Newer Older
李少辉-开发者's avatar
李少辉-开发者 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
default:
  image: node:latest
  before_script:
    - |
      if [[ ! -f package.json ]]; then
        echo "No package.json found! A package.json file is required to run npm build"
        exit 1
      fi
    - echo "current version is :"
    - echo $(node -p "require('./package.json').version")
stages:
  - test
  - deploy

check:
  stage: test
  script:
    - npm install
    - npm run build

publish:
  stage: deploy
  script:
    # If no .npmrc if included in the repo, generate a temporary one 
CoCo_Code_Op2's avatar
CoCo_Code_Op2 已提交
25 26 27 28 29 30 31 32 33 34
    # - echo $NPM_PUBLISH_TOKEN
    # - echo "https//registry.npmjs.org/:_authToken=${NPM_PUBLISH_TOKEN}"
    # - |
    #   if [[ ! -f .npmrc ]]; then
    #     echo 'No .npmrc found! Creating one now. Now we will generate one'
    #     {
    #       echo "https://registry.npmjs.org/:_authToken=${NPM_PUBLISH_TOKEN}"
    #     } >> .npmrc
    #   fi
    - npm config set registry "https://registry.npmjs.org/:_authToken=${NPM_PUBLISH_TOKEN}"
李少辉-开发者's avatar
李少辉-开发者 已提交
35 36 37 38 39 40 41

    # Extract a few values from package.json
    - NPM_PACKAGE_NAME=$(node -p "require('./package.json').name")
    - NPM_PACKAGE_VERSION=$(node -p "require('./package.json').version")

    # Compare the version in package.json to all published versions.
    # If the package.json version has not yet been published, run `npm publish`.
CoCo_Code_Op2's avatar
CoCo_Code_Op2 已提交
42
    - npm config get registry
李少辉-开发者's avatar
李少辉-开发者 已提交
43 44 45 46 47 48 49
    - |
      if [[ $(npm view "${NPM_PACKAGE_NAME}" versions) != *"'${NPM_PACKAGE_VERSION}'"* ]]; then
        npm publish
        echo "Successfully published version ${NPM_PACKAGE_VERSION} of ${NPM_PACKAGE_NAME} "
      else
        echo "Version ${NPM_PACKAGE_VERSION} of ${NPM_PACKAGE_NAME} has already been published, so no new version has been published."
      fi