From 3a964bbbcf09cf6902dc2f3e242bcf88a3a9ceaf Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 22 Feb 2026 11:38:15 +0100 Subject: [PATCH] Refactor CI pipeline: replace minversion file generation with single-file publish for downstream jobs --- .gitlab-ci.yml | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f13eb57..f257f27 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 <