javamavencode-coveragetravis-cicoveralls

How do I Integrate Coveralls to An Open-Source Project?


I want to contribute to an open-source project (specifically, this one) where the project owner has already set up Travis. I want to integrate Coveralls to this project and send a pull-request. When I own the project, the process is simple:

However, I've got problems with that when I do not own the repository.

So my questions are:

Thanks in advance.


Environment


Solution

  • You might want to modify your own pom.xml according to the coverage tool you'd like to use see https://github.com/trautonen/coveralls-maven-plugin for some explanation.

    You can avoid to put the repo token in the pom.xml file that you publish on github!

    Instead you can run the coverage report from the command line.

    Here is a small helper script that will allow to run converalls from the command line. Just put your token in a place like $HOME/.coveralls or any similar location.

    #!/bin/bash
    # WF 2019-06-26
    # create test coverage report for coveralls
    tokenpath=$HOME/.coveralls/coveralls.token
    if [ ! -f $tokenpath ]
    then
      echo "Script needs coveralls token in $tokenpath to work" 1>&2
      echo "Script can only be run successfully by project admins" 1>&2
      echo "see https://github.com/trautonen/coveralls-maven-plugin" 1>&2
      exit 1
    else
      token=$(cat $tokenpath)
      # comment out to use jacoco
      #mvn clean test jacoco:report coveralls:report -D jacoco=true -DrepoToken=$token
      # comment out to use cobertura
      mvn cobertura:cobertura coveralls:report -DrepoToken=$token
    fi
    

    Update Here is a version using the COVERALLS_TOKEN environment variable:

    #!/bin/bash
    # WF 2019-06-26
    # create test coverage report for coveralls
    
    # is the environment variable not set?
    if [ "$COVERALLS_TOKEN" = "" ]
    then
      tokenpath=$HOME/.dukes/coveralls.token
      if [ ! -f $tokenpath ]
      then
        echo "Script needs coveralls token in $tokenpath to or COVERALLS_TOKEN environment variable to work" 1>&2
        echo "Script can only be run successfully by project admins" 1>&2
        echo "see https://github.com/trautonen/coveralls-maven-plugin" 1>&2
        echo "see https://stackoverflow.com/a/56815300/1497139" 1>&2
        exit 1
      fi
    else
      export COVERALLS_TOKEN=$(cat $tokenpath)
    fi
    # the jacoco variable tries triggering a profile - check your pom.xml
    # for any profile being in use
    mvn clean test jacoco:report coveralls:report -D jacoco=true
    #mvn clean test jacoco:report coveralls:report -D jacoco=true -DrepoToken=$token
    #mvn cobertura:cobertura coveralls:report
    #mvn cobertura:cobertura coveralls:report -DrepoToken=$COVERALLS_TOKEN