Aggiornamento main #14

Merged
Alessio merged 5 commits from staging into main 2026-03-22 16:25:41 +01:00
4 changed files with 124 additions and 46 deletions
+36 -41
View File
@@ -30,34 +30,30 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 0 # Necessario per MinVer: deve percorrere tutta la storia Git per trovare i tag
- name: Setup .NET - name: Setup .NET
uses: actions/setup-dotnet@v4 uses: actions/setup-dotnet@v4
with: with:
dotnet-version: '9.0.x' dotnet-version: '9.0.x'
- name: Generate version.json with MinVer - name: Calcola versione e genera version.json
run: | run: |
# Fetch all tags for MinVer to work correctly # Calcola versione tramite git describe (non richiede dotnet build)
git fetch --tags --force git fetch --tags --force
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
# Build project to trigger MinVer (calcola versione automaticamente) if [ -z "$LATEST_TAG" ]; then
cd Data_Coupler echo "Warning: Nessun tag Git trovato. Uso fallback."
dotnet build -c Release /p:ContinuousIntegrationBuild=true VERSION="2.3.2"
else
# Extract version calculated by MinVer from build output VERSION="${LATEST_TAG#v}"
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.1.0-alpha.0.$(git rev-list --count HEAD)"
fi fi
echo "MinVer calculated version: $VERSION" echo "Versione calcolata: $VERSION (da tag: $LATEST_TAG)"
# Create version.json # Genera version.json
cat > wwwroot/version.json <<EOF cat > Data_Coupler/wwwroot/version.json <<EOF
{ {
"version": "${VERSION}", "version": "${VERSION}",
"commitSha": "${GITHUB_SHA:0:7}", "commitSha": "${GITHUB_SHA:0:7}",
@@ -68,8 +64,10 @@ jobs:
EOF EOF
echo "Generated version.json:" echo "Generated version.json:"
cat wwwroot/version.json cat Data_Coupler/wwwroot/version.json
cd ..
# Esporta la versione come variabile d'ambiente per il Docker build
echo "APP_VERSION=$VERSION" >> "$GITHUB_ENV"
shell: bash shell: bash
- name: Set up Docker Buildx - name: Set up Docker Buildx
@@ -136,6 +134,7 @@ jobs:
platforms: linux/amd64 platforms: linux/amd64
# Aumenta timeout per registry lenti # Aumenta timeout per registry lenti
build-args: | build-args: |
APP_VERSION=${{ env.APP_VERSION }}
BUILDKIT_STEP_LOG_MAX_SIZE=50000000 BUILDKIT_STEP_LOG_MAX_SIZE=50000000
provenance: false provenance: false
sbom: false sbom: false
@@ -159,7 +158,7 @@ jobs:
steps: steps:
- name: Checkout repository with Git - name: Checkout repository with Git
run: | run: |
git clone --depth 1 --branch ${{ github.ref_name }} https://alessio:%REGISTRY_TOKEN%@gitea.home-nas-ds.org/${{ github.repository }}.git . git clone --branch ${{ github.ref_name }} https://alessio:%REGISTRY_TOKEN%@gitea.home-nas-ds.org/${{ github.repository }}.git .
if not exist Dockerfile.windows ( if not exist Dockerfile.windows (
echo ERROR: Dockerfile.windows not found echo ERROR: Dockerfile.windows not found
exit /b 1 exit /b 1
@@ -175,33 +174,26 @@ jobs:
dotnet --version dotnet --version
shell: pwsh shell: pwsh
- name: Generate version.json with MinVer - name: Calcola versione e genera version.json
run: | run: |
# Fetch all tags for MinVer to work correctly # Calcola versione tramite git describe (non richiede dotnet build)
git fetch --tags --force git fetch --tags --force
$LATEST_TAG = git describe --tags --abbrev=0 2>$null
# Build project to trigger MinVer if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($LATEST_TAG)) {
cd Data_Coupler Write-Host "Warning: Nessun tag Git trovato. Uso fallback."
dotnet build -c Release /p:ContinuousIntegrationBuild=true $VERSION = "2.3.2"
} else {
# Extract version calculated by MinVer $VERSION = $LATEST_TAG -replace '^v', ''
$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.1.0-alpha.0.$commitCount"
} }
Write-Host "MinVer calculated version: $VERSION" Write-Host "Versione calcolata: $VERSION (da tag: $LATEST_TAG)"
$COMMIT_SHA = "${{ github.sha }}" $COMMIT_SHA = "${{ github.sha }}"
$SHORT_SHA = $COMMIT_SHA.Substring(0, 7) $SHORT_SHA = $COMMIT_SHA.Substring(0, 7)
$BRANCH = "${{ github.ref_name }}" $BRANCH = "${{ github.ref_name }}"
$BUILD_DATE = (Get-Date).ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss UTC") $BUILD_DATE = (Get-Date).ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss UTC")
# Create version.json # Genera version.json
$versionJson = @{ $versionJson = @{
version = $VERSION version = $VERSION
commitSha = $SHORT_SHA commitSha = $SHORT_SHA
@@ -210,11 +202,14 @@ jobs:
buildEnvironment = "Gitea Actions" buildEnvironment = "Gitea Actions"
} | ConvertTo-Json } | 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:" Write-Host "Generated version.json:"
Get-Content "wwwroot\version.json" Get-Content "Data_Coupler\wwwroot\version.json"
cd ..
# Esporta la versione come variabile d'ambiente per il Docker build
"APP_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Write-Host "APP_VERSION=$VERSION esportata per Docker build"
shell: pwsh shell: pwsh
- name: Debug - Verify files - name: Debug - Verify files
@@ -265,7 +260,7 @@ jobs:
) )
echo Building Windows Docker image... echo Building Windows Docker image...
docker build -t temp-windows -f Dockerfile.windows . docker build --build-arg APP_VERSION=%APP_VERSION% -t temp-windows -f Dockerfile.windows .
if errorlevel 1 ( if errorlevel 1 (
echo Build failed! echo Build failed!
exit /b 1 exit /b 1
+75 -1
View File
@@ -31,6 +31,42 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
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 e genera version.json
run: |
git fetch --tags --force
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LATEST_TAG" ]; then
echo "Warning: Nessun tag Git trovato su questo remote. Uso fallback."
VERSION="2.3.2"
else
VERSION="${LATEST_TAG#v}"
fi
echo "Versione calcolata: $VERSION (da tag: $LATEST_TAG)"
# Genera version.json
cat > Data_Coupler/wwwroot/version.json <<EOF
{
"version": "${VERSION}",
"commitSha": "${GITHUB_SHA:0:7}",
"branch": "${GITHUB_REF_NAME}",
"buildDate": "$(date -u +"%Y-%m-%d %H:%M:%S UTC")",
"buildEnvironment": "GitHub Actions"
}
EOF
echo "Generated version.json:"
cat Data_Coupler/wwwroot/version.json
echo "APP_VERSION=$VERSION" >> "$GITHUB_ENV"
shell: bash
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
@@ -75,6 +111,8 @@ jobs:
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
platforms: linux/amd64 platforms: linux/amd64
build-args: |
APP_VERSION=${{ env.APP_VERSION }}
- name: Generate artifact attestation - name: Generate artifact attestation
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
@@ -95,6 +133,42 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 0 # Necessario per MinVer: deve percorrere tutta la storia Git per trovare i tag
- name: Calcola versione e genera version.json
run: |
git fetch --tags --force
$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 su questo remote. Uso fallback."
$VERSION = "2.3.2"
} else {
$VERSION = $LATEST_TAG -replace '^v', ''
}
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")
# Genera version.json
$versionJson = @{
version = $VERSION
commitSha = $SHORT_SHA
branch = $BRANCH
buildDate = $BUILD_DATE
buildEnvironment = "GitHub Actions"
} | ConvertTo-Json
$versionJson | Out-File -FilePath "Data_Coupler\wwwroot\version.json" -Encoding UTF8
Write-Host "Generated version.json:"
Get-Content "Data_Coupler\wwwroot\version.json"
"APP_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
shell: pwsh
- name: Log in to GitHub Container Registry - name: Log in to GitHub Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v3
@@ -128,7 +202,7 @@ jobs:
$imageName = "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}".ToLower() $imageName = "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}".ToLower()
# Build with temporary tag # 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 # Parse and push all tags
$tags = "${{ steps.meta.outputs.tags }}" -split "`n" $tags = "${{ steps.meta.outputs.tags }}" -split "`n"
+7 -2
View File
@@ -3,6 +3,8 @@
# Stage 1: Build # Stage 1: Build
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
# Versione calcolata da MinVer sul runner CI/CD e passata come build-arg
ARG APP_VERSION=0.0.0-alpha.0
WORKDIR /src WORKDIR /src
# Copia i file di progetto e ripristina le dipendenze # Copia i file di progetto e ripristina le dipendenze
@@ -20,15 +22,18 @@ COPY . .
# Build del progetto principale # Build del progetto principale
WORKDIR "/src/Data_Coupler" WORKDIR "/src/Data_Coupler"
RUN dotnet build "Data_Coupler.csproj" -c Release -o /app/build /p:ContinuousIntegrationBuild=true RUN dotnet build "Data_Coupler.csproj" -c Release -o /app/build /p:ContinuousIntegrationBuild=true /p:MinVerVersionOverride=${APP_VERSION}
# Stage 2: Publish # Stage 2: Publish
FROM build AS publish FROM build AS publish
# Necessario ridichiarare ARG dopo FROM in multi-stage build
ARG APP_VERSION=0.0.0-alpha.0
RUN dotnet publish "Data_Coupler.csproj" -c Release -o /app/publish \ RUN dotnet publish "Data_Coupler.csproj" -c Release -o /app/publish \
/p:SelfContained=false \ /p:SelfContained=false \
/p:PublishTrimmed=false \ /p:PublishTrimmed=false \
/p:PublishSingleFile=false \ /p:PublishSingleFile=false \
/p:ContinuousIntegrationBuild=true /p:ContinuousIntegrationBuild=true \
/p:MinVerVersionOverride=${APP_VERSION}
# Stage 3: Runtime # Stage 3: Runtime
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
+6 -2
View File
@@ -3,6 +3,8 @@
# Stage 1: Build # Stage 1: Build
FROM mcr.microsoft.com/dotnet/sdk:9.0-nanoserver-ltsc2022 AS build FROM mcr.microsoft.com/dotnet/sdk:9.0-nanoserver-ltsc2022 AS build
# Versione calcolata da MinVer sul runner CI/CD e passata come build-arg
ARG APP_VERSION=0.0.0-alpha.0
WORKDIR /s WORKDIR /s
# Copia i file di progetto e ripristina le dipendenze con nomi originali # Copia i file di progetto e ripristina le dipendenze con nomi originali
@@ -23,11 +25,13 @@ COPY ["Components/", "Components/"]
# Build del progetto principale con output path corto # Build del progetto principale con output path corto
WORKDIR "/s/Data_Coupler" WORKDIR "/s/Data_Coupler"
RUN dotnet build "Data_Coupler.csproj" -c Release -o /o --no-restore RUN dotnet build "Data_Coupler.csproj" -c Release -o /o --no-restore /p:ContinuousIntegrationBuild=true /p:MinVerVersionOverride=%APP_VERSION%
# Stage 2: Publish # Stage 2: Publish
FROM build AS publish FROM build AS publish
RUN dotnet publish "Data_Coupler.csproj" -c Release -o /p --no-restore -r win-x64 --self-contained false # Necessario ridichiarare ARG dopo FROM in multi-stage build
ARG APP_VERSION=0.0.0-alpha.0
RUN dotnet publish "Data_Coupler.csproj" -c Release -o /p --no-restore -r win-x64 --self-contained false /p:ContinuousIntegrationBuild=true /p:MinVerVersionOverride=%APP_VERSION%
# Stage 3: Runtime # Stage 3: Runtime
FROM mcr.microsoft.com/dotnet/aspnet:9.0-nanoserver-ltsc2022 AS final FROM mcr.microsoft.com/dotnet/aspnet:9.0-nanoserver-ltsc2022 AS final