From 33a268ad868ece7ccf21e119f8ffa6c7e5f6c650 Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Mon, 12 Nov 2018 22:57:53 +0800 Subject: [PATCH 1/5] Adding Makefile to the project --- Makefile | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Makefile 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* From 947d5e7a9e8ff1298302909d256f0024da58a6a4 Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Mon, 12 Nov 2018 22:57:55 +0800 Subject: [PATCH 2/5] Adding config file for v2 --- .circleci/config.yml | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..2c10470 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,51 @@ +# Javascript Node CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-javascript/ for more details +# +version: 2 +jobs: + build: + docker: + # specify the version you desire here + - 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/ + # - image: circleci/mongo:3.4.4 + + working_directory: ~/node-cache-manager-redis + + 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: Linting + command: make lint + + - run: + name: Testing + command: make cover + + - run: + name: Sonar analysis + command: sudo make sonar From c915d2235fd57e2c3d9365029a1ef30336235abf Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Mon, 12 Nov 2018 23:04:52 +0800 Subject: [PATCH 3/5] Deleting sonar.project.version --- sonar-project.properties | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 sonar-project.properties 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 From 809f2016afed9925e0f1b810ae16e347d8348042 Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Sun, 18 Nov 2018 15:45:07 +0800 Subject: [PATCH 4/5] Adding workflow, second job with java image to run sonar correctly --- .circleci/config.yml | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2c10470..f8666df 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,6 @@ version: 2 jobs: build: docker: - # specify the version you desire here - image: circleci/node:8.9 # Specify service dependencies here if necessary @@ -15,37 +14,41 @@ jobs: # - image: circleci/mongo:3.4.4 working_directory: ~/node-cache-manager-redis - 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 + - v1-dependencies # fallback to using the latest cache if no exact match is found - run: - name: Install dependencies + name: Installing dependencies command: make deps - - save_cache: paths: - node_modules key: v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }} - - - run: - name: Linting - command: make lint - - run: name: Testing - command: make cover + command: make test + sonarqube: + docker: + - image: circleci/openjdk:8-jdk-browsers + steps: + - checkout - run: name: Sonar analysis - command: sudo make sonar + command: make sonar +workflows: + version: 2 + build_and_test: + jobs: + - build + - sonarqube: + requires: + - build From 90398ca70aae0fc0b26ba9d06d199458cbd8a617 Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Tue, 20 Nov 2018 15:50:40 +0800 Subject: [PATCH 5/5] Adding secondary job for sonar to run his analysis and report coverage on his dashboard --- .circleci/config.yml | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f8666df..2bc76bc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,50 +5,71 @@ 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/ - # - image: circleci/mongo:3.4.4 - - working_directory: ~/node-cache-manager-redis steps: - checkout - run: - name: install make + 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 }} - - v1-dependencies # fallback to using the latest cache if no exact match is found + # fallback to using the latest cache if no exact match is found + - v1-dependencies - run: - name: Installing dependencies + name: Install dependencies command: make deps - save_cache: paths: - node_modules key: v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }} - run: - name: Testing + 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