-
Notifications
You must be signed in to change notification settings - Fork 123
feat: introduce deduplicate-pipelineruns setting #2364
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
zakisk
wants to merge
5
commits into
tektoncd:main
Choose a base branch
from
zakisk:skip-duplicate-pipelineruns
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3f20335
feat: introduce deduplicate-pipelineruns setting
zakisk 81fc44f
Merge branch 'main' into skip-duplicate-pipelineruns
zakisk 3f69aaa
Merge branch 'main' into skip-duplicate-pipelineruns
zakisk 6c8a63a
Merge branch 'main' into skip-duplicate-pipelineruns
chmouel bec0021
Merge branch 'main' into skip-duplicate-pipelineruns
zakisk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| //go:build e2e | ||
|
|
||
| package test | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "regexp" | ||
| "testing" | ||
|
|
||
| tgithub "github.com/openshift-pipelines/pipelines-as-code/test/pkg/github" | ||
| "github.com/openshift-pipelines/pipelines-as-code/test/pkg/payload" | ||
| twait "github.com/openshift-pipelines/pipelines-as-code/test/pkg/wait" | ||
| "github.com/tektoncd/pipeline/pkg/names" | ||
| "gotest.tools/v3/assert" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| func TestGithubDeduplicatePipelineRuns(t *testing.T) { | ||
| targetNS := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-ns") | ||
|
|
||
| ctx := context.TODO() | ||
| ctx, runcnx, opts, ghcnx, err := tgithub.Setup(ctx, false, false) | ||
| assert.NilError(t, err) | ||
|
|
||
| yamlEntries := map[string]string{} | ||
| yamlEntries[".tekton/pipelinerun-match-all-branch.yaml"] = "testdata/pipelinerun.yaml" | ||
|
|
||
| repoinfo, resp, err := ghcnx.Client().Repositories.Get(ctx, opts.Organization, opts.Repo) | ||
| assert.NilError(t, err) | ||
| if resp != nil && resp.StatusCode == http.StatusNotFound { | ||
| t.Errorf("Repository %s not found in %s", opts.Organization, opts.Repo) | ||
| } | ||
|
|
||
| err = tgithub.CreateCRD(ctx, t, repoinfo, runcnx, opts, targetNS) | ||
| assert.NilError(t, err) | ||
|
|
||
| entries, err := payload.GetEntries(yamlEntries, targetNS, "*", "pull_request, push", map[string]string{}) | ||
| assert.NilError(t, err) | ||
|
|
||
| targetRefName := fmt.Sprintf("refs/heads/%s", | ||
| names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test")) | ||
|
|
||
| sha, vref, err := tgithub.PushFilesToRef(ctx, ghcnx.Client(), "Test Github Deduplicate PipelineRuns", repoinfo.GetDefaultBranch(), targetRefName, | ||
| opts.Organization, opts.Repo, entries) | ||
| assert.NilError(t, err) | ||
|
|
||
| runcnx.Clients.Log.Infof("Commit %s has been created and pushed to %s", sha, vref.GetURL()) | ||
| number, err := tgithub.PRCreate(ctx, runcnx, ghcnx, opts.Organization, | ||
| opts.Repo, targetRefName, repoinfo.GetDefaultBranch(), "Test Github Deduplicate PipelineRuns") | ||
| assert.NilError(t, err) | ||
|
|
||
| g := &tgithub.PRTest{ | ||
| PRNumber: number, | ||
| SHA: sha, | ||
| TargetNamespace: targetNS, | ||
| Logger: runcnx.Clients.Log, | ||
| Provider: ghcnx, | ||
| Options: opts, | ||
| TargetRefName: targetRefName, | ||
| Cnx: runcnx, | ||
| } | ||
|
|
||
| defer g.TearDown(ctx, t) | ||
|
|
||
| runcnx.Clients.Log.Infof("Pull request %d has been created", number) | ||
| err = twait.UntilPipelineRunCreated(ctx, runcnx.Clients, twait.Opts{ | ||
| RepoName: targetNS, | ||
| Namespace: targetNS, | ||
| MinNumberStatus: 1, | ||
| PollTimeout: twait.DefaultTimeout, | ||
| TargetSHA: sha, | ||
| }) | ||
| assert.NilError(t, err) | ||
|
|
||
| // but here we can't guarantee that for which event PipelineRun is created because we don't which | ||
| // event is received first on controller either push or pull_request. | ||
| prs, err := runcnx.Clients.Tekton.TektonV1().PipelineRuns(targetNS).List(ctx, metav1.ListOptions{}) | ||
| assert.NilError(t, err) | ||
| assert.Assert(t, len(prs.Items) == 1) | ||
|
|
||
| maxLines := int64(50) | ||
| err = twait.RegexpMatchingInControllerLog(ctx, runcnx, *regexp.MustCompile("Skipping duplicate PipelineRun"), 10, "controller", &maxLines) | ||
| assert.NilError(t, err) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error from the
Listcall to find existingPipelineRuns is not handled correctly. If this API call fails (e.g., due to a transient network issue), the error is ignored, and the code proceeds to create a newPipelineRun. This could lead to the creation of a duplicatePipelineRun, defeating the purpose of this feature. The error should be handled by returning it, which would cause the operation to fail and prevent potential duplicates.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we really fail here or continue if we got error in listing PipelineRuns? π€
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gemini-code-assist if we fail it will disturb execution of other PipelineRuns