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: Run benchmarks if PR is labeled with "run/benchmark" #2958

Merged
merged 10 commits into from
Jan 7, 2024
Merged

Conversation

seisman
Copy link
Member

@seisman seisman commented Jan 6, 2024

Support running benchmarks in PRs with the run/benchmark label.

Address comment #2952 (comment).

@seisman
Copy link
Member Author

seisman commented Jan 6, 2024

/bechmark

@seisman
Copy link
Member Author

seisman commented Jan 6, 2024

The slash command won't work until the PR is merged into main branch.

@weiji14
Copy link
Member

weiji14 commented Jan 6, 2024

The slash command won't work until the PR is merged into main branch.

Actually, will CodSpeed be able to link the benchmark report to the PR branch if we trigger it via repository_dispatch instead of pull_request?

@seisman
Copy link
Member Author

seisman commented Jan 6, 2024

The slash command won't work until the PR is merged into main branch.

Actually, will CodSpeed be able to link the benchmark report to the PR branch if we trigger it via repository_dispatch instead of pull_request?

That's a good question. I guess the answer is no.

@weiji14
Copy link
Member

weiji14 commented Jan 6, 2024

Actually, will CodSpeed be able to link the benchmark report to the PR branch if we trigger it via repository_dispatch instead of pull_request?

That's a good question. I guess the answer is no.

How about we set up the workflow to run only when there's a run-benchmark label? Can try to set up an if-condition following https://stackoverflow.com/questions/62325286/run-github-actions-when-pull-requests-have-a-specific-label

@seisman
Copy link
Member Author

seisman commented Jan 6, 2024

Actually, will CodSpeed be able to link the benchmark report to the PR branch if we trigger it via repository_dispatch instead of pull_request?

That's a good question. I guess the answer is no.

How about we set up the workflow to run only when there's a run-benchmark label? Can try to set up an if-condition following https://stackoverflow.com/questions/62325286/run-github-actions-when-pull-requests-have-a-specific-label

Sounds a clever solution.

@seisman seisman added the run/benchmark Trigger the benchmark workflow in PRs label Jan 6, 2024
@seisman seisman changed the title Support slash command /benchmark in PRs CI: Run benchmarks if PR is labeled with "run-benchmark" Jan 6, 2024
@seisman
Copy link
Member Author

seisman commented Jan 6, 2024

The benchmark workflow is trigged by the "run-benchmark" label, see https://github.com/GenericMappingTools/pygmt/actions/runs/7431110786?pr=2958.

@seisman seisman added the maintenance Boring but important stuff for the core devs label Jan 6, 2024
@seisman seisman added this to the 0.11.0 milestone Jan 6, 2024
@seisman
Copy link
Member Author

seisman commented Jan 6, 2024

I feel triggering a workflow based on the PR label is much better than the slash commands. Some thoughts:

  1. Migrate the other two slash commands /format and /test-gmt-dev to triggering by labels
  2. Instead of using labels like run-benchmark, maybe labels run/benchmark, run/format, run/test-gmt-dev are better?

@seisman
Copy link
Member Author

seisman commented Jan 6, 2024

Hmm, the workflow is canceled because I added the 'maintenance' label.

@weiji14
Copy link
Member

weiji14 commented Jan 6, 2024

  1. Migrate the other two slash commands /format and /test-gmt-dev to triggering by labels

Yeah, I was thinking of using it for /test-gmt-dev, but maybe not for /format since the labels can only be added by contributors/maintainers with triage permissions or above, so new contributors won't be able to use it.

  1. Instead of using labels like run-benchmark, maybe labels run/benchmark, run/format, run/test-gmt-dev are better?

Sounds good.

@seisman seisman added run/benchmark Trigger the benchmark workflow in PRs and removed run/benchmark Trigger the benchmark workflow in PRs labels Jan 6, 2024
@seisman seisman changed the title CI: Run benchmarks if PR is labeled with "run-benchmark" CI: Run benchmarks if PR is labeled with "run/benchmark" Jan 6, 2024
@seisman seisman marked this pull request as ready for review January 6, 2024 12:04
@@ -28,7 +28,7 @@ concurrency:
jobs:
benchmarks:
runs-on: ubuntu-22.04
if: github.repository == 'GenericMappingTools/pygmt'
if: github.repository == 'GenericMappingTools/pygmt' && contains(github.event.pull_request.labels.*.name, 'run/benchmark')
Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I'm unsure if the workflow will run in the main branch, because it's a push event not a pull_request event.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried in my own fork. It doesn't work in the main branch.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed the if condition to:

