Skip to content

Commit dbf2ca2

Browse files
committed
fix VERSION to include only tag or dev hash
1 parent f22179a commit dbf2ca2

1 file changed

Lines changed: 38 additions & 13 deletions

File tree

conda_build.sh

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,53 @@
11
#!/bin/bash
22
# This script helps build conda package with proper version extraction from git
33

4-
# Get the git describe tag (e.g. v0.4.0)
4+
# Get git information for versioning
5+
# Get full git describe output (tag-commits-hash) if on an untagged commit
6+
export GIT_DESCRIBE=$(git describe --tags 2>/dev/null || echo "")
7+
8+
# Get just the most recent tag
59
export GIT_DESCRIBE_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
10+
11+
# Get commit info
612
export GIT_FULL_HASH=$(git rev-parse HEAD)
713
export SHORT_HASH=${GIT_FULL_HASH:0:7}
814

915
# Generate a date-based version component
1016
export BUILD_DATE=$(date +"%Y%m%d")
1117

12-
# Always use a version that includes commit info
13-
if [ -z "$GIT_DESCRIBE_TAG" ]; then
14-
# No tag exists, use only commit hash
15-
export VERSION="0.0.0.dev${BUILD_DATE}+${SHORT_HASH}"
16-
echo "No git tag found, using version: $VERSION"
17-
else
18+
# Check if we're exactly on a tag
19+
if git describe --exact-match --tags HEAD >/dev/null 2>&1; then
20+
# We are exactly on a tag, use just the tag version
21+
TAG_VERSION=$GIT_DESCRIBE_TAG
22+
1823
# Remove 'v' prefix from tag for conda versioning
19-
if [[ $GIT_DESCRIBE_TAG == v* ]]; then
20-
export GIT_DESCRIBE_TAG="${GIT_DESCRIBE_TAG:1}"
24+
if [[ $TAG_VERSION == v* ]]; then
25+
TAG_VERSION="${TAG_VERSION:1}"
26+
fi
27+
28+
export VERSION="$TAG_VERSION"
29+
echo "On exact tag commit, using version: $VERSION"
30+
else
31+
# Not on a tag, use tag-commits-hash format (convert to PEP 440 compatible version)
32+
if [ -z "$GIT_DESCRIBE" ]; then
33+
# No tag exists at all, fallback to dev version
34+
export VERSION="0.0.0.dev${BUILD_DATE}+${SHORT_HASH}"
35+
echo "No git tag found at all, using version: $VERSION"
36+
else
37+
# Process the git describe output to create PEP 440 compatible version
38+
# git describe format is typically: tag-N-gHASH (e.g., v1.2.3-5-g123abc)
39+
# Extract parts from git describe output
40+
TAG=$(echo $GIT_DESCRIBE | sed -E 's/^(v?[0-9]+\.[0-9]+\.[0-9]+)(-.*)?$/\1/')
41+
# Remove 'v' prefix from tag if present
42+
if [[ $TAG == v* ]]; then
43+
TAG="${TAG:1}"
44+
fi
45+
# Extract commit count since tag (N from tag-N-gHASH)
46+
COMMITS=$(echo $GIT_DESCRIBE | sed -E 's/^v?[0-9]+\.[0-9]+\.[0-9]+-([0-9]+)-.*/\1/' 2>/dev/null || echo "0")
47+
# Format as PEP 440 compatible version: tag.devN+hash
48+
export VERSION="${TAG}.dev${COMMITS}+${SHORT_HASH}"
49+
echo "Not on exact tag commit, using version: $VERSION"
2150
fi
22-
23-
# Use tag + commit hash
24-
export VERSION="${GIT_DESCRIBE_TAG}.dev${BUILD_DATE}+${SHORT_HASH}"
25-
echo "Using version: $VERSION"
2651
fi
2752

2853
# Export the VERSION to environment for conda-build to use

0 commit comments

Comments
 (0)