Refactor CI pipeline: replace minversion file generation with single-file publish for downstream jobs

This commit is contained in:
MaddoScientisto 2026-02-22 11:38:15 +01:00
commit 3a964bbbcf

View file

@ -85,52 +85,45 @@ build_windows:
}
& $dotnetExe restore
& $dotnetExe build "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -v minimal
# Write a minversion file into the build output so downstream jobs can read the computed version.
# Produce a single-file, ready-to-run publish so downstream jobs only need the EXE.
try {
$outRoot = Join-Path -Path "imagecatalog\bin\$env:BUILD_CONFIG" -ChildPath '*'
# search under the build output for a file starting with ImageCatalog.
$built = Get-ChildItem -Path (Join-Path "imagecatalog\bin\$env:BUILD_CONFIG" '.') -Recurse -File -ErrorAction SilentlyContinue | Where-Object { $_.Name -like 'ImageCatalog.*' } | Select-Object -First 1
if ($built) {
$base = [System.IO.Path]::GetFileNameWithoutExtension($built.Name)
$version = $base -replace '^ImageCatalog\.', ''
$minPath = Join-Path $built.DirectoryName 'minversion'
Write-Host "Writing minversion '$version' to $minPath"
Set-Content -Path $minPath -Value $version -Encoding UTF8
} else {
Write-Host 'No ImageCatalog build artifact found to derive minversion from.'
}
& $dotnetExe publish "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -r win-x64 --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=true -p:PublishReadyToRun=true -o "imagecatalog\bin\$env:BUILD_CONFIG\net10.0-windows\publish" -v minimal
} catch {
Write-Host "Failed to write minversion: $_"
Write-Host "dotnet publish failed: $_"
throw
}
}
artifacts:
paths:
- "imagecatalog/bin/$BUILD_CONFIG/net10.0-windows/**"
- "imagecatalog/bin/$BUILD_CONFIG/net10.0-windows/publish/**"
expire_in: 1 hour
# Publish and create GitLab Release when building a tag.
publish_release:
stage: publish
image: mcr.microsoft.com/dotnet/sdk:10.0
variables:
GIT_DEPTH: 0
needs:
- job: build_windows
artifacts: true
script: |
set -euo pipefail
dotnet --info
echo "Reading MinVer version from build artifacts"
# locate a minversion file produced by the build artifacts
minfile=$(find imagecatalog -type f -iname 'minversion' -print | head -n1 || true)
if [ -z "$minfile" ]; then minfile=$(find . -type f -iname 'minversion' -print | head -n1 || true); fi
if [ -z "$minfile" ]; then echo "No minversion file found in artifacts"; exit 1; fi
echo "Found minversion file: $minfile"
version=$(cat "$minfile" | tr -d '\r\n')
if [ -z "$version" ]; then echo "minversion was empty"; exit 1; fi
export PATH="$PATH:$HOME/.dotnet/tools"
echo "Installing minver-cli"
dotnet tool install --global minver-cli --version 7.0.0
# Ensure we have full git history and tags for MinVer to compute an accurate version
git fetch --prune --unshallow || true
git fetch --tags || true
echo "Computing version with minver-cli"
version=$(minver 2>/dev/null | tail -n1 || true)
if [ -z "$version" ]; then echo "minver failed to produce a version"; exit 1; fi
echo "Using version: $version"
# find the primary artifact to upload (prefer the executable or first file under the build output)
file=$(find imagecatalog/bin -type f \! -iname 'minversion' -print | head -n1 || true)
if [ -z "$file" ]; then file=$(find . -type f -name 'ImageCatalog.*' -print | head -n1 || true); fi
if [ -z "$file" ]; then echo "No artifact file found to attach"; exit 1; fi
# find the single-file exe from the publish output
file=$(find imagecatalog/bin -type f -iname '*.exe' -print | head -n1 || true)
if [ -z "$file" ]; then file=$(find imagecatalog -type f -iname '*.exe' -print | head -n1 || true); fi
if [ -z "$file" ]; then echo "No artifact EXE found to attach"; exit 1; fi
echo "Uploading artifact: $file"
uploadResp=$(curl --silent --show-error --header "JOB-TOKEN:$CI_JOB_TOKEN" --form "file=@$file" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/uploads")
assetPath=$(echo "$uploadResp" | sed -n 's/.*"url":"\([^\"]*\)".*/\1/p')
@ -138,7 +131,6 @@ publish_release:
assetUrl="$CI_SERVER_URL$assetPath"
echo "Uploaded asset url: $assetUrl"
basename=$(basename "$file")
# create release JSON using the exact minversion value as tag_name
cat > release.json <<EOF
{"name":"$version","tag_name":"$version","ref":"$CI_COMMIT_SHA","description":"Automated release from CI (version $version)","assets":{"links":[{"name":"$basename","url":"$assetUrl"}]}}
EOF