if: github.repository == 'GenericMappingTools/pygmt' && (github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run/benchmark'))

Now it works in my own fork, see the changes between my fork and the pygmt repository: main...seisman:pygmt:main and the workflow was triggered when pushing in the main branch (https://github.com/seisman/pygmt/actions/workflows/benchmarks.yml).

@seisman seisman marked this pull request as draft January 6, 2024 15:21
@seisman seisman added the needs review This PR has higher priority and needs review. label Jan 7, 2024
@seisman
Copy link
Member Author

seisman commented Jan 7, 2024

It's unclear why I can't see the flame graphs.

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

It's unclear why I can't see the flame graphs.

Hmm yeah, are you getting this Execution profile not available message too at https://codspeed.io/GenericMappingTools/pygmt/branches/slash-benchmark?

image

If I try another branch (e.g. https://codspeed.io/GenericMappingTools/pygmt/branches/alias/function), it looks ok, though sometimes the flame graphs can take some time to render.

.github/workflows/benchmarks.yml Outdated Show resolved Hide resolved
@@ -12,8 +12,9 @@ on:
paths:
- 'pygmt/**/*.py'
- '.github/workflows/benchmarks.yml'
# Uncomment the 'pull_request' line below to trigger the workflow in PR
# pull_request:
# Run in PRs but only if the PR has the 'run/benchmark' label
Copy link
Member

Choose a reason for hiding this comment

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

Should we document in .github/PULL_REQUEST_TEMPLATE.md or somewhere for contributors to request that the run/benchmark label gets added to PRs that might affect performance? Or just rely on the maintainers to set the label for now?

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to leave the jobs to the maintainers. We probably will document it in the contributors guides when addressing #1113.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, or we can put it in doc/maintenance.md somewhere. Not urgent though, since we aren't running the benchmarks that often.

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

Thanks @seisman! Have secretly wanted this label-based trigger mechanism in PyGMT for a while now to be honest 😀

@seisman seisman merged commit ecefd53 into main Jan 7, 2024
7 checks passed
@seisman seisman deleted the slash-benchmark branch January 7, 2024 08:12
@seisman seisman removed needs review This PR has higher priority and needs review. run/benchmark Trigger the benchmark workflow in PRs labels Jan 7, 2024
@weiji14
Copy link
Member

weiji14 commented Jan 7, 2024

Quick question: Do we want to remove the run/benchmark label after a PR is merged, or keep the label on?

@seisman
Copy link
Member Author

seisman commented Jan 7, 2024

I'm OK with either. Maybe we should keep the label so that we know which branches have performance reports.

@seisman seisman added the run/benchmark Trigger the benchmark workflow in PRs label Jan 7, 2024
@seisman
Copy link
Member Author

seisman commented Jan 7, 2024

Quick question: Do we want to remove the run/benchmark label after a PR is merged, or keep the label on?

Actually, we should remove the 'run/benchmark' label. We usually label a PR as "needs-review", then "final-review-call" and remove the "final-review-call" label before merging. All these actions will trigger the benchmarks workflow if the run/benchmark label is kept.

@weiji14
Copy link
Member

weiji14 commented Jan 7, 2024

Quick question: Do we want to remove the run/benchmark label after a PR is merged, or keep the label on?

Actually, we should remove the 'run/benchmark' label. We usually label a PR as "needs-review", then "final-review-call" and remove the "final-review-call" label before merging. All these actions will trigger the benchmarks workflow if the run/benchmark label is kept.

Owh, but we would need to remove all those labels at the same time right? Maybe better to set an if-condition so that the benchmark workflow is not re-triggered after a PR is already merged?

@seisman
Copy link
Member Author

seisman commented Jan 7, 2024

Owh, but we would need to remove all those labels at the same time right?

We need to remove run/benchmark label as early as possible to avoid unnecessary runs.

Maybe better to set an if-condition so that the benchmark workflow is not re-triggered after a PR is already merged?

It may make the if-condition too complicated, which is already very long.

@weiji14
Copy link
Member

weiji14 commented Jan 7, 2024

Owh, but we would need to remove all those labels at the same time right?

We need to remove run/benchmark label as early as possible to avoid unnecessary runs.

Ok, let's go with this. Remove the run/benchmark label before the other labels are removed. Same goes for the run/test-gmt-dev label.

seisman added a commit that referenced this pull request Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs run/benchmark Trigger the benchmark workflow in PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants