Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 15, 2025

This PR implements automatic VERSION file updates with GitVersion semver on each checkout, allowing developers to easily see what version they're currently working on.

Changes Made

1. Created VERSION File

  • Added a VERSION file in the repository root that gets automatically updated
  • Initially set to 1.0.0 and managed by the version update system

2. Version Update Script

Created update-version.sh that intelligently determines the current version:

# Tries GitVersion first for proper semver calculation
dotnet-gitversion -config .gitversion -showvariable MajorMinorPatch

# Falls back to git describe when GitVersion returns defaults
git describe --tags --always --dirty

The script handles various scenarios:

  • GitVersion available: Uses calculated semver from GitVersion configuration
  • GitVersion returns default (1.0.0): Falls back to extracting version from git tags
  • Git describe: Extracts meaningful version from tag patterns like feature_larasets_5.10.25.10.2-2-g51926a7
  • Error handling: Maintains existing VERSION file if no version can be determined

3. Enhanced Post-Checkout Hook

Modified src/githooks/_post-checkout.sh to automatically call the version update script:

# Update VERSION file with current GitVersion semver
if [ -f "./update-version.sh" ]; then
  ./update-version.sh || zz_log w "Failed to update VERSION file"
else
  zz_log w "update-version.sh script not found, skipping VERSION file update"
fi

How It Works

  1. On Checkout: The post-checkout hook runs automatically when switching branches/commits
  2. Version Detection: The script determines the current version using GitVersion or git describe fallback
  3. File Update: The VERSION file is updated with the detected semver
  4. Developer Visibility: Developers can run cat VERSION to see their current working version

Example Usage

# After checking out any branch
$ cat VERSION
5.10.2-3-g51926a7

# The file automatically updates on checkout
$ git checkout main
$ cat VERSION
5.10.3-1-g8a2b3c4

This integrates seamlessly with the existing GitVersion configuration and devcontainer features workflow, requiring no manual intervention once the githooks feature is installed and configured.

Fixes #10.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] VERSION file update feat: add VERSION file update with gitversion semver on checkout Sep 15, 2025
@Copilot Copilot AI requested a review from tomgrv September 15, 2025 21:26
@tomgrv tomgrv self-requested a review September 15, 2025 21:30
Copy link
Owner

@tomgrv tomgrv left a comment

Choose a reason for hiding this comment

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

@copilot update package version

@tomgrv tomgrv marked this pull request as ready for review September 18, 2025 09:43
@Copilot Copilot AI review requested due to automatic review settings September 18, 2025 09:43
Copy link

@Copilot 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 automatic VERSION file updates using GitVersion semver on checkout to provide developers with visibility into their current working version.

  • Added a VERSION file that gets automatically updated with semver information
  • Created an intelligent version update script that tries GitVersion first, then falls back to git describe
  • Enhanced the post-checkout hook to automatically update the VERSION file on branch/commit switches

Reviewed Changes

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

File Description
update-version.sh New script that determines current version using GitVersion or git describe fallback
src/githooks/_post-checkout.sh Enhanced to call the version update script automatically
VERSION New file containing the current version string

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -0,0 +1,54 @@
#!/bin/bash
Copy link
Preview

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

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

The script is missing the executable permission setting. Consider adding a comment about setting executable permissions or ensuring the file is created with proper permissions.

Suggested change
#!/bin/bash
#!/bin/bash
# Ensure this script is executable: chmod +x update-version.sh

Copilot uses AI. Check for mistakes.

Comment on lines +24 to +27
# Extract version from patterns like:
# feature_larasets_5.10.2-1-g97bdb34 -> 5.10.2-1-g97bdb34
# feature_larasets_5.10.2 -> 5.10.2
echo "$describe_output" | sed -E 's/^[^_]*_[^_]*_([0-9]+\.[0-9]+\.[0-9]+.*)/\1/' | head -1
Copy link
Preview

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

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

The regex pattern is complex and assumes a specific tag naming convention (feature_larasets_X.Y.Z). Consider adding a comment explaining the expected tag format or making the pattern more flexible to handle different tag naming conventions.

Suggested change
# Extract version from patterns like:
# feature_larasets_5.10.2-1-g97bdb34 -> 5.10.2-1-g97bdb34
# feature_larasets_5.10.2 -> 5.10.2
echo "$describe_output" | sed -E 's/^[^_]*_[^_]*_([0-9]+\.[0-9]+\.[0-9]+.*)/\1/' | head -1
# Extract version from tags ending with a semantic version, e.g.:
# feature_larasets_5.10.2-1-g97bdb34 -> 5.10.2-1-g97bdb34
# release_5.10.2 -> 5.10.2
# v5.10.2 -> 5.10.2
# The regex matches any tag ending with X.Y.Z (optionally with suffixes).
echo "$describe_output" | sed -E 's/.*[_v]([0-9]+\.[0-9]+\.[0-9]+([-a-zA-Z0-9\.]*)?)/\1/' | head -1

Copilot uses AI. Check for mistakes.

# Try to get MajorMinorPatch from GitVersion
GITVERSION_OUTPUT=$(dotnet-gitversion -config .gitversion -showvariable MajorMinorPatch 2>/dev/null || echo "")
# Check if output is a valid version number (only digits and dots) and not default
if [ -n "$GITVERSION_OUTPUT" ] && echo "$GITVERSION_OUTPUT" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$' && [ "$GITVERSION_OUTPUT" != "1.0.0" ]; then
Copy link
Preview

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

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

The hardcoded exclusion of '1.0.0' as a default value may not be reliable if a project legitimately has version 1.0.0. Consider checking for GitVersion's actual error conditions or configuration instead of excluding specific version numbers.

Suggested change
if [ -n "$GITVERSION_OUTPUT" ] && echo "$GITVERSION_OUTPUT" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$' && [ "$GITVERSION_OUTPUT" != "1.0.0" ]; then
if [ -n "$GITVERSION_OUTPUT" ] && echo "$GITVERSION_OUTPUT" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then

Copilot uses AI. Check for mistakes.

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.

VERSION file update
2 participants