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

build.go: validate -version argument against regex from lib/build #9322

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gudvinr
Copy link
Contributor

@gudvinr gudvinr commented Jan 4, 2024

In #9267 it was mentioned that binaries built with incompatible versions can't be run.
To avoid situations like this completely, same regex is used to validate manually provided versions.

build.go Outdated Show resolved Hide resolved
@gudvinr
Copy link
Contributor Author

gudvinr commented Jan 4, 2024

Huh, some tests are already failing. That's interesting.

I don't know much about CI pipeline but it seems like git describe in getGitVersion only returns commit hash for some reason

@calmh
Copy link
Member

calmh commented Jan 4, 2024

Right, so it is, because the builds there do a shallow checkout. I added an exception for unknown-dev (which happens when there is no git at all), before seeing this.

Of course, disallowing the just-a-hash "versions" is correct, that's part of why we do this check to begin with. I guess options to fix it is to do full checkouts in more places in github actions, or have getVersion() return unknown-dev when it's just a hash...

@gudvinr
Copy link
Contributor Author

gudvinr commented Jan 9, 2024

I guess options to fix it is to do full checkouts in more places in github actions, or have getVersion() return unknown-dev when it's just a hash

I think it depends on how resulting build are used. If it's just to test compilation then unknown-dev is good enough for cases when it's not possible to determine version tag.

When build artifacts then used for packaging, then build process should be fixed. I don't think it's the case because production builds don't fail AFAIK.
However, it's still might be useful for external builds. E.g. linux packages built by distro maintainers. If git hash will be masked by "unknown-dev", it won't be noticed until after someone runs an app and checks version.

@calmh
Copy link
Member

calmh commented Jan 12, 2024

Perhaps a third option is to generate something like v0.0.0-g32cca86ac or v0.0.0-dev+g32cca86ac, which is acceptable to all the regexps, clearly shows that something funky happened during the build, and yet is identifiable if encountered in the wild...

Indeed we don't produce binaries like this (and hopefully nobody else either), but being able to run tests without knowing the correct version number might be useful.

gudvinr and others added 3 commits February 9, 2024 19:59
In syncthing#9267 it was mentioned that binaries built with incompatible
versions can't be run. To avoid situations like this completely,
same regex is used to validate manually provided verions.
@gudvinr gudvinr force-pushed the feature/9267_build_version_check branch from 32cca86 to e2c5f1d Compare February 9, 2024 17:00
@gudvinr
Copy link
Contributor Author

gudvinr commented Feb 9, 2024

Perhaps a third option is to generate something like v0.0.0-g32cca86ac or v0.0.0-dev+g32cca86ac, which is acceptable to all the regexps, clearly shows that something funky happened during the build, and yet is identifiable if encountered in the wild...

I'd suggest to add a check in runtime that will send a log message and visible warning in UI for unknown-dev version string specifically. That'll be a clear signal to users (or maintainers) that they messed up in build preparation. At the same time it shouldn't be an issue for official packages. And CI shouldn't care about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants