Skip to content

makefile: extract git commands#10514

Open
Tema wants to merge 1 commit intotikv:masterfrom
Tema:patch-1
Open

makefile: extract git commands#10514
Tema wants to merge 1 commit intotikv:masterfrom
Tema:patch-1

Conversation

@Tema
Copy link
Copy Markdown
Contributor

@Tema Tema commented Mar 31, 2026

What problem does this PR solve?

Issue Number: Close #10525

What is changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Code changes

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

Release note

None.

Summary by CodeRabbit

  • Chores
    • Optimized the build process by precomputing VCS commit and branch once and reusing them in build metadata.
    • Streamlined dashboard versioning to rely on the configured release version (left unset in CI), improving consistency and build determinism.

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. contribution This PR is from a community contributor. dco-signoff: no Indicates the PR's author has not signed dco. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Mar 31, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot bot commented Mar 31, 2026

Hi @Tema. Thanks for your PR.

I'm waiting for a tikv 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.

@ti-chi-bot ti-chi-bot bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 31, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

The Makefile now computes GITHASH and GITBRANCH once via git rev-parse and references them in LDFLAGS; when DASHBOARD != 0, the dashboard PDVersion linker value uses $(RELEASE_VERSION) instead of an inline git describe invocation.

Changes

Cohort / File(s) Summary
Build Variable Optimization
Makefile
Adds GITHASH := $(shell git rev-parse HEAD) and GITBRANCH := $(shell git rev-parse --abbrev-ref HEAD) and updates LDFLAGS to reference these variables. Replaces inline git describe --tags --dirty --always with $(RELEASE_VERSION) for dashboard PDVersion when building the dashboard.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped through lines of make and cheer,
Cached my hashes, held them near.
Branches tucked in neat and snug,
Builds now hum with lighter mug.
🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is incomplete. The issue number placeholder 'Close #xxx' was not replaced with an actual issue reference, and the commit message body is empty. Replace 'Close #xxx' with the actual issue number (e.g., 'Close #10525') and provide a detailed commit message explaining the changes made to the Makefile.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'makefile: extract git commands' is concise and clearly summarizes the main change: extracting git command substitutions into Makefile variables.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Makefile`:
- Around line 70-71: GITHASH and GITBRANCH are being eagerly evaluated with :=
causing git commands to run at Makefile parse time; change their assignment to
conditional/simple assignment (use ?= like RELEASE_VERSION) and provide safe
fallback defaults (e.g., "unknown" or empty) so that git rev-parse is only
executed when requested and not during every make invocation; update the lines
that define GITHASH and GITBRANCH to mirror the RELEASE_VERSION pattern so they
don't fail in non-git or shallow-clone environments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a5c873d8-fe25-49b4-b25b-406fc26997e9

📥 Commits

Reviewing files that changed from the base of the PR and between 0a0dcfd and 267af44.

📒 Files selected for processing (1)
  • Makefile

Comment on lines +70 to +71
GITHASH := $(shell git rev-parse HEAD)
GITBRANCH := $(shell git rev-parse --abbrev-ref HEAD)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify current assignment flavor and linker-flag usage (read-only).
rg -n '^(GITHASH|GITBRANCH)\s*[:?]?=' Makefile -C2
rg -n 'PDGitHash|PDGitBranch' Makefile -C2

Repository: tikv/pd

Length of output: 630


🏁 Script executed:

#!/bin/bash
# Check for other assignments to GITHASH or GITBRANCH
rg -n 'GITHASH|GITBRANCH' Makefile

# Check how other shell-based assignments are handled in Makefile
rg -n 'shell.*git|:=.*\$\(shell' Makefile | head -20

Repository: tikv/pd

Length of output: 899


🏁 Script executed:

#!/bin/bash
# Check for CI guards or checks for git context
rg -n '\.git|GIT_DIR|git.*error|non-git' Makefile -C1

# Check if any targets skip git operations
rg -n 'ifeq.*git|ifdef.*GIT' Makefile

Repository: tikv/pd

Length of output: 511


Avoid eager git command execution during Makefile parse.

On Lines 70-71, := runs git rev-parse for every make invocation (including non-build targets), which can fail in non-git contexts (shallow clones, docker builds) and inject empty values. Use ?= with fallbacks to match the pattern already established by RELEASE_VERSION on Line 65.

🔧 Suggested change
-GITHASH := $(shell git rev-parse HEAD)
-GITBRANCH := $(shell git rev-parse --abbrev-ref HEAD)
+GITHASH ?= $(shell git rev-parse HEAD 2>/dev/null || echo None)
+GITBRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo None)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
GITHASH := $(shell git rev-parse HEAD)
GITBRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GITHASH ?= $(shell git rev-parse HEAD 2>/dev/null || echo None)
GITBRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo None)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Makefile` around lines 70 - 71, GITHASH and GITBRANCH are being eagerly
evaluated with := causing git commands to run at Makefile parse time; change
their assignment to conditional/simple assignment (use ?= like RELEASE_VERSION)
and provide safe fallback defaults (e.g., "unknown" or empty) so that git
rev-parse is only executed when requested and not during every make invocation;
update the lines that define GITHASH and GITBRANCH to mirror the RELEASE_VERSION
pattern so they don't fail in non-git or shallow-clone environments.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.92%. Comparing base (3eb99ae) to head (7e4316e).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10514      +/-   ##
==========================================
+ Coverage   78.88%   78.92%   +0.03%     
==========================================
  Files         530      531       +1     
  Lines       71548    71632      +84     
