[Fix] Refactoring calcolo versione CI/CD: usa git describe invece di dotnet msbuild
Problemi risolti: - GitHub Windows: errore PowerShell 'Missing closing )' causato da (cd Dir; cmd) sintassi bash non valida in PowerShell - GitHub Linux: versione 1.0.0 invece di 2.3.2 perche il tag v2.3.2 esiste solo su Gitea e non su GitHub, quindi MinVer trovava il vecchio tag v1.0.0 Soluzione: - Sostituito dotnet msbuild -getProperty:Version con git describe --tags --abbrev=0 che e lo strumento nativo Git per ottenere l'ultimo tag raggiungibile - Funziona identicamente su Linux (bash) e Windows (PowerShell) - Non richiede dotnet installato ne accesso al .git dentro Docker - Rimosso il dotnet build intermedio sul runner (non piu necessario) - Corretti i percorsi version.json: ora usa Data_Coupler/wwwroot/version.json dal root del repo invece di wwwroot/ relativo dopo cd
This commit is contained in:
@@ -38,28 +38,22 @@ jobs:
|
||||
with:
|
||||
dotnet-version: '9.0.x'
|
||||
|
||||
- name: Generate version.json with MinVer
|
||||
- name: Calcola versione e genera version.json
|
||||
run: |
|
||||
# Fetch all tags for MinVer to work correctly
|
||||
# Calcola versione tramite git describe (non richiede dotnet build)
|
||||
git fetch --tags --force
|
||||
|
||||
# Build project to trigger MinVer (calcola versione automaticamente)
|
||||
cd Data_Coupler
|
||||
dotnet build -c Release /p:ContinuousIntegrationBuild=true
|
||||
|
||||
# Extract version calculated by MinVer from build output
|
||||
VERSION=$(dotnet msbuild -getProperty:Version -p:ContinuousIntegrationBuild=true 2>/dev/null | tail -1)
|
||||
|
||||
# Fallback if MinVer fails (no tags)
|
||||
if [ -z "$VERSION" ] || [ "$VERSION" = "0.0.0-alpha.0" ]; then
|
||||
echo "Warning: No git tags found. MinVer returned default. Using fallback."
|
||||
VERSION="2.3.2-alpha.0.$(git rev-list --count HEAD)"
|
||||
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
|
||||
if [ -z "$LATEST_TAG" ]; then
|
||||
echo "Warning: Nessun tag Git trovato. Uso fallback."
|
||||
VERSION="2.3.2"
|
||||
else
|
||||
VERSION="${LATEST_TAG#v}"
|
||||
fi
|
||||
|
||||
echo "MinVer calculated version: $VERSION"
|
||||
echo "Versione calcolata: $VERSION (da tag: $LATEST_TAG)"
|
||||
|
||||
# Create version.json
|
||||
cat > wwwroot/version.json <<EOF
|
||||
# Genera version.json
|
||||
cat > Data_Coupler/wwwroot/version.json <<EOF
|
||||
{
|
||||
"version": "${VERSION}",
|
||||
"commitSha": "${GITHUB_SHA:0:7}",
|
||||
@@ -70,8 +64,7 @@ jobs:
|
||||
EOF
|
||||
|
||||
echo "Generated version.json:"
|
||||
cat wwwroot/version.json
|
||||
cd ..
|
||||
cat Data_Coupler/wwwroot/version.json
|
||||
|
||||
# Esporta la versione come variabile d'ambiente per il Docker build
|
||||
echo "APP_VERSION=$VERSION" >> "$GITHUB_ENV"
|
||||
@@ -181,33 +174,26 @@ jobs:
|
||||
dotnet --version
|
||||
shell: pwsh
|
||||
|
||||
- name: Generate version.json with MinVer
|
||||
- name: Calcola versione e genera version.json
|
||||
run: |
|
||||
# Fetch all tags for MinVer to work correctly
|
||||
# Calcola versione tramite git describe (non richiede dotnet build)
|
||||
git fetch --tags --force
|
||||
|
||||
# Build project to trigger MinVer
|
||||
cd Data_Coupler
|
||||
dotnet build -c Release /p:ContinuousIntegrationBuild=true
|
||||
|
||||
# Extract version calculated by MinVer
|
||||
$VERSION = dotnet msbuild -getProperty:Version -p:ContinuousIntegrationBuild=true 2>$null | Select-Object -Last 1
|
||||
|
||||
# Fallback if MinVer fails (no tags)
|
||||
if ([string]::IsNullOrWhiteSpace($VERSION) -or $VERSION -eq "0.0.0-alpha.0") {
|
||||
Write-Host "Warning: No git tags found. MinVer returned default. Using fallback."
|
||||
$commitCount = git rev-list --count HEAD
|
||||
$VERSION = "2.3.2-alpha.0.$commitCount"
|
||||
$LATEST_TAG = git describe --tags --abbrev=0 2>$null
|
||||
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($LATEST_TAG)) {
|
||||
Write-Host "Warning: Nessun tag Git trovato. Uso fallback."
|
||||
$VERSION = "2.3.2"
|
||||
} else {
|
||||
$VERSION = $LATEST_TAG -replace '^v', ''
|
||||
}
|
||||
|
||||
Write-Host "MinVer calculated version: $VERSION"
|
||||
Write-Host "Versione calcolata: $VERSION (da tag: $LATEST_TAG)"
|
||||
|
||||
$COMMIT_SHA = "${{ github.sha }}"
|
||||
$SHORT_SHA = $COMMIT_SHA.Substring(0, 7)
|
||||
$BRANCH = "${{ github.ref_name }}"
|
||||
$BUILD_DATE = (Get-Date).ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss UTC")
|
||||
|
||||
# Create version.json
|
||||
# Genera version.json
|
||||
$versionJson = @{
|
||||
version = $VERSION
|
||||
commitSha = $SHORT_SHA
|
||||
@@ -216,11 +202,10 @@ jobs:
|
||||
buildEnvironment = "Gitea Actions"
|
||||
} | ConvertTo-Json
|
||||
|
||||
$versionJson | Out-File -FilePath "wwwroot\version.json" -Encoding UTF8
|
||||
$versionJson | Out-File -FilePath "Data_Coupler\wwwroot\version.json" -Encoding UTF8
|
||||
|
||||
Write-Host "Generated version.json:"
|
||||
Get-Content "wwwroot\version.json"
|
||||
cd ..
|
||||
Get-Content "Data_Coupler\wwwroot\version.json"
|
||||
|
||||
# Esporta la versione come variabile d'ambiente per il Docker build
|
||||
"APP_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
|
||||
Reference in New Issue
Block a user