woodpecker-ci / woodpecker

Woodpecker is a simple, yet powerful CI/CD engine with great extensibility.
https://woodpecker-ci.org
Apache License 2.0
4.18k stars 363 forks source link

PR triggers the CI twice #2888

Open xoxys opened 10 months ago

xoxys commented 10 months ago

Component

server

Describe the bug

Two CI runs are triggered at the same time on PR creation, see the two webhook events below.

Request URL: https://ci.rknet.org/api/hook?access_token=***
Request method: POST
Content-Type: application/json
X-GitHub-Delivery: 342485a1-***
X-GitHub-Event: pull_request
X-GitHub-Event-Type: pull_request
X-Gitea-Delivery: 342485a1-***
X-Gitea-Event: pull_request
X-Gitea-Event-Type: pull_request
X-Gitea-Signature: ***
X-Gogs-Delivery: 342485a1-***
X-Gogs-Event: pull_request
X-Gogs-Event-Type: pull_request
X-Gogs-Signature: ***
X-Hub-Signature: sha1=***
X-Hub-Signature-256: sha256=***

## Response 200
{"id":193,"number":33,"author":"renovator","parent":0,"event":"pull_request","status":"pending","errors":null,"enqueued_at":1701175158,"created_at":1701175158,"updated_at":1701175158,"started_at":0,"finished_at":0,"deploy_to":"","commit":"c17d6e7f15201d0a253f83890b1d088e9b34c43d","branch":"main","ref":"refs/pull/145/head","refspec":"renovate/docker-digests:main","clone_url":"","title":"chore(docker): update docker.io/clux/muslrust:1.74.0-stable docker digest to 37ba39a","message":"chore(docker): update docker.io/clux/muslrust:1.74.0-stable docker digest to 37ba39a","timestamp":0,"sender":"renovator","author_avatar":"https://gitea.rknet.org/avatars/188565bedb61ddcc66b2dceedd8aa136","author_email":"","forge_url":"https://gitea.rknet.org/container/vaultwarden/pulls/145","reviewed_by":"","reviewed_at":0,"workflows":[{"id":671,"pipeline_id":193,"pid":1,"name":"build-container","state":"pending","children":[{"id":2322,"uuid":"d77cc32e-3a56-41d2-92f5-1772c862ab68","pipeline_id":193,"pid":4,"ppid":1,"name":"clone","state":"pending","exit_code":0,"type":"clone"},{"id":2323,"uuid":"42927df2-9032-4aad-84b0-f1b09b1136cc","pipeline_id":193,"pid":5,"ppid":1,"name":"security-build","state":"pending","exit_code":0,"type":"plugin"},{"id":2324,"uuid":"f3d81d7a-b1dd-4b12-a045-e21b361a9f74","pipeline_id":193,"pid":6,"ppid":1,"name":"security-scan","state":"pending","exit_code":0,"type":"commands"}]},{"id":672,"pipeline_id":193,"pid":2,"name":"build-package","state":"pending","children":[{"id":2325,"uuid":"8eee1203-e26e-45b1-a612-f8840dd19f93","pipeline_id":193,"pid":7,"ppid":2,"name":"clone","state":"pending","exit_code":0,"type":"clone"},{"id":2326,"uuid":"8216ee3f-72ac-43cc-b168-0fb9147f47ff","pipeline_id":193,"pid":8,"ppid":2,"name":"changelog","state":"pending","exit_code":0,"type":"commands"}]},{"id":673,"pipeline_id":193,"pid":3,"name":"docs","state":"pending","children":[{"id":2327,"uuid":"74a6fcf2-853e-4565-82ae-7956b92ee653","pipeline_id":193,"pid":9,"ppid":3,"name":"clone","state":"pending","exit_code":0,"type":"clone"},{"id":2328,"uuid":"81282a99-5e37-47ec-a5da-8c46b8fa0643","pipeline_id":193,"pid":10,"ppid":3,"name":"markdownlint","state":"pending","exit_code":0,"type":"commands"},{"id":2329,"uuid":"b0e42cd5-2c17-4f79-9678-81889699cca7","pipeline_id":193,"pid":11,"ppid":3,"name":"spellcheck","state":"pending","exit_code":0,"type":"commands"},{"id":2330,"uuid":"a8a273bc-de6b-433c-b335-795bb29a8bec","pipeline_id":193,"pid":12,"ppid":3,"name":"link-validation","state":"pending","exit_code":0,"type":"commands"}]}]}
Request URL: https://ci.rknet.org/api/hook?access_token=****
Request method: POST
Content-Type: application/json
X-GitHub-Delivery: 563de175-***
X-GitHub-Event: pull_request
X-GitHub-Event-Type: pull_request_sync
X-Gitea-Delivery: 563de175-***
X-Gitea-Event: pull_request
X-Gitea-Event-Type: pull_request_sync
X-Gitea-Signature: ***
X-Gogs-Delivery: 563de175-***
X-Gogs-Event: pull_request
X-Gogs-Event-Type: pull_request_sync
X-Gogs-Signature: ***
X-Hub-Signature: sha1=***
X-Hub-Signature-256: sha256=***

