From 0baccc6a98ba8f56a156c1b5ede22095eddddf8a Mon Sep 17 00:00:00 2001 From: lish Date: Thu, 17 Jun 2021 18:46:42 +0800 Subject: [PATCH] add codechina-ci.yml Signed-off-by: lish --- .codechina-ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .codechina-ci.yml diff --git a/.codechina-ci.yml b/.codechina-ci.yml new file mode 100644 index 0000000..ae56d01 --- /dev/null +++ b/.codechina-ci.yml @@ -0,0 +1,46 @@ +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 + - | + if [[ ! -f .npmrc ]]; then + echo 'No .npmrc found! Creating one now. Now we will generate one' + { + echo "//registry.npmjs.org/:_authToken=\${NPM_PUBLISH_TOKEN}" + } >> .npmrc + fi + - echo "Created the following .npmrc:"; cat .npmrc + + # 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`. + - | + 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 -- GitLab