Skip to content

build: Implement semantic versioning in build system#4468

Open
NETIZEN-11 wants to merge 1 commit intokptdev:mainfrom
NETIZEN-11:feat/issue-4450-pr4-build-versioning
Open

build: Implement semantic versioning in build system#4468
NETIZEN-11 wants to merge 1 commit intokptdev:mainfrom
NETIZEN-11:feat/issue-4450-pr4-build-versioning

Conversation

@NETIZEN-11
Copy link
Copy Markdown

Description

This PR implements semantic versioning in the kpt build system using Git tags. It ensures that the version is correctly injected into the binary at build time and provides consistent version output across all architectures.

Part of #4450 - Stabilize kpt API to version 1

Changes Made

Makefile Updates

  1. Semantic Version Detection

    • Uses git describe --tags --match='v*' to automatically detect version from Git tags
    • Follows semantic versioning format: vMAJOR.MINOR.PATCH
    • Fallback to v0.0.0-dev+{commit-hash} for development builds
    • Ensures version consistency across all build environments
  2. Version Injection via ldflags

    • Injects version into github.com/kptdev/kpt/run.version variable
    • Version is embedded at compile time
    • Works seamlessly with the updated version command

How It Works

# Automatic version detection
VERSION := $(shell git describe --tags --match='v*' --abbrev=0 2>/dev/null || echo "v0.0.0-dev+${GIT_COMMIT}")

# Version injection during build
LDFLAGS := -ldflags "-X github.com/kptdev/kpt/run.version=${VERSION}"

Copilot AI review requested due to automatic review settings April 6, 2026 08:28
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 6, 2026

Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit 805a22c
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/69d55592ae77560009ba05ff
😎 Deploy Preview https://deploy-preview-4468--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. go Pull requests that update Go code labels Apr 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements semantic versioning in the kpt build system using Git tags. It detects versions from Git tags (matching the pattern v*) and injects them into the binary at build time. For development builds, it falls back to a dev version format with the commit hash. The PR also includes a major refactoring of the package update functionality with improved code structure and documentation, along with comprehensive render status tracking to capture detailed pipeline execution results.

Changes:

  • Semantic version detection via git describe in Makefile with automatic fallback for dev builds
  • Refactored PkgUpdate implementation with helper functions for better maintainability and clearer error handling
  • Enhanced render status tracking throughout the pipeline execution to capture mutation and validation step results
  • Cross-platform path handling improvements in Kptfile validation
  • Updated Kubernetes dependencies to v0.35.0
  • Updated krm-functions-catalog apply-setters from v0.2.2 to v0.2.4
  • Build tag updates for wasmtime runtime support detection

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Makefile Added semantic version detection using git describe with GIT_COMMIT fallback
pkg/lib/kptops/pkgupdate.go Refactored PkgUpdate into focused helper functions with improved documentation and error handling
pkg/api/kptfile/v1/validation.go Fixed path validation to use path.IsAbs instead of filepath.IsAbs for cross-platform correctness
pkg/api/kptfile/v1/types.go Added Resource field to ResultItem for render status tracking
internal/util/render/executor.go Comprehensive render status tracking with pipeline step results and error aggregation
internal/util/render/executor_test.go Updated tests with cross-platform path handling and render status verification; fixed mkdir bugs
internal/fnruntime/wasmtime.go Updated build tags to exclude Windows from cgo-based wasmtime support
internal/fnruntime/wasmtime_unsupported.go Updated build tags and fixed error message typos
internal/fnruntime/utils.go Code style improvements (YAML string extraction)
internal/builtins/pkg_context.go Improved path normalization and root package detection logic
internal/kptops/testdata/ Updated function version references from v0.2.0 to v0.2.4
go.mod Updated Kubernetes and related dependencies to v0.35.0

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@CsatariGergely
Copy link
Copy Markdown
Contributor

Please fix the DCO issue by following these instructions: https://github.com/kptdev/kpt/pull/4468/checks?check_run_id=70060980850

@NETIZEN-11 NETIZEN-11 force-pushed the feat/issue-4450-pr4-build-versioning branch from fb05e73 to f8a8606 Compare April 7, 2026 12:41
NETIZEN-11 pushed a commit to NETIZEN-11/kpt that referenced this pull request Apr 7, 2026
- Remove duplicate setRenderStatus function in executor.go
- Add TODO comment for unused opts parameter in pkgupdate.go
- Fix path handling inconsistency in validation.go (use path.Clean instead of filepath.Clean)

Resolves code review feedback from PR kptdev#4468

Signed-off-by: NETIZEN-11 <kumarnitesh121411@gmail.com>
Copilot AI review requested due to automatic review settings April 7, 2026 12:43
@NETIZEN-11
Copy link
Copy Markdown
Author

@CsatariGergely Thanks for pointing this out. I've fixed the DCO issue and updated the commits. Kindly take another look.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 17 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aravindtga
Copy link
Copy Markdown
Contributor

