Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Add Codecov support (alternative to Coveralls) #153

Open
westonruter opened this issue Mar 14, 2016 · 2 comments
Open

Add Codecov support (alternative to Coveralls) #153

westonruter opened this issue Mar 14, 2016 · 2 comments

Comments

@westonruter
Copy link
Contributor

See #152 (comment) from @ocean90:

Well, coveralls works without the src_dir value, but I agree that codecov looks much better.

Maybe provide a flag do decide which service should be used for coverage?

Example Project: https://codecov.io/github/WP-API/WP-API?branch=develop
Example Config: https://github.com/codecov/example-php/blob/master/.travis.yml

@ocean90
Copy link
Contributor

ocean90 commented Mar 14, 2016

Some relevant lines about the current implementation for Coveralls:

  • can_generate_coverage_clover():

    wp-dev-lib/check-diff.sh

    Lines 319 to 328 in f95a6e9

    function can_generate_coverage_clover {
    if [ -e .coveralls.yml ] && [ -e composer.json ] && ! grep -sqi 'coverage' <<< "$DEV_LIB_SKIP"; then
    if min_php_version "5.5.0" && cat composer.json | grep -Eq '"satooshi/php-coveralls"\s*:\s*"dev-master"'; then
    return 0
    elif min_php_version "5.3.0" && cat composer.json | grep -Eq '"satooshi/php-coveralls"\s*:\s*"~1.0"'; then
    return 0
    fi
    fi
    return 1
    }
    • Checks whether .coveralls.yml and composer.json with satooshi/php-coveralls exists
  • coverage_clover():

    wp-dev-lib/check-diff.sh

    Lines 330 to 334 in f95a6e9

    function coverage_clover {
    if can_generate_coverage_clover; then
    echo --coverage-clover build/logs/clover.xml
    fi
    }
    • Prints --coverage-clover build/logs/clover.xml if can_generate_coverage_clover() is true
  • travis.after_script.sh: https://github.com/xwp/wp-dev-lib/blob/f95a6e9e60fc261af655be929cee637e93149f41/travis.after_script.sh
    • Pushes data to Coveralls

What Codecov needs is the cover.xml file and the push to codecov.io. For GlotPress I've implemented this via https://github.com/GlotPress/GlotPress-WP/blob/develop/.travis.yml#L39-L43 and https://github.com/GlotPress/GlotPress-WP/blob/develop/phpunit.xml.dist#L28-L30.

It looks like can_generate_coverage_clover() can be used for both. Something like the following might work:

check-diff.sh:

# Flag
COVERAGE_SERVICE=${COVERAGE_SERVICE:-coveralls}

function can_generate_coverage_clover {
    if [ "$COVERAGE_SERVICE" == 'coveralls' ] && [ -e .coveralls.yml ] && [ -e composer.json ] && ! grep -sqi 'coverage' <<< "$DEV_LIB_SKIP"; then
        if min_php_version "5.5.0" && cat composer.json | grep -Eq '"satooshi/php-coveralls"\s*:\s*"dev-master"'; then
            return 0
        elif min_php_version "5.3.0" && cat composer.json | grep -Eq '"satooshi/php-coveralls"\s*:\s*"~1.0"'; then
            return 0
        fi
    elif  [ "$COVERAGE_SERVICE" == 'codecov' ] ; then
        return 1
    fi
    return 0
}

travis.after_script.sh:

if can_generate_coverage_clover && [ -s "$TEMP_DIRECTORY/paths-scope-php" ] && [ -n "$PHPUNIT_COVERAGE_DIR" ]; then
    if [ "$COVERAGE_SERVICE" == 'coveralls' ]; then
        cd "$PHPUNIT_COVERAGE_DIR"
        php vendor/bin/coveralls -vvv
        cd - > /dev/null
    elif  [ "$COVERAGE_SERVICE" == 'codecov' ] ; then
        bash <(curl -s https://codecov.io/bash) -f "$PHPUNIT_COVERAGE_DIR/build/logs/clover.xml"
    fi
fi

@ocean90
Copy link
Contributor

ocean90 commented Mar 30, 2016

generate-markdown-readme needs to be updated as well to show the correct badge.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants