Skip to content

Instantly share code, notes, and snippets.

@monkey-codes
Created August 10, 2020 05:59
Show Gist options
  • Select an option

  • Save monkey-codes/ea28df6eae139b1cc4881e924dbdb50b to your computer and use it in GitHub Desktop.

Select an option

Save monkey-codes/ea28df6eae139b1cc4881e924dbdb50b to your computer and use it in GitHub Desktop.
Sonar time machine bash script
#!/bin/bash
SONAR_SERVER="http://localhost:9000"
SONAR_USER="a username"
SONAR_PASSWORD="a secret"
SONAR_PROJECT_NAME="project-name"
SONAR_PROJECT_KEY="project-name"
SONAR_PROJECT_VERSION="1.0"
LCOV_REPORT_PATH="coverage/lcov.info"
COMMITS=$(git log --pretty="%ci %H" | awk '{ print $1,$4}' | awk '{arr[$1]=$2}END{for (a in arr) print a, arr[a]}' | sort )
while read -r p; do
DATE=$(echo $p | cut -f1 -d' ')
COMMIT=$(echo $p | cut -f2 -d' ')
echo "$DATE $COMMIT"
git checkout $COMMIT
./node_modules/.bin/ng test --watch=false --code-coverage
sonar-scanner -Dsonar.host.url="$SONAR_SERVER" -Dsonar.login="$SONAR_USER" \
-Dsonar.password="$SONAR_PASSWORD" \
-Dsonar.projectKey="$SONAR_PROJECT_KEY" \
-Dsonar.projectName="$SONAR_PROJECT_NAME" \
-Dsonar.projectVersion="$SONAR_PROJECT_VERSION" \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.sources=src \
-Dsonar.exclusions=**/node_modules/** \
-Dsonar.tests=src \
-Dsonar.test.inclusions=**/*.spec.ts \
-Dsonar.typescript.lcov.reportPaths="$LCOV_REPORT_PATH" \
-Dsonar.projectDate=$DATE
rm -rf ./coverage
done <<< "$COMMITS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment