-
Notifications
You must be signed in to change notification settings - Fork 32
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
Check for open PRs on push
GHA trigger
#234
Comments
Hm, I could be wrong, but either you plan for only people who have write access to the repo to contribute, in which case you don't need the upload-artifact action and the workflow_run, or you plan for external people to contribute, and they won't be able to trigger the The only setup where this would help if I understand correctly would be if you only have write-access contributors, and have only set up your CI for on:
push: to on:
pull_request:
push:
branches:
- "main" So if I understand correctly everything, you'd like to avoid doing the change above, and instead for the action to support PR mode on push. Right ? (I'm really only asking if I understood your problem correctly) |
This is correct 👍 I would like to avoid adding |
Maybe also helpful context: The repository where I use this is a private repo where all contributors have write access |
If you look closely at the example I put above, you'll notice that when adding |
Yep, I caught that, but then that means there's no CI run until a PR is opened.. which might not be ideal Sorry if my use case seems too specific, I guess I am looking for a way to use this action to "build my own workflow" instead of adapting to the workflow suggested by this action. |
I was about to try and start working on that but... If you push to a branch, the pull request may well not exist yet by the time the action finishes, so we can't post a comment to a non-existant PR ? There's always the possibility of posting if there's a PR, and ignoring otherwise. Would that make a good UX ? |
My "workaround" for that right now is the following: name: CI
on:
push:
branches:
- "**"
jobs:
# run all the lengthy and expensive tests and checks
########
reports:
name: reports
runs-on: [self-hosted]
permissions:
pull-requests: write
contents: write
checks: write
if: always()
needs: init
steps:
- name: coverage data
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
###########
# upload coverage file to cloud storage then on PR: name: PR
on:
pull_request:
branches-ignore:
- dependabot/**
jobs:
reports:
name: reports
runs-on: [self-hosted]
needs: [init]
permissions:
checks: write
contents: read
pull-requests: write
steps:
# download coverage assuming ci job is done
####
- name: coverage data
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
ANNOTATE_MISSING_LINES: true |
Ok ! If I were to handle this ticket, what would be your proposed workflow in case the action runs on push, not on the default branch, and there's no PR yet ? And what would happen if we subsequently openned a PR ? From the conversation, my current understanding is that:
As far as I can tell, those 2 statements are incompatible. |
My proposed workflow:
|
The problem with this is the following scenario: You push to the feature branch (the action does nothing) and then open a PR without pushing again. In order for the action to react to this and to post a comment, it needs to be used with a |
Summarizing: I could be wrong but I think @jarojasm95 acknowledged that if no PR is open at push time, then there's nothing we can (nor should) do to have a comment posted once the PR is openned, unless the action is also configured to run on pull_request. @jarojasm95 mentioned the ability to not having to configure the pull_request trigger as a benefit, but it's still necessary to have it unless you're ok with PRs not having the comment (at least until they are re-pushed after the PR was opened). Though I do understand that you may want your own CI steps to run on the first push and not wait until a PR is opened to start running, which leads to the workaround @jarojasm95 posted where the CI runs on push, the action on pull_request, and we need to somehow pass the coverage results between those steps. The problem with that workaround is what happens if the PR is opened right away before the CI finished running. Which is exactly where their proposal makes sense: if the action could post the comment on a push event, then it would work on all cases except when on the initial push where the PR doesn't exist. If the user wants this (pretty important) case covered, they'd need to put a similar workaround where they would store the coverage data, and add a "pull resquest created" workflow just for this case. But at least the problem of this workaround highlighted above would be solved. I think we can support it without it being too complicated, but it will be such a mess to use (due to having to setup the workaround) that I'm not even sure we'd want to advertise this in the doc, or at least more than a couple lines pointing to this ticket. |
Ah okay, I think I understand it now. So in the non-default-branch push event we would store the comment as an artifact and in the PR event we would check if such an artifact already exists and use that if it does. Do I understand that correctly? |
Ah, I was thinking about something much more direct: when running in |
@jarojasm95 Would you mind testing the PR linked above and tell us if it works as expected ? When it runs on a push event that's not on the default branch, ils tries to find the associated PR. If found, it acts as if it had been launched on the PR itself. If not found, it posts the PR comment as an artifact and leaves. |
Hello 👋
I've been successfully using this action for a couple weeks now (it is great 👏 ) - I am opening this issue to suggest an improvement:
When the action is run as part of a
push
it would be great if the action could lookup the open PR that the commit belongs to and post the PR comment there.I think this could simplify the usage of this action by obviating the need for:
pull_request
triggeractions/upload-artifact@v3
workflow_run
trigger(I am not suggesting that the above functionality is removed, only suggesting that we improve the
push
event handling for now, which could make this action easier to use imo)What do you think? If this sounds like an acceptable improvement I would also be willing to work on it 🙂
The text was updated successfully, but these errors were encountered: