woodpecker-ci / woodpecker

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

Wrong branch information while using annotated tags #2607

Open xoxys opened 10 months ago

xoxys commented 10 months ago

Component

server

Describe the bug

On a tag event, I got this issue with Python poetry:

invalid literal for int() with base 10: "Warnung: refname 'refs/tags/v3.1.0' is ambiguous.\n0"

Looks like the reason is that the clone step is doing + git init -b refs/tags/v3.1.0, the root cause seems to be an issue with the CI_COMMIT_BRANCH information provide by the server while using annotated tags:

System Info

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


### Additional context

_No response_

### Validations

- [X] Read the [Contributing Guidelines](https://github.com/woodpecker-ci/woodpecker/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://woodpecker-ci.org/docs/intro).
- [X] Check that there isn't [already an issue](https://github.com/woodpecker-ci/woodpecker/issues) that reports the same bug to avoid creating a duplicate.
- [X] Checked that the bug isn't fixed in the `next` version already [https://woodpecker-ci.org/faq#which-version-of-woodpecker-should-i-use]
- [X] Check that this is a concrete bug. For Q&A join our [Discord Chat Server](https://discord.gg/fcMQqSMXJy) or the [Matrix room](https://matrix.to/#/#woodpecker:matrix.org).
qwerty287 commented 10 months ago

There shouldn't be a branch in this env var on tag events (it should be empty)

xoxys commented 10 months ago

I think we agree on how it should be :smile:

qwerty287 commented 10 months ago

Tags don't have branches - they are only created on top of commits, so there shouldn't be a branch I think

xoxys commented 10 months ago

Not sure if I understand your comments. Yes there should be no branch information on tag events, as reported in the initial post there is a wrong branch information on tag evens in case an annotated tag was used.

xoxys commented 10 months ago

The git plugin creates a local branch + git init -b refs/tags/v3.1.0 on checkouts. The plugin does this if branch == CI_COMMIT_BRANCH is not empty https://github.com/woodpecker-ci/plugin-git/blob/main/plugin.go#L210-L216 and it is using the provided branch name.

As in my case git init -b refs/tags/v3.1.0 is executed CI_COMMIT_BRANCH has to be set to refs/tags/v3.1.0 by the server for whatever reason, which is wrong and the reason for this report.

qwerty287 commented 10 months ago

Ah, I think I misunderstood the issue 🙃

xoxys commented 10 months ago

No worries sorry if the initial description was not clear enough.