Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 80 additions & 13 deletions .github/scripts/build-and-pack-nuget.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
set -e

# Script to build and pack NuGet packages in dependency order
# Usage: ./build-and-pack-nuget.sh
# Usage: ./build-and-pack-nuget.sh [--skip-version-check]

SKIP_VERSION_CHECK=false
[[ "$1" == "--skip-version-check" ]] && SKIP_VERSION_CHECK=true

# Create artifacts directory for local NuGet feed
mkdir -p ./artifacts

# Get all packable projects from the solution filter
# Extract project paths from the solution filter and convert Windows paths to Unix paths
Expand Down Expand Up @@ -87,17 +93,61 @@ while [ -n "$REMAINING_PROJECTS" ] && [ $ITERATION -lt $MAX_ITERATIONS ]; do
while IFS= read -r project; do
if [ -z "$project" ]; then continue; fi
PROJECT_NAME=$(basename $(dirname "$project"))
echo "Building $PROJECT_NAME..."

# Restore with local feed for dependencies from previous iterations
dotnet restore "$project" -p:Configuration=Release --verbosity minimal --force --no-cache

# Build the project
dotnet build "$project" --configuration Release --no-restore --verbosity minimal

# Pack directly to artifacts with project name folder structure for proper NuGet feed
dotnet pack "$project" --configuration Release --no-build --output "./artifacts/${PROJECT_NAME}" -p:PACK=true --verbosity minimal


# Check if we should skip version checking (for PR validation)
if [ "$SKIP_VERSION_CHECK" = true ]; then
echo "Building $PROJECT_NAME (version check skipped)..."
SHOULD_BUILD=true
else
# Get the version and PackageId from the project file by evaluating MSBuild properties
VERSION=$(dotnet msbuild "$project" -getProperty:Version -p:Configuration=Release 2>/dev/null | tail -1)
PACKAGE_ID=$(dotnet msbuild "$project" -getProperty:PackageId -p:Configuration=Release 2>/dev/null | tail -1)

# If PackageId is not set, fall back to project name
if [ -z "$PACKAGE_ID" ]; then
PACKAGE_ID="$PROJECT_NAME"
fi

if [ -z "$VERSION" ]; then
echo "❌ ERROR: Could not extract version from $PROJECT_NAME, skipping"
echo " Make sure the project has a <Version> property defined"
SHOULD_BUILD=false
else
echo "Checking if $PACKAGE_ID $VERSION exists on NuGet.org..."

# Query NuGet API to check if this version exists
API_URL="https://api.nuget.org/v3/registration5-semver1/${PACKAGE_ID,,}/index.json"

if response=$(curl -s -f "$API_URL" 2>/dev/null); then
# Check if the specific version exists in the response
if echo "$response" | grep -q "\"$VERSION\""; then
echo " ⚪ Already exists on NuGet.org, skipping build"
SHOULD_BUILD=false
else
echo " 🟢 New version, will build"
SHOULD_BUILD=true
fi
else
# Package ID doesn't exist at all, so this version is definitely new
echo " 🟢 New package, will build"
SHOULD_BUILD=true
fi
fi
fi

if [ "$SHOULD_BUILD" = true ]; then
echo "Building $PROJECT_NAME..."

# Restore with local feed for dependencies from previous iterations
dotnet restore "$project" -p:Configuration=Release --verbosity minimal --force --no-cache

# Build the project
dotnet build "$project" --configuration Release --no-restore --verbosity minimal

# Pack directly to artifacts with project name folder structure for proper NuGet feed
dotnet pack "$project" --configuration Release --no-build --output "./artifacts/${PROJECT_NAME}" -p:PACK=true --verbosity minimal
fi

BUILT_PROJECTS="${BUILT_PROJECTS}${PROJECT_NAME};"
done < <(echo "$PROJECTS_TO_BUILD" | tr ';' '\n')

Expand All @@ -112,5 +162,22 @@ if [ $ITERATION -eq $MAX_ITERATIONS ]; then
exit 1
fi

PACKAGE_COUNT=$(ls ./artifacts/*/*.nupkg 2>/dev/null | wc -l)

echo ""
echo "Successfully created $(ls ./artifacts/*/*.nupkg 2>/dev/null | wc -l) packages"
echo "=== Build Summary ==="
echo "Successfully created $PACKAGE_COUNT package(s)"

# Only create zip and check for updates when NOT skipping version check
if [ "$SKIP_VERSION_CHECK" = false ]; then
if [ $PACKAGE_COUNT -eq 0 ]; then
echo ""
echo "No new packages to release (all packages are up-to-date)"
exit 1
fi

echo ""
echo "Creating release archive with new packages..."
find ./artifacts -name "*.nupkg" | zip -j "artifacts/Packages.zip" -@
echo "Created: artifacts/Packages.zip"
fi
44 changes: 26 additions & 18 deletions .github/scripts/push-nuget-packages.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

# Script to push NuGet packages and create a .zip file with all uploaded packages
# Script to push NuGet packages to NuGet.org
# Usage: ./push-nuget-packages.sh [--mock]

MOCK_MODE=false
Expand All @@ -19,30 +19,25 @@ done
echo "=================================="

