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

[CI]add a workflow to cancel previous running workflow #2279

Merged
merged 1 commit into from
Jun 17, 2021

Conversation

luolanzone
Copy link
Contributor

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

Comment on lines +1 to +6
name: Cancel Workflows
on:
workflow_run:
workflows: ["Go", "Golicense", "Kind", "Build and push latest image if needed", "Antrea upgrade"]
types:
- requested
Copy link
Contributor

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 }}

Copy link
Contributor Author

@luolanzone luolanzone Jun 17, 2021

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

Copy link
Contributor Author

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>
@luolanzone luolanzone changed the title add a workflow to cancel previous running workflow [CI]add a workflow to cancel previous running workflow Jun 17, 2021
Copy link
Contributor

@antoninbas antoninbas left a 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

@antoninbas
Copy link
Contributor

/skip-all

@antoninbas antoninbas merged commit 42077cb into antrea-io:main Jun 17, 2021
@antoninbas
Copy link
Contributor

@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).

@luolanzone
Copy link
Contributor Author

@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.

@luolanzone luolanzone deleted the cancel-workflows branch June 18, 2021 00:53
@antoninbas
Copy link
Contributor

@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.

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.

2 participants