==========================================
+ Hits        56439    56533      +94     
+ Misses      11092    11071      -21     
- Partials     4017     4028      +11     
Flag Coverage Δ
unittests 78.92% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: artem_danilov <artem.danilov@airbnb.com>
@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. and removed dco-signoff: no Indicates the PR's author has not signed dco. labels Mar 31, 2026
@bufferflies
Copy link
Copy Markdown
Contributor

What's the difference?

~/Documents/soft/golang/pd/bin/pd-server -V
Release Version: v9.0.0-beta.2.pre-328-g5ef55c918
Edition: Community
Kernel Type: Classic
Git Commit Hash: 5ef55c918795292e83aea368b1c0febdc7d2d965
Git Branch: bugfix/create_keyspace_atomic
UTC Build Time:  2026-03-26 02:12:06

@Tema
Copy link
Copy Markdown
Contributor Author

Tema commented Mar 31, 2026

What's the difference?

@bufferflies no-op for you, but our internal infra now can pass GITHASH and GITBRANCH same way as RELEASE_VERSION. This allows our CI to work with shallow git layers. Please treat it as an enhancement for periphery infra

I have the same for TiDB: pingcap/tidb#67437

@Tema
Copy link
Copy Markdown
Contributor Author

Tema commented Mar 31, 2026

/retest

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot bot commented Mar 31, 2026

@Tema: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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.

@rleungx
Copy link
Copy Markdown
Member

rleungx commented Apr 1, 2026

/ok-to-test

@ti-chi-bot ti-chi-bot bot added ok-to-test Indicates a PR is ready to be tested. and removed needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Apr 1, 2026
@rleungx
Copy link
Copy Markdown
Member

rleungx commented Apr 1, 2026

/retest

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot bot commented Apr 1, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: okJiang

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

The pull request process is described 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

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Apr 1, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot bot commented Apr 1, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-04-01 07:10:58.856635554 +0000 UTC m=+335464.061995611: ☑️ agreed by okJiang.

@ti-chi-bot ti-chi-bot bot added the approved label Apr 1, 2026
@Tema
Copy link
Copy Markdown
Contributor Author

Tema commented Apr 1, 2026

/retest-required

@Tema
Copy link
Copy Markdown
Contributor Author

Tema commented Apr 1, 2026

/retest-required

@Tema
Copy link
Copy Markdown
Contributor Author

Tema commented Apr 1, 2026

@rleungx tests are passed. PTAL

LDFLAGS += -X "github.com/pingcap/tidb-dashboard/pkg/utils/version.InternalVersion=$(shell scripts/describe-dashboard.sh internal-version)"
LDFLAGS += -X "github.com/pingcap/tidb-dashboard/pkg/utils/version.Standalone=No"
LDFLAGS += -X "github.com/pingcap/tidb-dashboard/pkg/utils/version.PDVersion=$(shell git describe --tags --dirty --always)"
LDFLAGS += -X "github.com/pingcap/tidb-dashboard/pkg/utils/version.PDVersion=$(RELEASE_VERSION)"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If RUN_CI is equal to 1, will the PDVersion turn into None?

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

Labels

approved contribution This PR is from a community contributor. dco-signoff: yes Indicates the PR's author has signed the dco. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. 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.

CI: Provide GITHASH and GITBRANCH to Makefile externally

4 participants