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

Change value of "CI_COMMIT_BRANCH" for pulls to source branch #3560

Open
3 tasks done
wxiaoguang opened this issue Mar 27, 2024 · 10 comments
Open
3 tasks done

Change value of "CI_COMMIT_BRANCH" for pulls to source branch #3560

wxiaoguang opened this issue Mar 27, 2024 · 10 comments
Labels
breaking will break existing installations if no manual action happens enhancement improve existing features
Milestone

Comments

@wxiaoguang
Copy link

wxiaoguang commented Mar 27, 2024

Describe the bug

Somewhat related to " PR triggers the CI twice #2888 ".

To reproduce:

  • Create a simple yaml in main branch:
steps:
  test-when:
    when: 
      branch: main
    image: ....
    commands: 
      - echo "running on CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH"
  • Create a new branch new-branch based on main and open a PR on Gitea
  • Make some changes in new-branch branch
  • When woodpecker receives the pull_request_sync event for the PR branch new-branch, it still runs it and considers it as main branch
  • Expected behavior: such event should be skipped

image

System Info

server & client: 2.4.1

Additional context

No response

Validations

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Checked that the bug isn't fixed in the next version already [https://woodpecker-ci.org/faq#which-version-of-woodpecker-should-i-use]
@wxiaoguang wxiaoguang added the bug Something isn't working label Mar 27, 2024
@qwerty287
Copy link
Contributor

If I understand you correctly that's intended.
For PRs, the branch is the PR target branch.

From docs about the env var:

commit branch (equals target branch for pull requests)

@wxiaoguang
Copy link
Author

wxiaoguang commented Mar 27, 2024

But it is quite counter-intuitive that a non-main branch runs with when: branch: main.

I think the filter should be respected.

Expected behavior: such event should be skipped

@qwerty287
Copy link
Contributor

But it is quite counter-intuitive that a non-main branch runs with when: branch: main.

And what's the branch if it's a PR from a fork?

This is also described in the docs: https://woodpecker-ci.org/docs/usage/workflow-syntax#branch

The step now triggers on main branch, but also if the target branch of a pull request is main. Add an event condition to limit it further to pushes on main only.

@wxiaoguang
Copy link
Author

Thank you, but it is just counter-intuitive at first glance ....

@anbraten
Copy link
Member

Might actually make a bit more sense to have branch = source branch instead of target branch. That would however be a breaking change we could only consider for 3.0

@wxiaoguang
Copy link
Author

Should I reopen this issue?

@anbraten anbraten reopened this Mar 27, 2024
@anbraten
Copy link
Member

Sure if that's a thing you would like to be changed.

@qwerty287 qwerty287 added enhancement improve existing features breaking will break existing installations if no manual action happens and removed bug Something isn't working labels Mar 27, 2024
@wxiaoguang
Copy link
Author

wxiaoguang commented Mar 28, 2024

I can see there could also be breaking changes in 2.x, eg: Use map on all environment keys in our config #3500 (comment)

So is it possible to take this breaking change in 2.5.x ?

@woodpecker-ci woodpecker-ci deleted a comment from qwerty287 Mar 28, 2024
@anbraten
Copy link
Member

image

How, did I removed that. 🤔 Sorry @qwerty287 that wasn't on purpose.

The comment was basically:

I can see there could also be breaking changes in 2.x, eg: Use map on all environment keys in our config #3500 (comment)

This should not be a breaking change and might be a bug, if so we should open a new issue.

So is it possible to take this breaking change in 2.5.x ?

As it is a breaking change, we can only change that in version 3.0

@wxiaoguang
Copy link
Author

wxiaoguang commented Mar 28, 2024

I can see there could also be breaking changes in 2.x, eg: Use map on all environment keys in our config #3500 (comment)

This should not be a breaking change and might be a bug, if so we should open a new issue.

OK, I managed to figure it out .... I guess it is the changed behavior of handling dots . in environment names (no idea what it is related to, maybe related to docker)

For example: ES 7 documents use "environment: node.name=..." https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docker.html . These environments don't work for the latest.

@6543 6543 added this to the 3.x.x milestone Mar 29, 2024
@6543 6543 changed the title Woodpecker uses wrong branch for "when" filter when handling pull_request_sync Change value of "CI_COMMIT_BRANCH" for pulls to source branch Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking will break existing installations if no manual action happens enhancement improve existing features
Projects
None yet
Development

No branches or pull requests

4 participants