2626 - uses : actions/checkout@v4
2727 with :
2828 fetch-depth : 0 # Fetch all history for proper versioning
29+ fetch-tags : true # Explicitly fetch all tags
2930 - name : Set up Python ${{ matrix.python-version }}
3031 uses : actions/setup-python@v5
3132 with :
5960 - uses : actions/checkout@v4
6061 with :
6162 fetch-depth : 0 # Fetch all history for proper versioning
63+ fetch-tags : true # Explicitly fetch all tags
6264 - name : Set up Python ${{ matrix.python-version }}
6365 uses : actions/setup-python@v5
6466 with :
8486 - name : Checkout
8587 uses : actions/checkout@v4
8688 with :
87- fetch-depth : 0
89+ fetch-depth : 0 # Fetch all history for proper versioning
90+ fetch-tags : true # Explicitly fetch all tags
8891
8992 - name : Set up Docker Buildx
9093 uses : docker/setup-buildx-action@v3
@@ -153,6 +156,7 @@ jobs:
153156 - uses : actions/checkout@v4
154157 with :
155158 fetch-depth : 0 # Fetch all history for proper versioning
159+ fetch-tags : true # Explicitly fetch all tags
156160
157161 # PyPI deployment (only for Python 3.x representative)
158162 - name : Set up Python
@@ -213,6 +217,27 @@ jobs:
213217 flavor : |
214218 latest=${{ matrix.python-version == '3.11' }}
215219
220+ - name : Get Version for Docker Build
221+ id : get_version
222+ run : |
223+ # Ensure we have tags
224+ git fetch --tags --force
225+
226+ # For tagged builds, use the exact tag
227+ if [[ "$GITHUB_REF" == refs/tags/* ]]; then
228+ TAG=${GITHUB_REF#refs/tags/}
229+ # Keep the v prefix for git tags
230+ VERSION="$TAG"
231+ echo "Using tag version: $VERSION"
232+ else
233+ # Use git version with v prefix
234+ VERSION=$(git describe --tags --always 2>/dev/null || echo "v0.1.0")
235+ echo "Using git version: $VERSION"
236+ fi
237+
238+ # Output for GitHub Actions
239+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
240+
216241 - name : Build and Push Docker Image
217242 uses : docker/build-push-action@v5
218243 with :
@@ -222,5 +247,6 @@ jobs:
222247 labels : ${{ steps.meta.outputs.labels }}
223248 build-args : |
224249 PYTHON_VERSION=${{ matrix.python-version }}
250+ VERSION=${{ steps.get_version.outputs.VERSION }}
225251 cache-from : type=gha
226252 cache-to : type=gha,mode=max
0 commit comments