## Response 200
{"id":194,"number":34,"author":"renovator","parent":0,"event":"pull_request","status":"pending","errors":null,"enqueued_at":1701175159,"created_at":1701175159,"updated_at":1701175159,"started_at":0,"finished_at":0,"deploy_to":"","commit":"c17d6e7f15201d0a253f83890b1d088e9b34c43d","branch":"main","ref":"refs/pull/145/head","refspec":"renovate/docker-digests:main","clone_url":"","title":"chore(docker): update docker.io/clux/muslrust:1.74.0-stable docker digest to 37ba39a","message":"chore(docker): update docker.io/clux/muslrust:1.74.0-stable docker digest to 37ba39a","timestamp":0,"sender":"renovator","author_avatar":"https://gitea.rknet.org/avatars/188565bedb61ddcc66b2dceedd8aa136","author_email":"","forge_url":"https://gitea.rknet.org/container/vaultwarden/pulls/145","reviewed_by":"","reviewed_at":0,"workflows":[{"id":674,"pipeline_id":194,"pid":1,"name":"build-container","state":"pending","children":[{"id":2331,"uuid":"2e55b6e7-e29f-450e-886b-e57f7f98bcbe","pipeline_id":194,"pid":4,"ppid":1,"name":"clone","state":"pending","exit_code":0,"type":"clone"},{"id":2332,"uuid":"419e9fcd-9fdd-4c06-87a7- 15280310afea","pipeline_id":194,"pid":5,"ppid":1,"name":"security-build","state":"pending","exit_code":0,"type":"plugin"},{"id":2333,"uuid":"8a6eb1c5-9e26-4cfa-963d-d487ab532bb0","pipeline_id":194,"pid":6,"ppid":1,"name":"security-scan","state":"pending","exit_code":0,"type":"commands"}]},{"id":675,"pipeline_id":194,"pid":2,"name":"build-package","state":"pending","children":[{"id":2334,"uuid":"2a48dbb4-75be-405f-a4e2-97a85891f66b","pipeline_id":194,"pid":7,"ppid":2,"name":"clone","state":"pending","exit_code":0,"type":"clone"},{"id":2335,"uuid":"54e90fd4-3b5e-4f22-b344-12b3f4caa4b5","pipeline_id":194,"pid":8,"ppid":2,"name":"changelog","state":"pending","exit_code":0,"type":"commands"}]},{"id":676,"pipeline_id":194,"pid":3,"name":"docs","state":"pending","children":[{"id":2336,"uuid":"990901af-c9f9-4347-add5-6d7358f37436","pipeline_id":194,"pid":9,"ppid":3,"name":"clone","state":"pending","exit_code":0,"type":"clone"},{"id":2337,"uuid":"b72998a4-1fc5-492a-a0d7-c8dd7e181e7c","pipeline_id":194,"pid":10,"ppid":3,"name":"markdownlint","state":"pending","exit_code":0,"type":"commands"},{"id":2338,"uuid":"06f2c11a-e255-41f1-a30e-d269a8142d5f","pipeline_id":194,"pid":11,"ppid":3,"name":"spellcheck","state":"pending","exit_code":0,"type":"commands"},{"id":2339,"uuid":"a85323cf-b1c1-4a99-bdaf-224ad6e4e22e","pipeline_id":194,"pid":12,"ppid":3,"name":"link-validation","state":"pending","exit_code":0,"type":"commands"}]}],"changed_files":["Containerfile"]}

