diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..2bc76bc --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,75 @@ +# Javascript Node CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-javascript/ for more details +# +version: 2 +jobs: + build: + working_directory: ~/node-cache-manager-redis + docker: + - image: circleci/node:8.9 + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + steps: + - checkout + - run: + name: Install make + command: sudo apt-get update && sudo apt-get -y install gcc make + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }} + - v1-dependencies-{{ .Branch }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies + - run: + name: Install dependencies + command: make deps + - save_cache: + paths: + - node_modules + key: v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }} + - run: + name: Test project + command: make test + + # Special step used to persist a temporary file to be used by another job in the workflow + - persist_to_workspace: + root: ~/node-cache-manager-redis + paths: + - coverage + + sonarqube: + working_directory: ~/node-cache-manager-redis + docker: + # Sonarqube need OpenJDK 8 to run his analysis correctly + - image: circleci/openjdk:8-jdk-browsers + steps: + - checkout + # Special step used to attach the workflow’s workspace to the current container + # Retrieve coverage's folder for sonarqube + - attach_workspace: + at: ~/node-cache-manager-redis + + # Sonarqube need to have node installed to run his analysis + - run: + name: Install node + command: | + sudo apt install curl + curl -sL https://deb.nodesource.com/setup_10.x | sudo bash - + sudo apt install nodejs + - run: + name: Sonar analysis + command: make sonar + +workflows: + version: 2 + build_and_test: + jobs: + - build + - sonarqube: + # sonarqube's job waiting for build's job before to run + requires: + - build diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8f56f92 --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +.PHONY: test + +run: + npm start + +deps: + npm install + +lint: + npm run lint + +test: + npm run test + +cover: + npm run cover + +sonar: + sed '/sonar.projectVersion/d' ./sonar-project.properties > tmp && mv tmp sonar-project.properties + echo sonar.projectVersion=`cat package.json | python -c "import json,sys;obj=json.load(sys.stdin);print obj['version'];"` >> sonar-project.properties + wget https://s3.eu-central-1.amazonaws.com/dialonce-cdn/utilities/sonar-scanner-cli.zip + unzip sonar-scanner-* +ifdef CIRCLE_PULL_REQUEST + @sonar-scanner/bin/sonar-scanner -e -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=${shell basename $(CIRCLE_PULL_REQUEST)} -Dsonar.github.repository=$(REPO_SLUG) -Dsonar.github.oauth=$(GITHUB_TOKEN) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) -Dsonar.host.url=$(SONAR_HOST_URL) +endif +ifeq ($(CIRCLE_BRANCH),develop) + @sonar-scanner/bin/sonar-scanner -e -Dsonar.analysis.mode=publish -Dsonar.host.url=$(SONAR_HOST_URL) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) +endif + rm -rf sonar-scanner* diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..c032933 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,9 @@ +sonar.projectKey=node-cache-manager-redis +sonar.projectName=node-cache-manager-redis + +sonar.sources=index.js +sonar.tests=test + +sonar.dynamicAnalysis=reuseReports +sonar.javascript.jstest.reportsPath=coverage +sonar.javascript.lcov.reportPaths=coverage/lcov.info