Skip to content

build(Makefile): avoid building if LDFLAGS returns error checking for SemVer#13418

Open
egypcio wants to merge 1 commit intokubernetes-sigs:mainfrom
egypcio:avoid-calling-goBuild-if-ldflags-do-not-find-a-semver-tag
Open

build(Makefile): avoid building if LDFLAGS returns error checking for SemVer#13418
egypcio wants to merge 1 commit intokubernetes-sigs:mainfrom
egypcio:avoid-calling-goBuild-if-ldflags-do-not-find-a-semver-tag

Conversation

@egypcio
Copy link
Copy Markdown

@egypcio egypcio commented Mar 8, 2026

What this PR does / why we need it:

hack/version.sh doesn't properly block the build if a SemVer is not found in git tags; it returns an erros via exit 1 but still passes its value to go build and it tries to move further with the build process - unnecessarily.

by merging this change, we:

  • fix properly halting build if SemVer is not found directly in the Makefile;
  • check if LDFLAGS was able to identify a Semantic Version tag in the repository;
  • avoid passing broken string values to go build.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

  • before patching
$ git tag -s v99.rs.belgrade
$ make clusterctl
go build -trimpath -ldflags "GIT_VERSION should be a valid Semantic Version. Current value: v99.rs.belgrade-dirty Please see more details here: https://semver.org" -o bin/clusterctl sigs.k8s.io/cluster-api/cmd/clusterctl
invalid value "GIT_VERSION should be a valid Semantic Version. Current value: v99.rs.belgrade-dirty Please see more details here: https://semver.org" for flag -ldflags: missing =<value> in <pattern>=<value>
usage: go build [-o output] [build flags] [packages]
Run 'go help build' for details.
make: *** [clusterctl] Error 2
  • after patching
$ git tag -s v99.br.rio-de-janeiro
$ make clusterctl
Makefile:268: SEMVER_CHECK: GIT_VERSION should be a valid Semantic Version. Current value: v99.br.rio-de-janeiro Please see more details here: https://semver.org
Makefile:269: *** Build halted.  Stop.
$ git tag -s v99.123.0
$ make clusterctl
go build -trimpath -ldflags "-X 'sigs.k8s.io/cluster-api/version.buildDate=2026-03-08T08:30:39Z' -X 'sigs.k8s.io/cluster-api/version.gitCommit=82699d020ac47d94061afd0bc62dfe7f0c23a858' -X 'sigs.k8s.io/cluster-api/version.gitTreeState=clean' -X 'sigs.k8s.io/cluster-api/version.gitMajor=99' -X 'sigs.k8s.io/cluster-api/version.gitMinor=123' -X 'sigs.k8s.io/cluster-api/version.gitVersion=v99.123.0' -X 'sigs.k8s.io/cluster-api/version.gitReleaseCommit=82699d020ac47d94061afd0bc62dfe7f0c23a858'" -o bin/clusterctl sigs.k8s.io/cluster-api/cmd/clusterctl

@k8s-ci-robot k8s-ci-robot added the do-not-merge/needs-area PR is missing an area label label Mar 8, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign fabriziopandini for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 8, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @egypcio. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@egypcio
Copy link
Copy Markdown
Author

egypcio commented Mar 8, 2026

/area clusterctl

@k8s-ci-robot k8s-ci-robot added area/clusterctl Issues or PRs related to clusterctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed do-not-merge/needs-area PR is missing an area label labels Mar 8, 2026
@egypcio
Copy link
Copy Markdown
Author

egypcio commented Mar 8, 2026

/area misc

@k8s-ci-robot k8s-ci-robot added area/misc Issues or PRs not related to any other area needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 8, 2026
  - check if LDFLAGS was able to identify a Semantic Version tag in the repository;
  - avoid building if that's true (see hack/version.sh for more information).

Signed-off-by: vinícius <651124+egypcio@users.noreply.github.com>
@egypcio egypcio force-pushed the avoid-calling-goBuild-if-ldflags-do-not-find-a-semver-tag branch from 82699d0 to fbc98a6 Compare March 11, 2026 14:41
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 11, 2026
@egypcio
Copy link
Copy Markdown
Author

egypcio commented Mar 11, 2026

rebased ✅

@egypcio
Copy link
Copy Markdown
Author

egypcio commented Mar 20, 2026

ping? 🤓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/clusterctl Issues or PRs related to clusterctl area/misc Issues or PRs not related to any other area cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants