-
Notifications
You must be signed in to change notification settings - Fork 366
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
[CI]add a workflow to cancel previous running workflow #2279
Conversation
name: Cancel Workflows | ||
on: | ||
workflow_run: | ||
workflows: ["Go", "Golicense", "Kind", "Build and push latest image if needed", "Antrea upgrade"] | ||
types: | ||
- requested |
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'm reading the webpage you shared: https://github.com/styfle/cancel-workflow-action#advanced-pull-requests-from-forks. I see the following:
Therefore, a special setup using workflow_run, which also works for push, is needed
Can you make sure that workflows triggered by push events to the main branch are never cancelled. In other words, let's only cancel workflows which are triggered by pull request events. In case of regression, it is useful to have the full workflow "history" for the main branch to detect which merge caused the regression. I'd rather keep pushing the Docker image to the registry for every push to main as well.
I think something like this would work:
jobs:
cancel:
name: Cancel workflows
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request' }}
steps:
- uses: styfle/cancel-workflow-action@0.9.0
with:
workflow_id: ${{ github.event.workflow.id }}
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.
sure, after verify a similar job in a sample repo, it will indeed also cancel the workflow triggered by merge, I will check how to make it to work on pull_request and push on non-main branch only
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.
@antoninbas I just verified the code you provided is correct, which can help to skip cancel workflows in main stream. and those actions triggered by forks PR can be cancelled as well, and the push on fork branch, I guess I misunderstood it, looks like all the workflows are triggered by PR from fork repo only in antrea repo, so no need to worry about the push on fork branch. I just updated the code. please check. thanks.
add a cancel workflow so when there is a new PR or push previous workflow will be cancelled which will help to reduce concurrent github runner usage. refer to https://github.com/styfle/cancel-workflow-action#advanced-pull-requests-from-forks according to github page [here](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_run) this file has to be in default branch to take affect. Signed-off-by: Lan Luo <luola@vmware.com>
9e6335a
to
93b90ff
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.
LGTM
I'll monitor to check if it breaks anything
/skip-all |
@luolanzone we may have to look into https://github.com/styfle/cancel-workflow-action#advanced-all-but-latest. I'm not sure how effective this will be in its current form, given that the cancel workflow may not be able to run if the pipeline is saturated (we do have a lot of different workflows, and only a fixed number of them can run at a given time). |
@antoninbas you are right, I think current solution will only cancel running workflows, is OK to use "all but latest"? if yes, I will verify the usage and submit a new PR later. |
I don't see an issue with using "all but latest" but I'm just going by the documentation. I didn't test it or researched it. |
add a cancel workflow so when there is a new push
previous workflow will be cancelled which will help to reduce
concurrent github runner usage and reduce unnecessary waiting time.
refer to https://github.com/styfle/cancel-workflow-action#advanced-pull-requests-from-forks
according to github page here
this file has to be in default branch first to take affect.
this is a part of issue #2014
Signed-off-by: Lan Luo luola@vmware.com