aravindtga commented Apr 7, 2026

Hi @NETIZEN-11,

Thanks for your PR and contribution!

This currently has 23 commits, many of which are unrelated to the build versioning scope. They got included in your branch as part of a merge, This makes it hard to review what's actually part of your change.

Could you rebase cleanly onto main so only the semantic versioning changes are visible in the diff?

I'd also request the same for your other open PRs. That will make reviews much easier across the board and help get things merged faster.

Thanks!

@NETIZEN-11 NETIZEN-11 force-pushed the feat/issue-4450-pr4-build-versioning branch from ddf69bb to b9924d7 Compare April 7, 2026 13:46
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Apr 7, 2026
@NETIZEN-11
Copy link
Copy Markdown
Author

Hi @aravindtga,

Thanks for the feedback. I’ve rebased the branch onto main and cleaned up the commits. Now the PR only contains the relevant semantic versioning changes.

Could you please take another look?

Thanks!

liamfallon
liamfallon previously approved these changes Apr 7, 2026
@dosubot dosubot bot added the lgtm label Apr 7, 2026
@liamfallon liamfallon self-requested a review April 7, 2026 17:02
@liamfallon liamfallon dismissed their stale review April 7, 2026 17:04

I tested the solution and it does not seem to work correctly for development builds.

@liamfallon
Copy link
Copy Markdown
Contributor

The solution here does not insert the correct version string into the binary when building a development version of kpt, see this log:

Before fix:

kpt % git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
kpt % make build
go build -ldflags "-X github.com/kptdev/kpt/run.version=2cd4e75fa " -o /Users/liam/go/bin/kpt -v .
github.com/kptdev/kpt
kpt % kpt version
2cd4e75fa

After fix:

kpt % git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   Makefile

no changes added to commit (use "git add" and/or "git commit -a")
kpt % git diff
diff --git a/Makefile b/Makefile
index 7b64949f8..048641216 100644
--- a/Makefile
+++ b/Makefile
@@ -22,9 +22,12 @@ YEAR_GEN          := $(shell date '+%Y')
 GOBIN := $(shell go env GOPATH)/bin
 GIT_COMMIT := $(shell git rev-parse --short HEAD)
 
+# Use git describe to get semantic version, fallback to commit hash for dev builds
+VERSION := $(shell git describe --tags --match='v*' --abbrev=0 2>/dev/null || echo "v0.0.0-dev+${GIT_COMMIT}")
+
 export KPT_FN_WASM_RUNTIME ?= nodejs
 
-LDFLAGS := -ldflags "-X github.com/kptdev/kpt/run.version=${GIT_COMMIT}
+LDFLAGS := -ldflags "-X github.com/kptdev/kpt/run.version=${VERSION}
 ifeq ($(OS),Windows_NT)
        # Do nothing
 else
kpt % make build
go build -ldflags "-X github.com/kptdev/kpt/run.version=v1.0.0-beta.62 " -o /Users/liam/go/bin/kpt -v .
github.com/kptdev/kpt
kpt % kpt version
v1.0.0-beta.62

I think the last version string should be v0.0.0-dev+2cd4e75fa

Copilot AI review requested due to automatic review settings April 7, 2026 18:58
@NETIZEN-11 NETIZEN-11 force-pushed the feat/issue-4450-pr4-build-versioning branch from b9924d7 to ed2e0e2 Compare April 7, 2026 18:58
@dosubot dosubot bot removed the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 7, 2026
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Apr 7, 2026
@NETIZEN-11 NETIZEN-11 force-pushed the feat/issue-4450-pr4-build-versioning branch from ed2e0e2 to 114441b Compare April 7, 2026 19:00
@NETIZEN-11
Copy link
Copy Markdown
Author

@liamfallon Good catch, thanks for pointing this out!

You're right — the previous implementation was incorrectly picking the latest tag even for development builds.

I've updated the logic to:

  • Use the tag only when the commit exactly matches a tag and the working tree is clean
  • Fall back to v0.0.0-dev+<commit> for development/dirty builds

This should now produce the expected version string. Please take another look.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Use git describe --exact-match to detect tagged commits
- Check for dirty working tree with git status --porcelain
- Use tag version ONLY if exact match AND clean working tree
- Otherwise fallback to v0.0.0-dev+<commit-hash> format
- Fixes issue where development builds showed old release tags

This ensures that:
1. Tagged commits with clean tree show release version (e.g., v1.0.0-beta.62)
2. Development builds show v0.0.0-dev+<commit-hash> format
3. Dirty working tree always shows dev version

Signed-off-by: NETIZEN-11 <niteshkumar121411@gmail.com>
@NETIZEN-11 NETIZEN-11 force-pushed the feat/issue-4450-pr4-build-versioning branch from 114441b to 805a22c Compare April 7, 2026 19:05
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update Go code lgtm size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants