Skip to content

fix: /ok-to-test /retest pipelineruns should not be created if last sha successful #2048

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

waveywaves
Copy link
Contributor

@waveywaves waveywaves commented Apr 15, 2025

Changes

/retest and /ok-to-test should only restart failed pipelines; the
changes in the PR ensure that we do not match successful pipelineruns
during invocation of these gitops commands. The tests have also been
updated to use /test instead wherever /retest is being used to restart
successful pipelines

fixes #1959

Submitter Checklist

  • 📝 Ensure your commit message is clear and informative. Refer to the How to write a git commit message guide. Include the commit message in the PR body rather than linking to an external site (e.g., Jira ticket).

  • ♽ Run make test lint before submitting a PR to avoid unnecessary CI processing. Consider installing pre-commit and running pre-commit install in the repository root for an efficient workflow.

  • ✨ We use linters to maintain clean and consistent code. Run make lint before submitting a PR. Some linters offer a --fix mode, executable with make fix-linters (ensure markdownlint and golangci-lint are installed).

  • 📖 Document any user-facing features or changes in behavior.

  • 🧪 While 100% coverage isn't required, we encourage unit tests for code changes where possible.

  • 🎁 If feasible, add an end-to-end test. See README for details.

  • 🔎 Address any CI test flakiness before merging, or provide a valid reason to bypass it (e.g., token rate limitations).

  • If adding a provider feature, fill in the following details:

    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

    (update the provider documentation accordingly)

@osp-pac osp-pac added the e2e label Apr 15, 2025
@waveywaves waveywaves force-pushed the execute-non-successful branch 9 times, most recently from fa2a595 to 72e4aca Compare April 16, 2025 14:17
@waveywaves
Copy link
Contributor Author

/cancel

@waveywaves waveywaves force-pushed the execute-non-successful branch 2 times, most recently from 579fd77 to 7508871 Compare April 16, 2025 23:58
@waveywaves waveywaves changed the title fix: filter out already successful pipelineruns fix: /ok-to-test /retest pipelineruns are not created if last sha successful Apr 16, 2025
@waveywaves waveywaves marked this pull request as ready for review April 17, 2025 00:02
@Copilot Copilot AI review requested due to automatic review settings April 17, 2025 00:02
Copilot

This comment was marked as outdated.

@waveywaves waveywaves changed the title fix: /ok-to-test /retest pipelineruns are not created if last sha successful fix: /ok-to-test /retest pipelineruns should not be created if last sha successful Apr 17, 2025
@waveywaves
Copy link
Contributor Author

/retest

@waveywaves waveywaves force-pushed the execute-non-successful branch 5 times, most recently from 8f5c0ab to b44e208 Compare April 18, 2025 11:11
@waveywaves
Copy link
Contributor Author

waveywaves commented Apr 18, 2025

cc @chmouel seems like the provider e2e tests are not running :/ wanted to test them, not sure what's up
(none of the e2e tests are, they are being skipped)

@waveywaves
Copy link
Contributor Author

cc @zakisk

@zakisk zakisk added e2e and removed e2e labels Apr 21, 2025
@zakisk
Copy link
Contributor

zakisk commented Apr 21, 2025

cc @chmouel seems like the provider e2e tests are not running :/ wanted to test them, not sure what's up (none of the e2e tests are, they are being skipped)

it may be happening due to changes @chmouel is making.

@@ -10,7 +10,7 @@ The advantage of using a `GitOps command` is that it provides a journal of all t

## GitOps Commands on Pull Requests

For example, when you are on a Pull Request, you may want to restart all your PipelineRuns. To do so, you can add a comment on your Pull Request starting with `/retest`, and all PipelineRuns attached to that Pull Request will be restarted.
For example, when you are on a Pull Request, you may want to restart failed PipelineRuns. To do so, you can add a comment on your Pull Request starting with `/retest`, and all **failed** PipelineRuns attached to that Pull Request will be restarted. If all previous PipelineRuns for the same commit were successful, no new PipelineRuns will be created to avoid unnecessary duplication.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
For example, when you are on a Pull Request, you may want to restart failed PipelineRuns. To do so, you can add a comment on your Pull Request starting with `/retest`, and all **failed** PipelineRuns attached to that Pull Request will be restarted. If all previous PipelineRuns for the same commit were successful, no new PipelineRuns will be created to avoid unnecessary duplication.
For example, when you are on a Pull Request, you may want to trigger failed PipelineRuns. To do so, you can add a comment on your Pull Request starting with `/retest`, and all **failed** PipelineRuns attached to that Pull Request will be triggered. If all previous PipelineRuns for the same commit were successful, no new PipelineRuns will be triggered to avoid unnecessary duplication.

Copy link
Contributor

Choose a reason for hiding this comment

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

@waveywaves here and all other places in docs you've updated, I see you're mentioning only /retest command but /test does the same. do you mind adding it as well in examples and wherever needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly because this PR is only related to /retest, I have updated all the tests to use /test instead of /retest whereever required. You want examples of of both /test and /retest through the repo is what you are saying ?

@@ -255,12 +270,12 @@ Here are the possible event types:

* `test-all-comment`: The event is a single `/test` that would test every matched PipelineRun.
* `test-comment`: The event is a `/test <PipelineRun>` comment that would test a specific PipelineRun.
* `retest-all-comment`: The event is a single `/retest` that would retest every matched PipelineRun.
* `retest-all-comment`: The event is a single `/retest` that would retest every matched **failed** PipelineRun. If a successful PipelineRun already exists for the same commit, no new PipelineRun will be created.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* `retest-all-comment`: The event is a single `/retest` that would retest every matched **failed** PipelineRun. If a successful PipelineRun already exists for the same commit, no new PipelineRun will be created.
* `retest-all-comment`: The event is a single `/retest` that would retest every matched **failed** PipelineRun. If a successful PipelineRun already exists for the same commit, no new PipelineRun will be triggered.

