-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Conversation
94044ef
to
29f84a9
Compare
Not sure what to do about that coverage change. The dip seems unrelated to these changes? |
4094f70
to
8904b1a
Compare
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. 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. |
46d8ad3
to
dd87892
Compare
There was a problem hiding this 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
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.') |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, thanks for clarifying!
031b9bb
to
4b11312
Compare
I'm not sure why the coverage dropped, and if that's related to these changes at all. |
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') |
There was a problem hiding this comment.
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.
docs/usage/tox.rst
Outdated
@@ -68,6 +68,9 @@ All variables: | |||
- ``GITHUB_REF`` | |||
- ``GITHUB_SHA`` | |||
- ``GITHUB_HEAD_REF`` | |||
- ``GITHUB_RUN_ID`` | |||
- ``GITHUB_RUN_NUMBER`` |
There was a problem hiding this comment.
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! :-)
6697680
to
92775f1
Compare
e929368
to
9068caa
Compare
I decided that their official action was just broken, and implemented the functionality myself. |
@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. :-(
|
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') |
There was a problem hiding this comment.
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.
I opted for the RUN_NUMBER because it gives way more meaningful numbers on the builds, rather than super large mostly arbitrary IDs. Makes me wonder if setting the build_number to something like "${GITHUB_WORKFLOW}-${GITHUB_RUN_NUMBER}" would be nicer. |
Something like |
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. |
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.
@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 @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! |
This is now live on PyPI as v2.1.0 -- Conda release will happen shortly. |
* 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>
- 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
The environment varialbe that needs to set seems to have changed as of this PR [1] [1] TheKevJames/coveralls-python#227
The environment variable that needs to set seems to have changed as of [this PR][1] [1]: TheKevJames/coveralls-python#227
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: