Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate circleci v1 to v2 #86

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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*
9 changes: 9 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -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