[Fix] Passa versione MinVer come build-arg al Docker per evitare errore MINVER1001

Il problema era che MinVer veniva eseguito dentro il container Docker dove la
directory .git non esiste, causando il warning MINVER1001 e l'uso di 0.0.0-alpha.0
(poi sostituito dal fallback hardcoded 2.1.0).

Soluzione:
- La versione viene calcolata sul runner CI/CD (dove git e' disponibile)
- Esportata come variabile d'ambiente APP_VERSION via GITHUB_ENV
- Passata al Docker build tramite --build-arg APP_VERSION
- Nei Dockerfile aggiunto ARG APP_VERSION e /p:MinVerVersionOverride per imporla
  a MinVer senza che tenti di accedere a git (assente nel container)
- ARG ridichiarato dopo ogni FROM in multi-stage build (comportamento Docker)
This commit is contained in:
Alessio Dal Santo
2026-03-20 18:25:54 +01:00
parent 4262fd6d71
commit c15e6c9065
4 changed files with 55 additions and 6 deletions
+33 -1
View File
@@ -34,6 +34,23 @@ jobs:
with:
fetch-depth: 0 # Necessario per MinVer: deve percorrere tutta la storia Git per trovare i tag
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Calcola versione con MinVer
run: |
git fetch --tags --force
VERSION=$(cd Data_Coupler && dotnet msbuild -getProperty:Version -p:ContinuousIntegrationBuild=true 2>/dev/null | tail -1)
if [ -z "$VERSION" ] || [ "$VERSION" = "0.0.0-alpha.0" ]; then
echo "Warning: MinVer non ha trovato tag. Uso fallback."
VERSION="2.3.2-alpha.0.$(git rev-list --count HEAD)"
fi
echo "Versione calcolata: $VERSION"
echo "APP_VERSION=$VERSION" >> "$GITHUB_ENV"
shell: bash
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
@@ -77,6 +94,8 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
build-args: |
APP_VERSION=${{ env.APP_VERSION }}
- name: Generate artifact attestation
if: github.event_name != 'pull_request'
@@ -100,6 +119,19 @@ jobs:
with:
fetch-depth: 0 # Necessario per MinVer: deve percorrere tutta la storia Git per trovare i tag
- name: Calcola versione con MinVer
run: |
git fetch --tags --force
$VERSION = (cd Data_Coupler; dotnet msbuild -getProperty:Version -p:ContinuousIntegrationBuild=true 2>$null | Select-Object -Last 1)
if ([string]::IsNullOrWhiteSpace($VERSION) -or $VERSION -eq "0.0.0-alpha.0") {
Write-Host "Warning: MinVer non ha trovato tag. Uso fallback."
$commitCount = git rev-list --count HEAD
$VERSION = "2.3.2-alpha.0.$commitCount"
}
Write-Host "Versione calcolata: $VERSION"
"APP_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
shell: pwsh
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
@@ -132,7 +164,7 @@ jobs:
$imageName = "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}".ToLower()
# Build with temporary tag
docker build -t "${imageName}:temp-windows" -f Dockerfile.windows .
docker build --build-arg "APP_VERSION=$env:APP_VERSION" -t "${imageName}:temp-windows" -f Dockerfile.windows .
# Parse and push all tags
$tags = "${{ steps.meta.outputs.tags }}" -split "`n"