Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Github Actions #275

Closed

Conversation

Smolevich
Copy link
Contributor

  • Add support Github actions for collector
  • Add test case

@@ -64,6 +64,7 @@ public function collect(array $env)
->fillAppVeyor()
->fillJenkins()
->fillLocal()
->fillGithubActiions()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: double i

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@Smolevich
Copy link
Contributor Author

Travis build for PHP with version 7.1 failed

> php dev-tools/vendor/bin/phpmd src text build/config/phpmd.xml

/home/travis/build/php-coveralls/php-coveralls/src/Bundle/CoverallsBundle/Command/CoverallsJobsCommand.php:24
The class CoverallsJobsCommand has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.

Script php dev-tools/vendor/bin/phpmd src text build/config/phpmd.xml handling the sca event returned with error code 2

I don't know that it means

@Smolevich
Copy link
Contributor Author

Do we need Github Actions ci file for this PR?

@Smolevich
Copy link
Contributor Author

@keradus, can you review please?

@ADmad
Copy link

ADmad commented Nov 12, 2019

Could the maintainers review / merge this please.

@Smolevich
Copy link
Contributor Author

As I understand this repo has one member - @keradus and judging by the status on the github he is on vacation

@Smolevich
Copy link
Contributor Author

@ADmad you can use this repo for sending events to coveralls.io

@ADmad
Copy link

ADmad commented Nov 12, 2019

Thanks @Smolevich.

leofeyer added a commit to contao/contao that referenced this pull request Nov 12, 2019
…ons (see #963)

Description
-----------

Unfortunately, we have to delay using GitHub actions to generate the coverage reports until php-coveralls/php-coveralls#275 has been addressed.

Commits
-------

88c0c24 Remove the coverage workflow until php-coveralls supports GitHub actions
@leofeyer
Copy link

leofeyer commented Nov 13, 2019

Unfortunately, this does not work for pull requests, because GITHUB_REF is set to refs/remotes/pull/123/merge instead of refs/heads/… (see this log). Then Coveralls will not associate the build with the pull request (see this build) and never report the status back to GitHub.

@keradus
Copy link
Member

keradus commented Nov 20, 2019

hey. exactly, i was on hols. thanks for understanding.

I took care of Travis build for PHP with version 7.1 failed issue on 2.1 branch, please merge/rebase the PR to see it.

@Smolevich, can you please look at @leofeyer concern? thanks!

@Smolevich
Copy link
Contributor Author

hey. exactly, i was on hols. thanks for understanding.

I took care of Travis build for PHP with version 7.1 failed issue on 2.1 branch, please merge/rebase the PR to see it.

@Smolevich, can you please look at @leofeyer concern? thanks!

Ok, i see case @leofeyer. @keradus, What branch should merge in branch for PR?

@Smolevich
Copy link
Contributor Author

@leofeyer, see build

@Smolevich Smolevich force-pushed the add-support-for-github-actions branch from cb09f1c to 42b8068 Compare January 16, 2020 22:39
@Smolevich
Copy link
Contributor Author

@keradus can you review please?

@emmetog
Copy link

emmetog commented Feb 6, 2020

I've tried to test this PR again (instructions here) but it's not working, I believe it's because coveralls doesn't yet handle the "github" service_name.

When I modify this PR branch to hardcode CI_JOB_ID and CI_NAME to null it generates a coveralls.json as follows:

    "service_name": "",
    "service_branch": "my-branch",
    "repo_token": "<<redacted>>",
    "git": {
    ...

this seems to work ☝️

However the PR in its current state creates a coveralls.json like this:

    "service_name": "github",
    "service_job_id": "44727b6d6df5c15b11b26579f72d9b8edd8069a1",
    "service_branch": "my-branch",
    "repo_token": "<<redacted>>",
    "git": {
    ...

which does not work 😞 It fails with the following output:

...
Collect git info
Read environment variables
Dump submitting json file: /path/coveralls.json
File size: 968.15 kB
Submitting to https://coveralls.io/api/v1/jobs
Client error occurred. status: 422 Unprocessable Entity
Couldn't find a repository matching this job.
elapsed time: 2.054 sec memory: 10.00 MB

The official coveralls docs suggest that the service_name and service_job_id are optional, it seems that if these are present and valid then coveralls asks the relevant CI system for additional info to supplement it's analysis.

I suspect it's failing because coveralls doesn't yet recognise the "github" service_name or it's not working yet or something.

Should we set the service name and job ID to be null or not present for the moment until Coveralls handles them correctly?

@simPod
Copy link
Contributor

simPod commented Feb 6, 2020

This works well for me simPod@b9c9d4c I reversed engineered their js implementation and api so I'm setting the same fields as they do.

I don't have BRANCH set. Try it without it.

@Smolevich
Copy link
Contributor Author

@emmetog can i show your test?

@Smolevich
Copy link
Contributor Author

@emmetog
Copy link

emmetog commented Feb 7, 2020

@Smolevich For my test I first set the env vars:

$ export CI_NAME='github'
$ export GITHUB_ACTIONS=1
$ export GITHUB_REF=refs/heads/my-branch
$ export GITHUB_SHA=44727b6d6df5c15b11b26579f72d9b8edd8069a1
$ export COVERALLS_REPO_TOKEN=<<redacted>>
$ export GITHUB_EVENT_NAME=pull_request

Then I run phpunit to generate the clover coverage xml and run coveralls to push them:

$ ./vendor/bin/phpunit --coverage-clover coverage/clover.xml
$ vendor/bin/php-coveralls --coverage_clover coverage/clover.xml --json_path coveralls.json -vvv

I'm using a private GitHub repo. The php-coveralls package in my vendor/ is using this exact PR which can be set up by following the instructions here.

@simPod I tried removing the branch as you suggested but still no joy 😞 Here's the coveralls.json that was generated:

    "service_name": "github",
    "service_job_id": "44727b6d6df5c15b11b26579f72d9b8edd8069a1",
    "repo_token": "<<redacted>>",
    "git": {

Could you add a step in your github-actions file to show the generated /home/runner/work/laravel-mongodb/laravel-mongodb/build/logs/coveralls-upload.json file in that repository that works? Something like this:

      - name: Debug converalls.json
        run: cat /home/runner/work/laravel-mongodb/laravel-mongodb/build/logs/coveralls-upload.json

@Smolevich
Copy link
Contributor Author

@Smolevich For my test I first set the env vars:

$ export CI_NAME='github'
$ export GITHUB_ACTIONS=1
$ export GITHUB_REF=refs/heads/my-branch
$ export GITHUB_SHA=44727b6d6df5c15b11b26579f72d9b8edd8069a1
$ export COVERALLS_REPO_TOKEN=<<redacted>>
$ export GITHUB_EVENT_NAME=pull_request

Then I run phpunit to generate the clover coverage xml and run coveralls to push them:

$ ./vendor/bin/phpunit --coverage-clover coverage/clover.xml
$ vendor/bin/php-coveralls --coverage_clover coverage/clover.xml --json_path coveralls.json -vvv

I'm using a private GitHub repo. The php-coveralls package in my vendor/ is using this exact PR which can be set up by following the instructions here.

@simPod I tried removing the branch as you suggested but still no joy 😞 Here's the coveralls.json that was generated:

    "service_name": "github",
    "service_job_id": "44727b6d6df5c15b11b26579f72d9b8edd8069a1",
    "repo_token": "<<redacted>>",
    "git": {

Could you add a step in your github-actions file to show the generated /home/runner/work/laravel-mongodb/laravel-mongodb/build/logs/coveralls-upload.json file in that repository that works? Something like this:

      - name: Debug converalls.json
        run: cat /home/runner/work/laravel-mongodb/laravel-mongodb/build/logs/coveralls-upload.json

What is the version php-coveralls in composer.json?

@emmetog
Copy link

emmetog commented Feb 7, 2020

Interestingly, setting COVERALLS_RUN_LOCALLY in my github-actions job seems to make everything work (my composer is still locked to this PR branch). in other words:

      - name: Upload coverage results to Coveralls
        run: vendor/bin/php-coveralls --coverage_clover coverage/clover.xml --json_path coveralls.json -vvv
        env:
            COVERALLS_RUN_LOCALLY: 1

From what I've seen this also sets the branch and pull request link details correctly in the coveralls UI. This suggests that the changes which are made when COVERALLS_RUN_LOCALLY=1 are the correct ones for github actions (they work):

        if (isset($this->env['COVERALLS_RUN_LOCALLY']) && $this->env['COVERALLS_RUN_LOCALLY']) {
            $this->env['CI_JOB_ID'] = null;
            $this->env['CI_NAME'] = 'php-coveralls';
            $this->env['COVERALLS_EVENT_TYPE'] = 'manual';
            // ....

@Smolevich
Copy link
Contributor Author

Smolevich commented Feb 7, 2020

Interestingly, setting COVERALLS_RUN_LOCALLY in my github-actions job seems to make everything work (my composer is still locked to this PR branch). in other words:

      - name: Upload coverage results to Coveralls
        run: vendor/bin/php-coveralls --coverage_clover coverage/clover.xml --json_path coveralls.json -vvv
        env:
            COVERALLS_RUN_LOCALLY: 1

From what I've seen this also sets the branch and pull request link details correctly in the coveralls UI. This suggests that the changes which are made when COVERALLS_RUN_LOCALLY=1 are the correct ones for github actions (they work):

        if (isset($this->env['COVERALLS_RUN_LOCALLY']) && $this->env['COVERALLS_RUN_LOCALLY']) {
            $this->env['CI_JOB_ID'] = null;
            $this->env['CI_NAME'] = 'php-coveralls';
            $this->env['COVERALLS_EVENT_TYPE'] = 'manual';
            // ....

See https://github.com/Smolevich/reindexer-client/runs/431760052?check_suite_focus=true
PR Smolevich/reindexer-client#12

@@ -74,9 +74,9 @@ protected function collectBranch()

foreach ($branchesResult as $result) {
if (strpos($result, '* ') === 0) {
$exploded = explode('* ', $result, 2);
preg_match('~^\* (?:\(HEAD detached at )?([\w/]+)\)?~', $result, $matches);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks for branches which have hyphens (-) and other non-word characters in them. This method incorrectly extracts my for the branch name when the full branch name is my-branch for example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Smolevich I'll fix this and send you PR, k?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My branch has hyphen and this code don't break

Copy link

@emmetog emmetog Feb 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(edit: fixed the code of the test)

Here's a test which replicates the problem (feel free to use it in this PR):

    /**
     * @test
     */
    public function shouldParseCaseInsensitive()
    {
        $branches = [
            '  TEST-123',
            '* TEST-456',
            '  TEST-789',
        ];

        $gitCommand = $this->createGitCommandStubWith($branches, $this->getHeadCommitValue, $this->getRemotesValue);

        $object = new GitInfoCollector($gitCommand);

        $result =$object->collect();

        $this->assertEquals('TEST-456', $result->getBranch());
    }

I've seen that github actions checks out the code in detached HEAD (HEAD detached at...) but when running locally it's not detached and it returns TEST instead of TEST-456.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also recovered support for hyphens
#298

@twinh
Copy link
Contributor

twinh commented Jun 14, 2020

Hello, I have merged the PR into my forked repo, added parallel job support, and published a new release, feel free to use it.

https://github.com/twinh/php-coveralls#github-actions

Add a new step after phpunit generate coverage report.

- name: Upload coverage results to Coveralls
  env:
    COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: |
    composer global require twinh/php-coveralls
    php-coveralls --coverage_clover=build/logs/clover.xml -v

$jobId = $githubRef;
}

$this->env['CI_JOB_ID'] = $jobId;
Copy link

@OndraM OndraM Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->env['CI_JOB_ID'] = $jobId;
$this->env['CI_JOB_ID'] = $this->env['GITHUB_RUN_NUMBER'];

$this->env['GITHUB_RUN_NUMBER'] is now available should be used instead of the custom commit hash based value.

https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OndraM maybe, but seems like maintainers ignore this PR and communication with community is broken

@szepeviktor
Copy link
Contributor

szepeviktor commented Sep 28, 2020

@OndraM @keradus Could we somehow support GHA?
It is 1 year old.
https://github.blog/2019-08-08-github-actions-now-supports-ci-cd/

Maybe with #296?

@simPod
Copy link
Contributor

simPod commented Sep 28, 2020

Anyone considering / already migrated to codecov and can share experience?

@szepeviktor
Copy link
Contributor

szepeviktor commented Sep 28, 2020

migrated to codecov

Coveralls is the superior service.
I use and advocate https://github.com/twinh/php-coveralls

@SignpostMarv
Copy link

Anyone considering / already migrated to codecov and can share experience?

they've got a github action for it, works fine.

@ADmad
Copy link

ADmad commented Sep 29, 2020

Anyone considering / already migrated to codecov and can share experience?

They use the GH annotations API so that you get comments on the lines without code coverage on the pull request page itself.

@keradus
Copy link
Member

keradus commented Oct 5, 2020

I merged the extended version of this PR - the #296.

big thanks to work on that!
i kept your co-ownership when merging to master ;)

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

Successfully merging this pull request may close these issues.

None yet