Skip to content

Commit 17b01fd

Browse files
authored
Merge pull request #200 from stronk7/coveralls_fix
Bump to php-coveralls/php-coveralls v2
2 parents 1f47398 + 965270a commit 17b01fd

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

docs/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
99
The format of this change log follows the advice given at [Keep a CHANGELOG](http://keepachangelog.com).
1010

1111
## [Unreleased]
12+
### Fixed
13+
- Updated to `php-coveralls/php-coveralls` v2 for uploading coverage results to [Coveralls](https://coveralls.io) with the `coveralls-upload` command.
14+
- ACTION REQUIRED: Review any use of the `coveralls-upload` command in GHA and ensure that `COVERALLS_REPO_TOKEN` is set in the environment. See [Coveralls integration](https://github.com/moodlehq/moodle-plugin-ci/blob/master/docs/CodeCoverage.md#coveralls-integration) for more information.
1215

1316
## [3.4.4] - 2023-01-20
1417
### Changed

docs/CodeCoverage.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Code coverage will now automatically fallback between `pcov` => `xdebug` => `php
1010

1111
The way you generate code coverage is to use one of the coverage options on the `phpunit` command. The currently
1212
available options are `--coverage-text` and `--coverage-clover`. The easiest way to start generating code coverage
13-
is to use the text option as that gets printed in the Travis CI logs. Example:
13+
is to use the text option as that gets printed in the CI logs. Example:
1414

1515
```yaml
1616
script:
@@ -42,9 +42,24 @@ If you would like to use Coveralls, then go to https://coveralls.io and login wi
4242
need to authorize access to your public repositories. Once you have done that, navigate to your
4343
[REPOS](https://coveralls.io/repos) listing and use the _ADD REPOS_ button in the upper right to turn on your project.
4444

45-
Then, you need to make the following changes to your plugin's `.travis.yml` file. You need to tell the `phpunit`
46-
command to generate clover coverage and then use the `coveralls-upload` command to actually upload the coverage.
47-
Example:
45+
Then, you need to instruct to your favourite CI tool, so the `phpunit` command generates the clover coverage file and, then, use the `coveralls-upload` command to actually upload the coverage.
46+
47+
Some examples follow:
48+
49+
#### GitHub Actions
50+
51+
```yaml
52+
- name: PHPUnit tests
53+
if: ${{ always() }}
54+
run: |
55+
moodle-plugin-ci phpunit --coverage-clover
56+
moodle-plugin-ci coveralls-upload
57+
env:
58+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
```
60+
Note that, instead of the automatically generated for every run `${{ secrets.GITHUB_TOKEN }}` token you can use any other GitHub token (PAT...) with the correct perms or, also, the token that Coveralls offers to you for every repository. Just it's easier to use the automatic GitHub one, because that way you don't need to create tokens or secrets manually and maintain them.
61+
62+
#### Travis
4863

4964
```yaml
5065
script:
@@ -61,4 +76,4 @@ will be updated with a new coverage report.
6176

6277
**Tips on troubleshooting:** if you are having problems with sending coverage to Coveralls, do not forget that you
6378
can expand the `coveralls-upload` line in the Travis CI logs where there might be some details as to why. Also don't
64-
forget that coverage is only generated for PHP7 or later and this applies to the Coveralls integration as well.
79+
forget that coverage is only generated for PHP7 or later and this applies to the Coveralls integration as well.

src/Command/CoverallsUploadCommand.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
5151
return 0;
5252
}
5353

54-
$process = new Process('composer create-project -n --no-dev --prefer-dist satooshi/php-coveralls _php_coveralls ^1', $this->plugin->directory);
55-
$this->execute->mustRun($process);
56-
5754
$filesystem = new Filesystem();
55+
56+
// Only if it has not been installed before.
57+
if (!$filesystem->exists($this->plugin->directory.'/coveralls')) {
58+
$process = new Process('composer create-project -n --no-dev --prefer-dist php-coveralls/php-coveralls coveralls ^2', $this->plugin->directory);
59+
$this->execute->mustRun($process);
60+
}
61+
5862
$filesystem->copy($coverage, $this->plugin->directory.'/build/logs/clover.xml');
5963

60-
$process = $this->execute->passThrough('_php_coveralls/bin/coveralls -v', $this->plugin->directory);
64+
$process = $this->execute->passThrough('coveralls/bin/php-coveralls -v', $this->plugin->directory);
6165

6266
return $process->isSuccessful() ? 0 : 1;
6367
}

0 commit comments

Comments
 (0)