|
1 | 1 | #!/bin/sh -e |
2 | 2 |
|
3 | 3 | # parse the current git commit hash |
4 | | -COMMIT=`git rev-parse HEAD` |
| 4 | +COMMIT=`git rev-parse --short=8 HEAD` |
5 | 5 |
|
6 | | -# check if the current commit has a matching tag |
7 | | -TAG=$(git describe --exact-match --abbrev=0 --tags ${COMMIT} 2> /dev/null || true) |
| 6 | +# check if the current commit has a matching tag (filter for v* tags, excluding api/) |
| 7 | +TAG=$(git describe --exact-match --abbrev=0 --tags --match="v[0-9]*" 2> /dev/null || true) |
8 | 8 |
|
9 | 9 | # use the matching tag as the version, if available |
10 | 10 | if [ -z "$TAG" ]; then |
11 | | - VERSION=$COMMIT |
| 11 | + # No exact tag on current commit, find the last version tag and bump minor version |
| 12 | + # Get all tags matching v[0-9]*, sort them, and take the last one |
| 13 | + LAST_TAG=$(git tag --list "v[0-9]*" --sort=-version:refname | head -1) |
| 14 | + |
| 15 | + if [ -z "$LAST_TAG" ]; then |
| 16 | + # No tags found, use v0.1.0 as fallback |
| 17 | + BASE_VERSION="v0.1.0" |
| 18 | + else |
| 19 | + # Parse the last tag and bump minor version |
| 20 | + # Remove 'v' prefix |
| 21 | + TAG_WITHOUT_V="${LAST_TAG#v}" |
| 22 | + |
| 23 | + # Split version into parts (major.minor.patch) |
| 24 | + MAJOR=$(echo "$TAG_WITHOUT_V" | cut -d. -f1) |
| 25 | + MINOR=$(echo "$TAG_WITHOUT_V" | cut -d. -f2) |
| 26 | + PATCH=$(echo "$TAG_WITHOUT_V" | cut -d. -f3) |
| 27 | + |
| 28 | + # Bump minor version |
| 29 | + MINOR=$((MINOR + 1)) |
| 30 | + |
| 31 | + # Construct base version with bumped minor |
| 32 | + BASE_VERSION="v${MAJOR}.${MINOR}.0" |
| 33 | + fi |
| 34 | + |
| 35 | + # Get commit timestamp in YYYYMMDDhhmmss format |
| 36 | + TIMESTAMP=$(git log -1 --format=%ci HEAD | sed 's/[-: ]//g' | cut -c1-14) |
| 37 | + |
| 38 | + # Construct pseudo-version |
| 39 | + VERSION="${BASE_VERSION}-${TIMESTAMP}-${COMMIT}" |
12 | 40 | else |
13 | 41 | VERSION=$TAG |
14 | 42 | fi |
|
0 commit comments