Konubinix' opinionated web of thoughts

Sonar Play Analysis in the Past

Fleeting

In case you want to have a nice activity in sonar in a project, like clk.

For instance guess that you want to run the scans of all the tags. In case you follow the same definition of projectVersion as I do, you might want to reach everycommit just before a tag and scan it. It will be the last analysis of the given version. You will also want to scan the commit of the tag, making it the first analysis of the version. I recommend using to ensure an appropriate analysis history.

Unfortunately, because the projectDate only accepts dates and not hours, I cannot scan the commit prior to the tag and the commit under the tag, because they generally are the same day. The most valuable one, to me, is the last commit of each version, hence I drop the scan of the tag itself.

You might also want to perform an empty analysis at the beginning of the history as a reference point, but that would likely just result in showing a pike (with all the technical debt) at the beginning of the history.

You first have to reset your project and start a brand new one. Then export the appropriate environment variables.

export SONAR_HOST_URL=https://sonarcloud.io ; export SONAR_TOKEN=<youtoken>
TMP="$(mktemp -d)"
trap "rm -rf '${TMP}'" 0

cp sonar-project.properties /tmp

pushd "${TMP}" > /dev/null
{
    cp /tmp/sonar-project.properties ./
    # in clk, just before the first commit, got with git log --format=%cs|sort | head -1
    sonar-scanner -Dsonar.projectDate=2018-04-04
}
popd > /dev/null

scanit ( ) {
    local commitish="$1"
    git checkout .
    git checkout "${commitish}"
    git clean -fd
    cp /tmp/sonar-project.properties ./
    sonar-scanner -Dsonar.projectVersion="$(git tag --sort=creatordate --merged|grep '^v'|tail -1)" -Dsonar.projectDate="$(git log -1 --format=%cs)"
}

git tag | sort -V | while read tag
do
    scanit "${tag}~"
    # scanit "${tag}"
done

scanit main