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

  • Add checkForExistingSuccessfulPipelineRun logic to prevent creating duplicate
    PipelineRuns when /retest or /ok-to-test commands are used and a
    successful PipelineRun already exists for the same SHA

  • Fix cancel-in-progress flow by short-circuiting PullRequestClosed events
    to avoid interference with matching logic

  • Ensure /retest commands always create new PipelineRuns
    as explicitly requested by users

  • Add GetOriginalPipelineRunName helper function to eliminate duplicate
    logic across test files for finding PipelineRun names

  • Fix multiple tests that incorrectly used plain /retest expecting multiple
    PipelineRuns: now use /retest for forced reruns

  • Update max-keep-runs tests to use specific PipelineRun names for proper
    testing of cleanup functionality

  • Fix timing issues in tests by adding proper waits for Repository CRD updates

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

pkg/pipelineascode/pipelineascode.go:196

  • [nitpick] Consider renaming the variable 'existingPRs' (later in the block) to 'existingRuns' or similar to more clearly indicate that it represents a collection of PipelineRun objects.
labelSelector := fmt.Sprintf("%s=%s", keys.SHA, formatting.CleanValueKubernetes(p.event.SHA))

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

@waveywaves waveywaves force-pushed the execute-non-successful branch 9 times, most recently from fe82231 to 95d7ede Compare August 5, 2025 20:59
@waveywaves
Copy link
Contributor Author

@zakisk @chmouel this PR is ready to be reviewed

@zakisk zakisk force-pushed the execute-non-successful branch 2 times, most recently from 4f3915b to e1d965f Compare August 11, 2025 13:28
@@ -23,7 +23,7 @@ or other supported Git providers (currently GitHub and Gitea).
to trigger the CI for a pull request by commenting `/ok-to-test`. This enables
CI to run on pull requests submitted by contributors who are not collaborators
of the repository or organization. It also applies to `/test` and `/retest`
commands. This action takes precedence over the `pull_request` action.
commands. Note that `/retest` will only create new PipelineRuns if previous runs failed. This action takes precedence over the `pull_request` action.
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
commands. Note that `/retest` will only create new PipelineRuns if previous runs failed. This action takes precedence over the `pull_request` action.
commands. Note that `/retest` will only trigger failed PipelineRuns. This action takes precedence over the `pull_request` action.

@@ -35,7 +35,7 @@ tracking using a Git workflow.

<--->

- Pull-request "*GitOps*" actions through comments with `/retest`, `/test <pipeline-name>` and so on.
- Pull-request "*GitOps*" actions through comments with `/retest` (reruns failed pipelines), `/test <pipeline-name>` (force rerun specific pipeline) and so on.
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
- Pull-request "*GitOps*" actions through comments with `/retest` (reruns failed pipelines), `/test <pipeline-name>` (force rerun specific pipeline) and so on.
- Pull-request "*GitOps*" actions through comments with `/retest` (reruns failed PipelineRuns), `/test <pipeline-name>` (force rerun specific PipelineRun) and so on.

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

@@ -21,6 +21,21 @@ failure is not with your PR but seems to be an infrastructure issue.
/retest
```

The `/retest` command will only create new PipelineRuns if:
- Previous PipelineRuns for the same commit **failed**, OR
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
- Previous PipelineRuns for the same commit **failed**, OR
- Previously **failed** PipelineRuns for the same commit, OR

@@ -21,6 +21,21 @@ failure is not with your PR but seems to be an infrastructure issue.
/retest
```

The `/retest` command will only create new PipelineRuns if:
- Previous PipelineRuns for the same commit **failed**, OR
- No PipelineRuns exist for the same commit
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
- No PipelineRuns exist for the same commit
- No PipelineRun has been run for the same commit yet

- Previous PipelineRuns for the same commit **failed**, OR
- No PipelineRuns exist for the same commit

If a successful PipelineRun already exists for the same commit, `/retest` will **skip** creating a new PipelineRun 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
If a successful PipelineRun already exists for the same commit, `/retest` will **skip** creating a new PipelineRun to avoid unnecessary duplication.
If a successful PipelineRun already exists for the same commit, `/retest` will **skip** triggering a new PipelineRun 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 trigger is appropriate term I guess

/retest <pipelinerun-name>
```

This will always create a new PipelineRun, even if previous runs were successful.
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
This will always create a new PipelineRun, even if previous runs were successful.
This will always trigger a new PipelineRun, even if previous runs were successful.


This will always create a new PipelineRun, even if previous runs were successful.

Similar to `/retest`, the `/ok-to-test` command will only create new PipelineRuns if no successful PipelineRun already exists for the same commit. This prevents duplicate runs when repository owners repeatedly approve the same commit.
Copy link
Contributor

@zakisk zakisk Aug 12, 2025

Choose a reason for hiding this comment

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

Suggested change
Similar to `/retest`, the `/ok-to-test` command will only create new PipelineRuns if no successful PipelineRun already exists for the same commit. This prevents duplicate runs when repository owners repeatedly approve the same commit.
Similar to `/retest`, the `/ok-to-test` command will only trigger new PipelineRuns if no successful PipelineRun already exists for the same commit. This prevents duplicate runs when repository owners repeatedly test the same commit by `/test` and `/retest` command.

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

* `retest-comment`: The event is a `/retest <PipelineRun>` that would retest a specific PipelineRun.
* `on-comment`: The event is coming from a custom comment that would trigger a PipelineRun.
* `cancel-all-comment`: The event is a single `/cancel` that would cancel every matched PipelineRun.
* `cancel-comment`: The event is a `/cancel <PipelineRun>` that would cancel a specific PipelineRun.
* `ok-to-test-comment`: The event is a `/ok-to-test` that would allow running the CI for an unauthorized user.
* `ok-to-test-comment`: The event is a `/ok-to-test` that would allow running the CI for an unauthorized user. 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
* `ok-to-test-comment`: The event is a `/ok-to-test` that would allow running the CI for an unauthorized user. If a successful PipelineRun already exists for the same commit, no new PipelineRun will be created.
* `ok-to-test-comment`: The event is a `/ok-to-test` that would allow running the CI for an unauthorized user. 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?

@zakisk
Copy link
Contributor

zakisk commented Aug 12, 2025

/test linters

…ipelineruns

when executing /ok-to-test or /retest gitops commands, check whether
the last pipelinerun created for the same SHA was successful. If the
run was successful, skip new pipelinerun creation

- Add checkForExistingSuccessfulPipelineRun logic to prevent creating duplicate
  PipelineRuns when /retest or /ok-to-test commands are used and a
  successful PipelineRun already exists for the same SHA
- Fix cancel-in-progress flow by short-circuiting PullRequestClosed events
  to avoid interference with matching logic
- Ensure /retest <pipelinerun-name> commands always create new PipelineRuns
  as explicitly requested by users

- Add GetOriginalPipelineRunName helper function to eliminate duplicate
  logic across test files for finding PipelineRun names
- Fix multiple tests that incorrectly used plain /retest expecting multiple
  PipelineRuns: now use /retest <name> for forced reruns
- Update max-keep-runs tests to use specific PipelineRun names for proper
  testing of cleanup functionality
- Fix timing issues in tests by adding proper waits for Repository CRD updates
@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

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