Skip to content

feat: add version subcommand to display build metadata #119

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 5 commits into from
Apr 15, 2025

Conversation

joe-ton
Copy link
Contributor

@joe-ton joe-ton commented Apr 5, 2025

Feature: version Subcommand for GitHub MCP Server CLI

This PR adds a new version subcommand to the GitHub MCP Server CLI, providing build metadata for better visibility and traceability in development and CI environments.

What’s Included

  • Adds server version command using Cobra
  • Outputs:
    • Semantic version
    • Git commit hash
    • UTC build date
### Build Metadata Injection
go build -ldflags "\
  -X main.version=v0.1.0 \
  -X main.commit=$(git rev-parse --short HEAD) \
  -X main.date=$(date -u +%Y-%m-%d)" \
  -o server ./cmd/github-mcp-server

### Example Output
$ ./server version
GitHub MCP Server
Version: v0.1.0
Commit: abc1234
Build Date: 2025-04-04
  

Perhaps work on Makefiles / automation (build + make) for later.

@joe-ton
Copy link
Contributor Author

joe-ton commented Apr 5, 2025

✅ Rebased with main and resolved conflicts.
✅ PR passes local testing.
Let me know if anything else is needed!

@juruen
Copy link
Collaborator

juruen commented Apr 5, 2025

@joe-ton

There's already a -v flag to display version info:

 % ./github-mcp-server -v
server version v0.1.0 (270bbf7) 2025-04-05

isn't that enough?

@SamMorrowDrums
Copy link
Collaborator

I believe we can add a SetVersionTemplate param to the root cobra command or similar to improve the output, as I agree that the output could be nicer, and I like the format suggested in this PR.

But as @juruen mentioned, the --version flag, and ldflags are already being set in the docker builds and binary builds specified in the .goreleaser file in the repo root.

@joe-ton
Copy link
Contributor Author

joe-ton commented Apr 5, 2025

@juruen @SamMorrowDrums

Good point -- I noticed the -v flag after opening the PR. My intent here was improving the clarity and completeness of the build metadata for easier traceability in CI/CD environments. If we're aligned on keeping the simpler flag, I'm happy to refactor the existing -v output using SetVersionTemplate as Sam suggested. Would this work for you both?

@SamMorrowDrums
Copy link
Collaborator

Yes, definitely.

@joe-ton joe-ton closed this Apr 5, 2025
@joe-ton joe-ton force-pushed the feat/version-subcommand branch from deacd75 to 6b02799 Compare April 5, 2025 21:54
@joe-ton joe-ton reopened this Apr 5, 2025
@joe-ton
Copy link
Contributor Author

joe-ton commented Apr 5, 2025

@SamMorrowDrums @juruen

Implemented version output improvement using SetVersionTemplate. Ready for review and workflow approval. Let me know if any additional tweaks are needed!

@joe-ton
Copy link
Contributor Author

joe-ton commented Apr 5, 2025

For easy reproduction and verification, you can use the following:

In project root:

Build:

go build -ldflags "\
  -X main.version=v0.1.0 \
  -X main.commit=$(git rev-parse --short HEAD) \
  -X main.date=$(date -u +%Y-%m-%d)" \
  -o server ./cmd/github-mcp-server

Test:

./server --version

@SamMorrowDrums
Copy link
Collaborator

@joe-ton I fixed spaces instead of tabs, and because the template command uses a template library, I made use of it - although it doesn't make much difference. The output is the same.

GitHub MCP Server
Version: v0.1.0
Commit: ff3036d
Build Date: 2025-04-15

SamMorrowDrums
SamMorrowDrums previously approved these changes Apr 15, 2025
@SamMorrowDrums
Copy link
Collaborator

@joe-ton the tabs not spaces thing for go is important, and you should have go-fmt run on save in your code editor. The Go tools are great, and will save you a bunch of time!

@SamMorrowDrums SamMorrowDrums merged commit b72a591 into github:main Apr 15, 2025
9 checks passed
@joe-ton
Copy link
Contributor Author

joe-ton commented Apr 15, 2025

@SamMorrowDrums Thanks for accepting the PR. Yes, I need to do go-fmt on my NeoVim config lol Appreciate it!!

@joe-ton joe-ton deleted the feat/version-subcommand branch April 15, 2025 19:14
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.

3 participants