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

Update Github Actions support #227

Merged
merged 4 commits into from
Jul 7, 2020
Merged

Conversation

TimoRoth
Copy link
Contributor

@TimoRoth TimoRoth commented Jun 9, 2020

Github Actions, and the coveralls side of support for it, seem to have changed/evolved.
This PR brings coveralls-python in line with the official github action, which is commonly used to finish parallel builds.

Additionally, there is no need to manually provide your repo token anymore (though you still can, so existing setups should not be affected by this), since the native github support takes the automatically provided GITHUB_TOKEN instead, very similar to how things work on Travis.
You do however have to export that GITHUB_TOKEN to an env var in your workflow.yml:

env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

@TimoRoth TimoRoth requested a review from TheKevJames as a code owner June 9, 2020 13:19
@TimoRoth TimoRoth force-pushed the master branch 4 times, most recently from 94044ef to 29f84a9 Compare June 9, 2020 13:36
@TimoRoth
Copy link
Contributor Author

TimoRoth commented Jun 9, 2020

Not sure what to do about that coverage change. The dip seems unrelated to these changes?

@TimoRoth TimoRoth force-pushed the master branch 4 times, most recently from 4094f70 to 8904b1a Compare June 9, 2020 15:54
@TimoRoth
Copy link
Contributor Author

TimoRoth commented Jun 9, 2020

While this appears to be working fine, one issue with it is that it spams the Commit-Status with A TON of results, for every individual partial job.
For example:
OGGM/oggm#1033

They are also all red, because they are below the configured minimum percentage.

But it really only seems to work properly for a parallel build when the flag-name is set. Otherwise it ignores all but one parallel steps.

@TimoRoth TimoRoth force-pushed the master branch 3 times, most recently from 46d8ad3 to dd87892 Compare June 9, 2020 18:52
Copy link
Owner

@TheKevJames TheKevJames left a comment

Choose a reason for hiding this comment

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

@TimoRoth thanks for the contribution, much appreciated!

coveralls/api.py Outdated
Comment on lines 67 to 76
service = self.config.get('service_name') or ''
if self._token_required and service.startswith('github'):
gh_token = os.environ.get('GITHUB_TOKEN')
if gh_token:
self.config['repo_token'] = gh_token
return
raise CoverallsException(
'Running on Github Actions but GITHUB_TOKEN is not set. '
'Add "env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}" to '
'your step config.')
Copy link
Owner

Choose a reason for hiding this comment

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

I think moving this block into load_config_from_github() would help us keep things more encapsulated by service.

coveralls/api.py Outdated

@staticmethod
def load_config_from_github():
service_number = os.environ.get('GITHUB_SHA')
service = 'github'
if 'COVERALLS_REPO_TOKEN' in os.environ:
Copy link
Owner

Choose a reason for hiding this comment

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

Could you modify this line to be if os.environ.get('COVERALLS_REPO_TOKEN'):? I've run into some systems before where foo in os.environ always returns True for unset environment variables (eg. they get set to os.environ[foo] = None).

coveralls/api.py Outdated
if gh_token:
self.config['repo_token'] = gh_token
return
raise CoverallsException(
Copy link
Owner

Choose a reason for hiding this comment

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

Just to be clear with your top-level comment: what happens in the case when GITHUB_TOKEN is unset but COVERALLS_REPO_TOKEN has been provided? Should this check for either-or?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then load_config_from_environment sets config['repo_token'] to it and ensure_token bails out from its very first line checking for that.
Will address the rest tomorrow.

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry, I should have been more clear, what I'd meant to ask was: is that Ok from Github-Actions' perspective? It sounds like both cases work (ie. either token can be used), just want to be sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That depends on the service-name sent to Coveralls it seems. If it's 'github', it can be the Github-Token, if it's not 'github', i.e. the so far used name of 'github-actions', it cannot be the Github-Token.
But the behavior here is wholly undocumented, and just based on testing and guesswork.

Copy link
Owner

Choose a reason for hiding this comment

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

Gotcha, thanks for clarifying!

@TimoRoth TimoRoth force-pushed the master branch 3 times, most recently from 031b9bb to 4b11312 Compare July 1, 2020 23:52
@TimoRoth
Copy link
Contributor Author

TimoRoth commented Jul 2, 2020

I'm not sure why the coverage dropped, and if that's related to these changes at all.
But everything else seems generally.

@MarvinT
Copy link

MarvinT commented Jul 3, 2020

These changes solve my issues. What's blocking this from getting merged?

coveralls/api.py Outdated
'your step config.')
self.config['repo_token'] = gh_token

job = os.environ.get('GITHUB_RUN_NUMBER')
Copy link

Choose a reason for hiding this comment

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

I suggest to use None here instead. GITHUB_RUN_NUMBER is not unique at all, but job is being passed to service_job_id which should be A unique identifier of the job on the service specified by service_name. But GITHUB_RUN_NUMBER isn't unique: A unique number for each run of a particular workflow in a repository. This number begins at 1 for the workflow's first run, and increments with each new run. This number does not change if you re-run the workflow run., it's just a number of the workflow run, it doesn't change for the individual parallel job runs. And there doesn't seem to be any other variable that does identify the individual job run, so our only option is not to pass service_job_id at all and let coveralls generate it itself. I tested that and it works that way.

@@ -68,6 +68,9 @@ All variables:
- ``GITHUB_REF``
- ``GITHUB_SHA``
- ``GITHUB_HEAD_REF``
- ``GITHUB_RUN_ID``
- ``GITHUB_RUN_NUMBER``
Copy link

@liskin liskin Jul 5, 2020

Choose a reason for hiding this comment

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

Don't forget to remove this (and from the tests as well) if we confirm that it really is unnecessary. Thanks! :-)

@TimoRoth TimoRoth force-pushed the master branch 2 times, most recently from 6697680 to 92775f1 Compare July 5, 2020 14:41
@TimoRoth TimoRoth force-pushed the master branch 6 times, most recently from e929368 to 9068caa Compare July 5, 2020 18:03
@TimoRoth
Copy link
Contributor Author

TimoRoth commented Jul 5, 2020

I decided that their official action was just broken, and implemented the functionality myself.
This appears to work fine. You do however still have to set the flag name. Otherwise multiple runs of the same Workflow pile up more and more jobs.

@liskin
Copy link

liskin commented Jul 6, 2020

@TimoRoth Where are you testing this? I tried replacing the official action with a curl and the result was still the same: no commit status from coveralls. :-(

  coveralls-finished:
    needs: tests
    runs-on: ubuntu-latest
    steps:
      - name: Finished
        run: |
          set -ex -o pipefail
          curl -v https://coveralls.io/webhook -d "repo_token=${GITHUB_TOKEN}&repo_name=${GITHUB_REPOSITORY}&payload[build_num]=${GITHUB_RUN_ID}&payload[status]=done"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

@liskin
Copy link

liskin commented Jul 6, 2020

It seems my issue with no commit status was caused by me not having "claimed" the repo on coveralls. After doing that, it seems to work fine even with the official github action (which does the same thing as my curl). I'm still not setting the flag name to prevent commit statuses of individual coverage runs, I don't mind the piling up of jobs: that only happens if I manually re-run the workflow, which I only ever do for intermittent test failures, and these should be rare anyway.

coveralls/api.py Outdated
'your step config.')
self.config['repo_token'] = gh_token

number = os.environ.get('GITHUB_RUN_NUMBER')
Copy link

Choose a reason for hiding this comment

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

This should really be GITHUB_RUN_ID in case anyone wants multiple different github actions workflows reporting to coveralls. Also, using GITHUB_RUN_ID makes it possible to use https://github.com/marketplace/actions/coveralls-github-action to finalize the parallel build.

Basically, neither of the two is unique enough to be used as job, but GITHUB_RUN_ID is better to identify the build (workflow run), as it's used in github actions URLs, etc.

@TimoRoth
Copy link
Contributor Author

TimoRoth commented Jul 6, 2020

I opted for the RUN_NUMBER because it gives way more meaningful numbers on the builds, rather than super large mostly arbitrary IDs.
But yeah, if you have multiple independent workflows submitting coverage, they'd inevitably collide at some point.

Makes me wonder if setting the build_number to something like "${GITHUB_WORKFLOW}-${GITHUB_RUN_NUMBER}" would be nicer.

@liskin
Copy link

liskin commented Jul 6, 2020

Makes me wonder if setting the build_number to something like ${GITHUB_WORKFLOW}-${GITHUB_RUN_NUMBER}" would be nicer.

Something like workflow-#123 might be nicer, but I'd still prefer to keep compatibility with the official action performing parallel-finished. Especially if this is purely cosmetic.

@TimoRoth
Copy link
Contributor Author

TimoRoth commented Jul 6, 2020

The official action is clearly broken, given that it submits GITHUB_RUN_ID as service_job_id, which makes no sense if the job_id is really supposed to be unique for the individual jobs.
Which is why I decided to ignore that action and implemented "coveralls --finish".

liskin added a commit to liskin/taskwiki that referenced this pull request Jul 6, 2020
Primary motivation for this is speed: GitHub Actions doesn't limit the
number of concurrent jobs to 4, and also provides a docker registry
(GitHub Packages) that we can use to cache the image (building the image
takes cca 5 minutes, fetching it would take less than 10 seconds). This
is done in another commit.

The workflow definition is a bit more complicated because coveralls
support for GitHub Actions is less mature than for Travis CI, so we need
to manually tell coveralls that all parallel builds have finished and
that it can publish the combined result. Also, coveralls-python support
is work-in-progress
(TheKevJames/coveralls-python#227) so I've
tagged a working snapshot of that PR in my fork. Once it's in a released
version of coveralls-python I'll switch to it.
@TheKevJames
Copy link
Owner

@TimoRoth thanks for the awesome contribution -- this is looking pretty good to me; I'm going to merge it, run a few more tests, and get it released right away. Really appreciate all the work put into this! Getting --finish implemented will make life a bit simpler :)

@liskin thanks for volunteering some code review time, much appreciate the extra eyes on this!

@MarvinT no blockers, just needed to find some time in my day for OSS work. Sorry for any delays!

@TheKevJames TheKevJames merged commit f597109 into TheKevJames:master Jul 7, 2020
@TheKevJames
Copy link
Owner

This is now live on PyPI as v2.1.0 -- Conda release will happen shortly.

MarvinT added a commit to MarvinT/ponyo that referenced this pull request Jul 9, 2020
ajlee21 added a commit to greenelab/ponyo that referenced this pull request Jul 17, 2020
* add coverage configuration

* yaml whitespace fixes

* remove coveralls app and use python-coveralls

* use full conda path to call coveralls

* test-requirements.txt

* CI_BRANCH env var

* GITHUB_TOKEN env variable

* try python-coveralls PR?

* pip install -e .

* Update test-requirements.txt

TheKevJames/coveralls-python#227 was merged

* Update test-requirements.txt

* fix typo

* -e

* add badge

Co-authored-by: ajlee21 <alexjlee.21@gmail.com>
fniephaus added a commit to hpi-swa/smalltalkCI that referenced this pull request Aug 6, 2020
- Align behavior with coveralls-python (see [1])
- Provide `service_number` if run on GitHub Actions (see [2])
- Add support for custom `flag_name`
- Provide `service_pull_request` if possible

[1] https://github.com/coveralls-clients/coveralls-python/blob/30e4815169b3db2616981939d55d2f4495816821/coveralls/api.py#L73-L146
[2] TheKevJames/coveralls-python#227
vamega added a commit to vamega/Box that referenced this pull request Oct 27, 2020
The environment varialbe that needs to set seems to have changed as of this
PR [1]

[1] TheKevJames/coveralls-python#227
vamega added a commit to vamega/Box that referenced this pull request Oct 27, 2020
The environment variable that needs to set seems to have changed as of [this PR][1]

[1]: TheKevJames/coveralls-python#227
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.

4 participants