stages: - test - upload - bump - publish - review - bake - deploy before_script: ## Update repository - git fetch --prune origin - git checkout develop && git pull - git checkout master && git pull - git checkout production && git pull - if [[ -z ${CI_BUILD_TAG} ]]; then - git checkout "${CI_BUILD_REF_NAME}" && git pull - else - git checkout tags/"${CI_BUILD_REF_NAME}" - fi ## Update submodules - git submodule sync --recursive - git submodule update --init --recursive ## Setup remote to push back - if [[ ! -z $(git remote -v | grep back-to-gitlab) ]]; then git remote remove back-to-gitlab; fi - gitlab_origin=$(echo $CI_BUILD_REPO | sed 's|^.*@|http://gitlab-runner@|' | sed "s|@|:${GITLAB_RUNNER_PASSWORD}@|") - git remote add back-to-gitlab $gitlab_origin ## Ensure Nodejs installed - source ~/.nvm/nvm.sh - nvm install 6.9.2 units: stage: test script: - export CI_BUILD_ENVIRONMENT=sandbox - . opskit/load-deployment-context.sh ## Install all dependencies - npm install ## Run tests and parse coverage - export CLIO_MONGO_URL=$TEST_MONGO_URL - npm run cover artifacts: paths: - coverage/lcov-report/ cache: key: $CI_BUILD_NAME paths: - node_modules/ coverage report: stage: upload only: - develop script: ## Avoid uploading coverage on new version - if [[ ! -z $(git tag -l --points-at HEAD) ]] && [[ -z ${CI_BUILD_TAG} ]]; then exit 0; fi ## Login to vault server - export VAULT_TOKEN=$(vault write -field=token auth/approle/login role_id=${ROLE_ID}) ## Retrieve service account credentials - vault read -format json secret/io-arisan-ci | jq '.data' > account.json ## Activate service account - gcloud auth activate-service-account --key-file account.json ## Prepare coverage report to be uploaded - cd coverage - mv lcov-report data-api ## Upload coverage report - gsutil -m cp -r data-api gs://coverage.arisan.io version: stage: bump only: - develop - master - production script: ## Avoid version bump on new version - if [[ ! -z $(git tag -l --points-at HEAD) ]] && [[ -z ${CI_BUILD_TAG} ]]; then exit 0; fi ## Calculate next version - . opskit/next-version.sh ## Avoid using any version prefix like 'v' - npm config set tag-version-prefix '' ## Bump, tag and commit next version - 'npm version ${NEXT_VERSION} -m "ver: %s"' ## Push the updated package.json back to repo - git push back-to-gitlab ## Push the new version tag back to repo - git push back-to-gitlab refs/tags/${NEXT_VERSION} npm package: stage: publish only: - tags script: - npm install - packaged_name=$(node -e "console.log(require('./package.json').name)") - packaged_version=$(node -e "console.log(require('./package.json').version)") - if [[ -z $(npm info $packaged_name@$packaged_version) ]]; then - npm publish - fi cache: key: $CI_BUILD_NAME paths: - node_modules/ alpha: stage: review only: - /alpha/ except: - branches variables: CI_BUILD_ENVIRONMENT: 'sandbox' environment: name: 'sandbox' script: ## Load deployment context - . opskit/load-deployment-context.sh ## Use current commit revision as version - export VERSION=${CI_BUILD_TAG} ## Configure deployment variables - ./iac/configure-variables ## Create an iac tarball - tar -zcf iac.tar.gz iac ## Compose an appropriate instance name - instance_name='data-api' ## Check if review instance is already up - instance_count=$(gcloud compute instances list --filter="name=${instance_name}" --format='(name)' | tail -n -1 | wc -l) ## Create an instance if review instance is not already up - if [[ "${instance_count}" -lt "1" ]]; then - gcloud compute instances create ${instance_name} --machine-type=${DATA_API_MACHINE_TYPE} --image-project=ubuntu-os-cloud --image-family=ubuntu-1404-lts --tags=http-server - sleep 30 - fi ## Cleanup staging area before installation - gcloud compute ssh ubuntu@${instance_name} -- sudo bash -e <