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

Prevent CI from running on both push and pull_request events #2170

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

KaanOzkan
Copy link
Contributor

@KaanOzkan KaanOzkan commented Jan 28, 2025

Motivation

Duplicate CI runs waste resources

Implementation

Push events will only be triggered on main. As a result pushes to your branches without a PR will not trigger a build.

Tests

@KaanOzkan KaanOzkan requested a review from a team as a code owner January 28, 2025 15:27
@paracycle
Copy link
Member

I am not sure if the reasoning is correct. AFAIK, the pull_request build runs against a merge commit of the current branch onto the current state of main which gives you more confidence that your PR won't cause a conflict if merged to main at that point in time.

So, there is a separate value we get from pull_request builds.

Ref: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request

Note that GITHUB_SHA for this event is the last merge commit of the pull request merge branch. If you want to get the commit ID for the last commit to the head branch of the pull request, use github.event.pull_request.head.sha instead.

Push events will only be triggered on `main`. As a result pushes to your
branches without a PR will not trigger a build.
@KaanOzkan
Copy link
Contributor Author

Updated the configuration to favour pull_request builds by default instead. As a result pushed branches without a PR don't trigger CI.

Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

Thanks!

@paracycle
Copy link
Member

Updated the configuration to favour pull_request builds by default instead. As a result pushed branches without a PR don't trigger CI.

Except pushes to main

@KaanOzkan KaanOzkan merged commit 35230da into main Jan 28, 2025
18 checks passed
@KaanOzkan KaanOzkan deleted the ko/duplicate-ci branch January 28, 2025 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants