145 lines
6.3 KiB
YAML
145 lines
6.3 KiB
YAML
stages:
|
|
- determine
|
|
- build
|
|
|
|
variables:
|
|
SOLUTION_FILE: "Pulsar.sln"
|
|
BUILD_CONFIGURATION: "Release"
|
|
SERVER_TARGET_FRAMEWORK: "net9.0-windows"
|
|
SERVER_RUNTIME: "win-x64"
|
|
CLIENT_TARGET_FRAMEWORK: "net472"
|
|
|
|
# Only run on main branch when C# files or project files change
|
|
workflow:
|
|
rules:
|
|
- if: $CI_COMMIT_BRANCH == "main"
|
|
changes:
|
|
- "**/*.cs"
|
|
- "**/*.csproj"
|
|
- "**/*.sln"
|
|
- ".gitlab-ci.yml"
|
|
|
|
determine-version:
|
|
stage: determine
|
|
image: ubuntu:22.04
|
|
tags:
|
|
- docker
|
|
before_script:
|
|
- apt-get update -qq && apt-get install -y -qq git grep
|
|
script:
|
|
- |
|
|
if [ -f "Pulsar.Server/Properties/AssemblyInfo.cs" ]; then
|
|
VERSION=$(grep -oP '\[assembly: AssemblyVersion\("\K[0-9]+\.[0-9]+\.[0-9]+' Pulsar.Server/Properties/AssemblyInfo.cs || echo "unknown")
|
|
echo "Found version: $VERSION"
|
|
echo "VERSION=$VERSION" >> variables.env
|
|
else
|
|
echo "AssemblyInfo.cs not found"
|
|
echo "VERSION=unknown" >> variables.env
|
|
fi
|
|
- |
|
|
if echo "$CI_COMMIT_MESSAGE" | grep -q "^STABLE"; then
|
|
echo "Stable release detected"
|
|
echo "IS_STABLE=true" >> variables.env
|
|
echo "RELEASE_TYPE=stable" >> variables.env
|
|
else
|
|
echo "Development build"
|
|
echo "IS_STABLE=false" >> variables.env
|
|
echo "RELEASE_TYPE=dev" >> variables.env
|
|
fi
|
|
- echo "Commit short SHA:" $CI_COMMIT_SHORT_SHA
|
|
- echo "Ref name:" $CI_COMMIT_REF_NAME
|
|
- echo "COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA" >> variables.env
|
|
- |
|
|
# Clean commit message for dotenv (remove problematic characters)
|
|
CLEAN_MESSAGE=$(echo "$CI_COMMIT_MESSAGE" | tr -d '\n\r' | sed 's/"/\\"/g' | sed "s/'/\\'/g")
|
|
echo "COMMIT_MESSAGE=$CLEAN_MESSAGE" >> variables.env
|
|
|
|
build:
|
|
stage: build
|
|
needs: ["determine-version"]
|
|
image: debian:12
|
|
tags:
|
|
- docker
|
|
before_script:
|
|
# Install Microsoft packages repository and .NET SDK 9.0
|
|
- apt-get update -qq
|
|
- apt-get install -y -qq wget ca-certificates apt-transport-https
|
|
- wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
|
|
- dpkg -i packages-microsoft-prod.deb
|
|
- rm packages-microsoft-prod.deb
|
|
- apt-get update -qq
|
|
- apt-get install -y -qq dotnet-sdk-9.0 zip
|
|
script:
|
|
- set -e # Exit on any error
|
|
- echo "Building Pulsar version:" $VERSION
|
|
- echo "Release type:" $RELEASE_TYPE
|
|
- echo "Commit:" $COMMIT_SHORT_SHA
|
|
- echo "Commit message:" $COMMIT_MESSAGE
|
|
- echo "Restoring dependencies..."
|
|
- dotnet restore $SOLUTION_FILE --runtime $SERVER_RUNTIME
|
|
- echo "Build completed. Checking if restore was successful..."
|
|
- echo "Building client..."
|
|
- dotnet build Pulsar.Client/Pulsar.Client.csproj --configuration $BUILD_CONFIGURATION --no-restore --framework $CLIENT_TARGET_FRAMEWORK
|
|
- echo "Client build completed. Checking build output..."
|
|
- ls -la Pulsar.Client/bin/Release/ 2>/dev/null || echo "Client bin directory not found"
|
|
- echo "Publishing server..."
|
|
- dotnet publish Pulsar.Server/Pulsar.Server.csproj --configuration $BUILD_CONFIGURATION --output "$CI_PROJECT_DIR/publish/server" --no-restore --framework $SERVER_TARGET_FRAMEWORK --runtime $SERVER_RUNTIME --self-contained false
|
|
- echo "Server publish completed. Checking publish output..."
|
|
- ls -la publish/server/ 2>/dev/null || echo "Server publish directory not found"
|
|
- echo "Preparing build output..."
|
|
- mkdir -p build_output
|
|
# Copy all published server code to build_output
|
|
- cp -r publish/server/* build_output/
|
|
# Find and copy client.bin - check multiple possible locations
|
|
- |
|
|
CLIENT_FOUND=false
|
|
# Check location 1: Pulsar.Client/bin/Release/net472/Pulsar.Client.exe
|
|
if [ -f "Pulsar.Client/bin/Release/$CLIENT_TARGET_FRAMEWORK/Pulsar.Client.exe" ]; then
|
|
cp "Pulsar.Client/bin/Release/$CLIENT_TARGET_FRAMEWORK/Pulsar.Client.exe" build_output/client.bin
|
|
echo "✓ Copied Pulsar.Client.exe as client.bin from Pulsar.Client/bin"
|
|
CLIENT_FOUND=true
|
|
# Check location 2: bin/Release/net472/Client.exe (like GitHub Actions)
|
|
elif [ -f "bin/Release/$CLIENT_TARGET_FRAMEWORK/Client.exe" ]; then
|
|
cp "bin/Release/$CLIENT_TARGET_FRAMEWORK/Client.exe" build_output/client.bin
|
|
echo "✓ Copied Client.exe from bin directory as client.bin"
|
|
CLIENT_FOUND=true
|
|
# Check location 3: bin/Release/net472/Pulsar.Client.exe
|
|
elif [ -f "bin/Release/$CLIENT_TARGET_FRAMEWORK/Pulsar.Client.exe" ]; then
|
|
cp "bin/Release/$CLIENT_TARGET_FRAMEWORK/Pulsar.Client.exe" build_output/client.bin
|
|
echo "✓ Copied Pulsar.Client.exe from bin directory as client.bin"
|
|
CLIENT_FOUND=true
|
|
# Check location 4: Pulsar.Client/bin/Release/net472/Client.exe
|
|
elif [ -f "Pulsar.Client/bin/Release/$CLIENT_TARGET_FRAMEWORK/Client.exe" ]; then
|
|
cp "Pulsar.Client/bin/Release/$CLIENT_TARGET_FRAMEWORK/Client.exe" build_output/client.bin
|
|
echo "✓ Copied Client.exe as client.bin from Pulsar.Client/bin"
|
|
CLIENT_FOUND=true
|
|
fi
|
|
|
|
if [ "$CLIENT_FOUND" = false ]; then
|
|
echo "❌ ERROR: Client executable not found!"
|
|
echo "Searched locations:"
|
|
echo " - Pulsar.Client/bin/Release/$CLIENT_TARGET_FRAMEWORK/Pulsar.Client.exe"
|
|
echo " - bin/Release/$CLIENT_TARGET_FRAMEWORK/Client.exe"
|
|
echo " - bin/Release/$CLIENT_TARGET_FRAMEWORK/Pulsar.Client.exe"
|
|
echo " - Pulsar.Client/bin/Release/$CLIENT_TARGET_FRAMEWORK/Client.exe"
|
|
echo ""
|
|
echo "Available files in project directories:"
|
|
echo "Pulsar.Client/bin contents:"
|
|
find Pulsar.Client/bin -name "*.exe" 2>/dev/null || echo "No exe files found in Pulsar.Client/bin"
|
|
echo "bin contents:"
|
|
find bin -name "*.exe" 2>/dev/null || echo "No exe files found in bin"
|
|
echo ""
|
|
echo "All bin directories structure:"
|
|
find . -type d -name "bin" -exec echo "Directory: {}" \; -exec find {} -name "*.exe" \; 2>/dev/null || echo "No bin directories found"
|
|
exit 1
|
|
fi
|
|
# Create the final zip with just the essentials
|
|
- cd build_output && zip -r ../build_output.zip . && cd ..
|
|
- echo "✓ Build package created successfully"
|
|
- echo "Package contents:"
|
|
- unzip -l build_output.zip | head -20 || true
|
|
artifacts:
|
|
paths:
|
|
- build_output.zip
|
|
expire_in: 30 days
|
|
when: on_success |