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 restore
& $dotnetExe build "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -v minimal & $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 { try {
$outRoot = Join-Path -Path "imagecatalog\bin\$env:BUILD_CONFIG" -ChildPath '*' & $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
# 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.'
}
} catch { } catch {
Write-Host "Failed to write minversion: $_" Write-Host "dotnet publish failed: $_"
throw
} }
} }
artifacts: artifacts:
paths: paths:
- "imagecatalog/bin/$BUILD_CONFIG/net10.0-windows/**" - "imagecatalog/bin/$BUILD_CONFIG/net10.0-windows/publish/**"
expire_in: 1 hour expire_in: 1 hour
# Publish and create GitLab Release when building a tag. # Publish and create GitLab Release when building a tag.
publish_release: publish_release:
stage: publish stage: publish
image: mcr.microsoft.com/dotnet/sdk:10.0 image: mcr.microsoft.com/dotnet/sdk:10.0
variables:
GIT_DEPTH: 0
needs: needs:
- job: build_windows - job: build_windows
artifacts: true artifacts: true
script: | script: |
set -euo pipefail set -euo pipefail
dotnet --info dotnet --info
echo "Reading MinVer version from build artifacts" export PATH="$PATH:$HOME/.dotnet/tools"
# locate a minversion file produced by the build artifacts echo "Installing minver-cli"
minfile=$(find imagecatalog -type f -iname 'minversion' -print | head -n1 || true) dotnet tool install --global minver-cli --version 7.0.0
if [ -z "$minfile" ]; then minfile=$(find . -type f -iname 'minversion' -print | head -n1 || true); fi # Ensure we have full git history and tags for MinVer to compute an accurate version
if [ -z "$minfile" ]; then echo "No minversion file found in artifacts"; exit 1; fi git fetch --prune --unshallow || true
echo "Found minversion file: $minfile" git fetch --tags || true
version=$(cat "$minfile" | tr -d '\r\n') echo "Computing version with minver-cli"
if [ -z "$version" ]; then echo "minversion was empty"; exit 1; fi 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" echo "Using version: $version"
# find the primary artifact to upload (prefer the executable or first file under the build output) # find the single-file exe from the publish output
file=$(find imagecatalog/bin -type f \! -iname 'minversion' -print | head -n1 || true) file=$(find imagecatalog/bin -type f -iname '*.exe' -print | head -n1 || true)
if [ -z "$file" ]; then file=$(find . -type f -name 'ImageCatalog.*' -print | head -n1 || true); fi if [ -z "$file" ]; then file=$(find imagecatalog -type f -iname '*.exe' -print | head -n1 || true); fi
if [ -z "$file" ]; then echo "No artifact file found to attach"; exit 1; fi if [ -z "$file" ]; then echo "No artifact EXE found to attach"; exit 1; fi
echo "Uploading artifact: $file" 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") 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') assetPath=$(echo "$uploadResp" | sed -n 's/.*"url":"\([^\"]*\)".*/\1/p')
@ -138,7 +131,6 @@ publish_release:
assetUrl="$CI_SERVER_URL$assetPath" assetUrl="$CI_SERVER_URL$assetPath"
echo "Uploaded asset url: $assetUrl" echo "Uploaded asset url: $assetUrl"
basename=$(basename "$file") basename=$(basename "$file")
# create release JSON using the exact minversion value as tag_name
cat > release.json <<EOF 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"}]}} {"name":"$version","tag_name":"$version","ref":"$CI_COMMIT_SHA","description":"Automated release from CI (version $version)","assets":{"links":[{"name":"$basename","url":"$assetUrl"}]}}
EOF EOF