UPLOADED_COUNT=0
SKIPPED_COUNT=0
CONFLICT_COUNT=0
FAILED_COUNT=0
UPLOADED_PACKAGES=""

for package in ./artifacts/*/*.nupkg; do
PACKAGE_NAME=$(basename "$package")
echo "Attempting to push: $PACKAGE_NAME"

if [[ "$MOCK_MODE" == "true" ]]; then
UPLOADED_PACKAGES="$UPLOADED_PACKAGES$package
"
echo "🟢 Successfully uploaded (mocked): $PACKAGE_NAME"
UPLOADED_COUNT=$((UPLOADED_COUNT + 1))
elif output=$(dotnet nuget push "$package" \
--api-key "$NUGET_API_KEY" \
--source "https://api.nuget.org/v3/index.json" 2>&1); then
UPLOADED_PACKAGES="$UPLOADED_PACKAGES$package
"
echo "🟢 Successfully uploaded: $PACKAGE_NAME"
UPLOADED_COUNT=$((UPLOADED_COUNT + 1))
else
if echo "$output" | grep -q "409 (Conflict"; then
echo "⚪ Already exists: $PACKAGE_NAME"
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
echo "🟡 Conflict (already exists): $PACKAGE_NAME"
CONFLICT_COUNT=$((CONFLICT_COUNT + 1))
else
echo "🔴 Failed to upload: $PACKAGE_NAME"
echo " Error: $output"
Expand All @@ -54,16 +49,29 @@ done
echo ""
echo "=== Upload Summary ==="
echo "Successfully uploaded: $UPLOADED_COUNT packages"
echo "Already existed: $SKIPPED_COUNT packages"
echo "Conflicts (409): $CONFLICT_COUNT packages"
echo "Failed uploads: $FAILED_COUNT packages"

if [ $UPLOADED_COUNT -gt 0 ]; then
# Fail if any errors were encountered
TOTAL_FAILED=$((FAILED_COUNT + CONFLICT_COUNT))

if [ $TOTAL_FAILED -gt 0 ]; then
echo ""
if [ $CONFLICT_COUNT -gt 0 ]; then
echo "❌ ERROR: $TOTAL_FAILED package(s) failed to upload (of which $CONFLICT_COUNT were conflicts)"
echo "Note: Conflicts should not happen as build-and-pack-nuget.sh filters existing packages."
else
echo "❌ ERROR: $FAILED_COUNT package(s) failed to upload"
fi
exit 1
fi

if [ $UPLOADED_COUNT -eq 0 ]; then
echo ""
echo "Creating release archive..."
echo "$UPLOADED_PACKAGES" | zip -j "artifacts/Packages.zip" -@
echo "Created: artifacts/Packages.zip"
exit 0
else
echo "No packages were successfully uploaded"
echo "❌ ERROR: No packages were successfully uploaded"
exit 1
fi
fi

echo ""
echo "✅ Successfully pushed $UPLOADED_COUNT package(s) to NuGet.org"
exit 0
2 changes: 1 addition & 1 deletion .github/workflows/pack-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
- name: Build and pack in dependency order
run: |
chmod +x .github/scripts/build-and-pack-nuget.sh
.github/scripts/build-and-pack-nuget.sh
.github/scripts/build-and-pack-nuget.sh --skip-version-check
32 changes: 17 additions & 15 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ env:
DOTNET_CLI_TELEMETRY_OPTOUT: true

permissions:
contents: write
id-token: write

jobs:
build-and-publish:
runs-on: ubuntu-latest

permissions:
contents: write
id-token: write

steps:
Expand All @@ -36,6 +38,20 @@ jobs:
chmod +x .github/scripts/build-and-pack-nuget.sh
.github/scripts/build-and-pack-nuget.sh

- name: Set release date
run: |
echo "RELEASE_DATE=$(date +%Y-%m-%d)" >> $GITHUB_ENV
echo "RELEASE_TAG=v$(date +%Y.%-m.%-d)" >> $GITHUB_ENV

- name: Create GitHub Release
uses: softprops/action-gh-release@v2.3.2
with:
name: War3Net Release ${{ env.RELEASE_DATE }}
tag_name: ${{ env.RELEASE_TAG }}
files: |
./artifacts/Packages.zip
draft: ${{ github.ref_name != 'master' }}

- name: NuGet login
uses: NuGet/login@v1
id: login
Expand All @@ -51,18 +67,4 @@ jobs:
.github/scripts/push-nuget-packages.sh
fi
env:
NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }}

- name: Set release date
run: |
echo "RELEASE_DATE=$(date +%Y-%m-%d)" >> $GITHUB_ENV
echo "RELEASE_TAG=v$(date +%Y.%-m.%-d)" >> $GITHUB_ENV

- name: Create GitHub Release
uses: softprops/action-gh-release@v2.3.2
with:
name: War3Net Release ${{ env.RELEASE_DATE }}
tag_name: ${{ env.RELEASE_TAG }}
files: |
./artifacts/Packages.zip
draft: ${{ github.ref_name != 'master' }}
NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }}
1 change: 1 addition & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<package pattern="Microsoft.*" />
<package pattern="NuGet.*" />
<package pattern="System.*" />
<package pattern="War3Net.*" />
</packageSource>
</packageSourceMapping>
</configuration>
Loading