@@ -72,8 +72,10 @@ get_tests() {
mapfile -t testfiles < <(find test/ -maxdepth 1 -name '*.go')
ghglabre="Github|Gitlab|Bitbucket"
if [[ ${target} == "providers" ]]; then
# echo "TestGithubMaxKeepRuns"
Copy link
Contributor

Choose a reason for hiding this comment

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

@waveywaves I think this is added mistakenly?

Copy link
Contributor Author

@waveywaves waveywaves Aug 15, 2025

Choose a reason for hiding this comment

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

I added this when I was trying to test individually in the CI, I'll remove this in the very end

@zakisk
Copy link
Contributor

zakisk commented Aug 12, 2025

/test linters

@zakisk zakisk force-pushed the execute-non-successful branch from e1d965f to 53877c2 Compare August 12, 2025 09:32
@zakisk
Copy link
Contributor

zakisk commented Aug 12, 2025

/test linters

@zakisk
Copy link
Contributor

zakisk commented Aug 12, 2025

@waveywaves linters is failing due to docs changes, please address them!

@zakisk
Copy link
Contributor

zakisk commented Aug 12, 2025

@waveywaves I've tested it and it is not working as expected. I had 4 failed PipelineRuns in my test PR when I did /retest all of them ran 🤷🏻

Screencast.From.2025-08-12.15-44-20.mp4

@waveywaves waveywaves force-pushed the execute-non-successful branch 5 times, most recently from 4cb77c7 to 332b54e Compare August 15, 2025 13:17
@waveywaves
Copy link
Contributor Author

@zakisk thank you for testing this, I have updated the PR and it works as expected now. Let me know what you think.

/retest and /ok-to-test should only restart failed pipelines; the
changes in the PR ensure that we do not match successful pipelineruns
during invocation of these gitops commands. The tests have also been
updated to use /test instead wherever /retest is being used to restart
successful pipelines

Signed-off-by: Vibhav Bobade <[email protected]>
Assisted-by: Claude-4-Sonnet (via Cursor)
@waveywaves waveywaves force-pushed the execute-non-successful branch from 4c32c59 to 092c22b Compare August 15, 2025 13:38
@waveywaves
Copy link
Contributor Author

Screen.Recording.2025-08-15.at.7.54.16.PM.mov

@waveywaves
Copy link
Contributor Author

@zakisk do check the video uploaded above, it's the expected behavior you can see for only a failing pipelinerun being retriggered, let me know what you think

@waveywaves
Copy link
Contributor Author

/gemini review

@waveywaves waveywaves requested a review from Copilot August 15, 2025 14:27
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a fix to prevent creating duplicate PipelineRuns when using /ok-to-test or /retest commands if a successful PipelineRun already exists for the same SHA, while maintaining the ability to force reruns with specific PipelineRun names.

  • Added logic to check for existing successful PipelineRuns before creating new ones for /retest and /ok-to-test commands
  • Fixed the cancel-in-progress flow by short-circuiting PullRequestClosed events to avoid interference with matching logic
  • Updated tests to use specific PipelineRun names for forced reruns and improved test reliability

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/matcher/annotation_matcher.go Implemented filterSuccessfulTemplates logic to prevent duplicate runs for successful commits
pkg/matcher/annotation_matcher_test.go Added comprehensive tests for the new checkForExistingSuccessfulPipelineRun functionality
pkg/pipelineascode/pipelineascode.go Modified PullRequestClosed event handling to short-circuit matching logic
test/*.go Updated test files to use /test instead of /retest or specific PipelineRun names for forced reruns
docs/content/docs/guide/*.md Updated documentation to clarify new /retest behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant improvement by preventing duplicate PipelineRuns for /retest and /ok-to-test commands when a successful run for the same SHA already exists. The changes are well-implemented across the board, with corresponding updates to documentation and tests to reflect the new behavior. The refactoring to handle PullRequestClosed events earlier is a nice cleanup.

I've found one potential issue in the filterSuccessfulTemplates function where returning an existing successful PipelineRun could lead to an incorrect failure status. I've left a specific comment with a suggestion to address this. Otherwise, the changes look great.

Comment on lines +441 to +447
// If all templates were skipped, return a reference to the first successful one
if len(filteredPRs) == 0 && anySkipped && len(successfulTemplates) > 0 {
// Return any successful run as reference
for _, successfulPR := range successfulTemplates {
return []Match{{PipelineRun: successfulPR, Repo: repo}}
}
}

Choose a reason for hiding this comment

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

high

The current logic of returning an existing successful PipelineRun when all potential runs are skipped seems to have an unintended side effect. The calling function startPR will attempt to re-create this existing PipelineRun, which will fail with an "already exists" error. This will ultimately result in a failure status being reported on the commit, which is not the desired behavior of simply skipping the run.

To fix this, you should return an empty slice, which will prevent any new PipelineRun from being created and avoid the erroneous failure status. While this means the user won't get explicit feedback that the run was skipped, it correctly implements the primary goal of preventing duplicate runs without causing a failure.

	// If all templates were skipped, return an empty slice to prevent new runs.
	if len(filteredPRs) == 0 && anySkipped {
		logger.Infof("all matched pipelineruns for sha %s have already succeeded, skipping", event.SHA)
		return []Match{}
	}

@waveywaves
Copy link
Contributor Author

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

/ok-to-test re-runs all the pipelines
4 participants