diff --git a/.github/workflows/tests-unit-js.yml b/.github/workflows/tests-unit-js.yml index e6725c18d..448e0d1e6 100644 --- a/.github/workflows/tests-unit-js.yml +++ b/.github/workflows/tests-unit-js.yml @@ -25,9 +25,14 @@ on: type: string NODE_OPTIONS: description: Space-separated list of command-line Node options. - type: string default: '' required: false + type: string + CODECOV_FLAGS: + description: Flags to be passed to Codecov. + default: 'unittests' + required: false + type: string secrets: NPM_REGISTRY_TOKEN: description: Authentication for the private npm registry. @@ -44,6 +49,9 @@ on: ENV_VARS: description: Additional environment variables as a JSON formatted object. required: false + CODECOV_TOKEN: + description: Codecov token. + required: false jobs: tests-unit-js: @@ -118,4 +126,18 @@ jobs: run: ${{ format('{0} {1}', inputs.PACKAGE_MANAGER, env.ARGS) }} - name: Run Jest - run: ./node_modules/.bin/jest ${{ inputs.JEST_ARGS }} + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + run: | + COVERAGE_ARGS="" + [ -n "$CODECOV_TOKEN" ] && COVERAGE_ARGS="--coverage" + ./node_modules/.bin/jest $COVERAGE_ARGS ${{ inputs.JEST_ARGS }} + + - name: Upload coverage to Codecov + if: ${{ hashFiles('coverage/lcov.info') != '' }} + uses: codecov/codecov-action@v6 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage/lcov.info + flags: ${{ inputs.CODECOV_FLAGS }} + verbose: true diff --git a/.github/workflows/tests-unit-php.yml b/.github/workflows/tests-unit-php.yml index c91911ab4..1efae1c61 100644 --- a/.github/workflows/tests-unit-php.yml +++ b/.github/workflows/tests-unit-php.yml @@ -23,6 +23,11 @@ on: default: '--coverage-text' required: false type: string + CODECOV_FLAGS: + description: Flags to be passed to Codecov. + default: 'unittests' + required: false + type: string secrets: COMPOSER_AUTH_JSON: description: Authentication for privately hosted packages and repositories as a JSON formatted object. @@ -30,6 +35,9 @@ on: ENV_VARS: description: Additional environment variables as a JSON formatted object. required: false + CODECOV_TOKEN: + description: Codecov token. + required: false jobs: tests-unit-php: @@ -67,4 +75,18 @@ jobs: composer-options: ${{ inputs.COMPOSER_ARGS }} - name: Run PHPUnit - run: ./$(composer config bin-dir)/phpunit ${{ inputs.PHPUNIT_ARGS }} + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + run: | + COVERAGE_ARGS="" + [ -n "$CODECOV_TOKEN" ] && COVERAGE_ARGS="--coverage-clover coverage.xml" + ./$(composer config bin-dir)/phpunit $COVERAGE_ARGS ${{ inputs.PHPUNIT_ARGS }} + + - name: Upload coverage to Codecov + if: ${{ hashFiles('coverage.xml') != '' }} + uses: codecov/codecov-action@v6 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.xml + flags: ${{ inputs.CODECOV_FLAGS }} + verbose: true diff --git a/docs/js.md b/docs/js.md index ac95421d5..649470150 100644 --- a/docs/js.md +++ b/docs/js.md @@ -27,6 +27,7 @@ jobs: | `NPM_REGISTRY_DOMAIN` | `'https://npm.pkg.github.com/'` | Domain of the private npm registry | | `NODE_VERSION` | `18` | Node version with which the unit tests are to be executed | | `JEST_ARGS` | `'--reporters=default --reporters=github-actions'` | Set of arguments passed to Jest | +| `CODECOV_FLAGS` | `'unittests'` | Flags to be passed to Codecov | **Note**: The default `github-actions` reporter requires Jest 28 or higher. @@ -39,6 +40,7 @@ jobs: | `GITHUB_USER_NAME` | Username for the GitHub user configuration | | `GITHUB_USER_SSH_KEY` | Private SSH key associated with the GitHub user passed as `GITHUB_USER_NAME` | | `ENV_VARS` | Additional environment variables as a JSON formatted object | +| `CODECOV_TOKEN` | Codecov token | **Example with configuration parameters:** @@ -53,9 +55,11 @@ jobs: NPM_REGISTRY_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }} ENV_VARS: >- [{"name":"EXAMPLE_USERNAME", "value":"${{ secrets.USERNAME }}"}] + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: NODE_VERSION: 14 - JEST_ARGS: 'my-test --reporters=jest-junit --coverage' + JEST_ARGS: 'my-test --reporters=jest-junit' + CODECOV_FLAGS: 'js' ``` ## Static analysis JavaScript diff --git a/docs/php.md b/docs/php.md index 68991f832..c63a72c69 100644 --- a/docs/php.md +++ b/docs/php.md @@ -153,6 +153,7 @@ jobs: | `PHP_EXTENSIONS` | `''` | PHP extensions supported by shivammathur/setup-php to be installed or disabled | | `COMPOSER_ARGS` | `'--prefer-dist'` | Set of arguments passed to Composer | | `PHPUNIT_ARGS` | `'--coverage-text'` | Set of arguments passed to PHPUnit | +| `CODECOV_FLAGS` | `'unittests'` | Flags to be passed to Codecov | #### Secrets @@ -160,6 +161,7 @@ jobs: |----------------------|------------------------------------------------------------------------------------------| | `COMPOSER_AUTH_JSON` | Authentication for privately hosted packages and repositories as a JSON formatted object | | `ENV_VARS` | Additional environment variables as a JSON formatted object | +| `CODECOV_TOKEN` | Codecov token | **Example with configuration parameters:** @@ -174,9 +176,12 @@ jobs: matrix: php: [ "8.1", "8.2", "8.3" ] uses: inpsyde/reusable-workflows/.github/workflows/tests-unit-php.yml@main + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: PHP_VERSION: ${{ matrix.php }} - PHPUNIT_ARGS: '--coverage-text --debug' + PHPUNIT_ARGS: '--coverage-text' + CODECOV_FLAGS: 'php' ``` ## Lint PHP