Skip to content

feat(go): fix parsing main module version for go >= 1.24 #8433

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

Merged
merged 3 commits into from
Feb 24, 2025

Conversation

nabokihms
Copy link
Contributor

@nabokihms nabokihms commented Feb 23, 2025

Description

This commit refines the logic for determining the main module version in projects using Go version 1.24 and later. The changes ensure that a more accurate version is used by leveraging the ldflags version when appropriate.

Key adjustments include:

  • Checking for a version retrieved from go buildinfo.
  • Prioritizing the ldflags version when the retrieved version is a placeholder version like "v0.0.0" and a valid ldflags version exists.
  • Defaulting to the ldflags version if no version is found in the build information.

These improvements enhance the reliability of version handling in builds.

Related issues

Related PRs

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

This commit refines the logic for determining the main module version in projects using Go version 1.24 and later. The changes ensure that a more accurate version is used by leveraging the `ldflags` version when appropriate.

Key adjustments include:
- Checking for a version retrieved from `go buildinfo`.
- Prioritizing the `ldflags` version when the retrieved version is a placeholder version like "v0.0.0" and a valid `ldflags` version exists.
- Defaulting to the `ldflags` version if no version is found in the build information.

These improvements enhance the reliability of version handling in builds.

Signed-off-by: maksim.nabokikh <[email protected]>
Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. LGTM.
I left a small comment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For several reasons, I propose that we stop including binaries as test data in the future. First, having binaries in the repository will bloat its size, which makes operations like cloning slower. Additionally, since Git cannot diff binary files, each commit significantly increases the repository’s size. Moreover, because we don’t know how these binaries were generated, it’s difficult to modify them if needed.

We do have an idea to automatically generate these binaries (using go generate, for example) when running unit tests. Could you please remove the binaries for now and comment out the tests? Once this PR is merged, we’ll generate the necessary test binaries on our end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sure

nabokihms and others added 2 commits February 24, 2025 12:06

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Co-authored-by: DmitriyLewen <[email protected]>
Signed-off-by: maksim.nabokikh <[email protected]>
Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@knqyf263 knqyf263 enabled auto-merge February 24, 2025 11:16
@knqyf263 knqyf263 added this pull request to the merge queue Feb 24, 2025
Merged via the queue into aquasecurity:main with commit e58dcfc Feb 24, 2025
11 of 12 checks passed
RingoDev pushed a commit to RingoDev/trivy that referenced this pull request Feb 26, 2025

Verified

This commit was signed with the committer’s verified signature.
RingoDev Thomas Grininger
…y#8433)

Signed-off-by: maksim.nabokikh <[email protected]>
Co-authored-by: DmitriyLewen <[email protected]>
dstrelbytskyi pushed a commit to datarobot/trivy that referenced this pull request Mar 5, 2025
dstrelbytskyi pushed a commit to datarobot/trivy that referenced this pull request Mar 10, 2025
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.

Enhance Version Detection for ldflags Overrides in Go 1.24 Binaries
3 participants