-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add VERSION file update with gitversion semver on checkout #11
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
base: main
Are you sure you want to change the base?
Changes from all commits
97bdb34
2c387f2
51926a7
b2566d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5.10.2-3-g51926a7-dirty |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,54 @@ | ||||||||||||||||||||||
#!/bin/bash | ||||||||||||||||||||||
# Script to update VERSION file with GitVersion semver | ||||||||||||||||||||||
# This script handles both GitVersion tool and fallback scenarios | ||||||||||||||||||||||
|
||||||||||||||||||||||
set -e | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Define the VERSION file path | ||||||||||||||||||||||
VERSION_FILE="VERSION" | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Function to update VERSION file | ||||||||||||||||||||||
update_version_file() { | ||||||||||||||||||||||
local version="$1" | ||||||||||||||||||||||
if [ -n "$version" ]; then | ||||||||||||||||||||||
echo "$version" > "$VERSION_FILE" | ||||||||||||||||||||||
echo "Updated VERSION file to: $version" | ||||||||||||||||||||||
else | ||||||||||||||||||||||
echo "Warning: Could not determine version" | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Function to extract semver from git describe | ||||||||||||||||||||||
extract_semver_from_describe() { | ||||||||||||||||||||||
local describe_output="$1" | ||||||||||||||||||||||
# 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 | ||||||||||||||||||||||
Comment on lines
+24
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Try GitVersion first (if available and working) | ||||||||||||||||||||||
if command -v dotnet-gitversion >/dev/null 2>&1; then | ||||||||||||||||||||||
# 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 | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||
update_version_file "$GITVERSION_OUTPUT" | ||||||||||||||||||||||
exit 0 | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Fallback to git describe | ||||||||||||||||||||||
GIT_DESCRIBE=$(git describe --tags --always --dirty 2>/dev/null || echo "") | ||||||||||||||||||||||
if [ -n "$GIT_DESCRIBE" ]; then | ||||||||||||||||||||||
FALLBACK_VERSION=$(extract_semver_from_describe "$GIT_DESCRIBE") | ||||||||||||||||||||||
update_version_file "$FALLBACK_VERSION" | ||||||||||||||||||||||
exit 0 | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Final fallback - keep existing version or use default | ||||||||||||||||||||||
if [ -f "$VERSION_FILE" ]; then | ||||||||||||||||||||||
echo "Warning: Could not determine new version, keeping existing VERSION file" | ||||||||||||||||||||||
else | ||||||||||||||||||||||
update_version_file "1.0.0" | ||||||||||||||||||||||
fi |
There was a problem hiding this comment.
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.
Copilot uses AI. Check for mistakes.