System Info

{"source":"https://github.com/woodpecker-ci/woodpecker","version":"next-111a0b4ea5"}

Additional context

No response

Validations

qwerty287 commented 10 months ago

These are two different webhooks, was something changed at gitea's side?

xoxys commented 10 months ago

Nope. Both events were triggered in the exact same second and for the same commit.

qwerty287 commented 10 months ago

But one event is pull_request_sync , the other pull_request (of course we can still ignore the later one)

xoxys commented 10 months ago

Wondering a bit why this occurs now and if something in WP or Gitea has changed.

aozomaro commented 10 months ago

We’ve recently started seeing the same issue and our forge is GitHub. Our use case is slightly different though. We are syncing branches which are chained/stacked together so we see 1 run for every branch in the chain

qwerty287 commented 10 months ago

I can't reproduce with gitea 1.21.1. PR is only triggered once in woodpecker. Also, there's just one webhooks in gitea's list. This looks like an issue with gitea to me.

anbraten commented 10 months ago

Might be 2 webhooks being registered?

xoxys commented 10 months ago

No only one webhook in gitea. A duplicate webhook would also not explain a pr and pr sync event.

xoxys commented 10 months ago

I can't reproduce with gitea 1.21.1. PR is only triggered once in woodpecker. Also, there's just one webhooks in gitea's list. This looks like an issue with gitea to me.

That might be, Ill try to debug this further.

anbraten commented 10 months ago

No only one webhook in gitea. A duplicate webhook would also not explain a pr and pr sync event.

true

lafriks commented 10 months ago

What I noticed that Gitea now sends not only push but also create event that is for new branch creation when pushing new branch and woodpecker converts create also to push so there is duplicate pipeline created

xoxys commented 10 months ago

For me, this issue is gone with current Woodpecker next and Gitea 1.21.2.

qwerty287 commented 10 months ago

Then I guess we can close this?

xoxys commented 10 months ago

Not sure about the comment from @lafriks

xoxys commented 9 months ago

Nope, the issue still exists -.-

xoxys commented 9 months ago

Still happens on current next release:

image

I have just created a fresh repo and executed renovate to get the onboarding PR. I will try to create a reproducible procedure for a local dev setup tomorrow.

xoxys commented 9 months ago

Looks like this is not only exclusive to GH. The PR for Release 2.2.0 seems to be triggered twice for the same commit.

image

qwerty287 commented 9 months ago

No, this is expected because AFAIK the not pushes two commits to the PR.

xoxys commented 9 months ago

Two commits with the same hash?

qwerty287 commented 9 months ago

Oh, didn't see this. Then you're right, I just thought one is the merge from main and one the changelog update.

psvillanueva commented 7 months ago

We were also facing this issue while using Graphite to submit our PR stacks. It seems the way Graphite works is that it would update tracking branches/PR metadata whenever a change was submitted. This would fire off a GH pull_request_synchronize event as well as a push, resulting in a double trigger of our CI. We noticed the commit hashes were the same (also shown in @xoxys screenshot a few comments above). Ultimately, we made some modifications to our workflow config: Instead of using event: [pull_request], we replaced this with evaluate: 'CI_PIPELINE_EVENT == "pull_request" && CI_COMMIT_SHA != CI_PREV_COMMIT_SHA'. Everything seems fine and dandy for now.

evadim commented 4 months ago

I also experience this behavior and it annoy me a lot.

In Gitea (original description) can be easily corrected by editing webhook: Gitea by default enable all the events for hook. So, in edit webhook dialog one can switch "Trigger on" to "Custom Events..." and choose one of "Push" or "Pull request synchronized". Looks like first one fires on actual git push and second one see changes in PR (i.e. - new commit added to it) but as Gitea works very fast it feels like two runs on same time.

P.S. I just flying around, sorry if I miss something in long discussion thread.

anbraten commented 4 months ago

Seems to be the case for our release PRs as well: