Update gitea workflow

This commit is contained in:
2025-12-12 16:18:31 +09:00
parent fb31fd8ca8
commit c4ca3e1bc9

View File

@@ -22,11 +22,7 @@ jobs:
- name: Restore dependencies
run: dotnet restore
# Note: We skipped the global "Build all projects" step.
# dotnet pack will build automatically, and we only want to build/pack
# the specific projects that strictly need updates.
- name: Check and Pack Projects
- name: Check, Build, and Pack Projects
env:
NUGET_API_KEY: ${{ secrets.NUGET_TOKEN }}
SOURCE_URL: "https://git.personalnas.com/api/packages/Misaki/nuget"
@@ -34,28 +30,24 @@ jobs:
mkdir -p ./artifacts
for projfile in $(find . -name "*.csproj"); do
# 1. Check if the project is configured to generate a package
# 1. Check if the project generates a package
GENERATE_PKG=$(dotnet build "$projfile" --getProperty:GeneratePackageOnBuild)
if [[ "$GENERATE_PKG" != "true" && "$GENERATE_PKG" != "True" ]]; then
continue
fi
# 2. Extract Package ID and Version efficiently
# 2. Get Package ID and Version
PACKAGE_ID=$(dotnet build "$projfile" --getProperty:PackageId)
VERSION=$(dotnet build "$projfile" --getProperty:Version)
# Fallback: If PackageId is not explicitly set in csproj, use the filename
if [ -z "$PACKAGE_ID" ]; then
PACKAGE_ID=$(basename "$projfile" .csproj)
fi
echo "Checking $PACKAGE_ID version $VERSION..."
# 3. Check if version exists in Gitea Registry
# Convert ID to lowercase for URL consistency (NuGet V3 standard)
# 3. Check Gitea Registry
LOWER_ID=$(echo "$PACKAGE_ID" | tr '[:upper:]' '[:lower:]')
# Gitea supports the NuGet V3 Registration endpoint
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: token $NUGET_API_KEY" \
"${SOURCE_URL}/registration/${LOWER_ID}/${VERSION}.json")
@@ -63,10 +55,19 @@ jobs:
if [ "$HTTP_CODE" -eq 200 ]; then
echo "✅ Version $VERSION of $PACKAGE_ID already exists. Skipping..."
else
echo "🆕 Version $VERSION of $PACKAGE_ID is new. Building and Packing..."
echo "🆕 Version $VERSION of $PACKAGE_ID is new."
# Build and Pack only this project
if ! dotnet pack "$projfile" -c Release -o ./artifacts; then
# 4. EXPLICIT BUILD (Creates the DLLs)
echo "Building $projfile..."
if ! dotnet build "$projfile" -c Release; then
echo "❌ Failed to build $projfile"
exit 1
fi
# 5. PACK (Packages the DLLs created above)
echo "Packing $projfile..."
# We use --no-build because we just built it in step 4
if ! dotnet pack "$projfile" -c Release -o ./artifacts --no-build; then
echo "❌ Failed to pack $projfile"
exit 1
fi
@@ -77,14 +78,12 @@ jobs:
env:
NUGET_API_KEY: ${{ secrets.NUGET_TOKEN }}
run: |
# If no packages were created (all skipped), exit gracefully
if [ ! -d "./artifacts" ] || [ -z "$(ls -A ./artifacts/*.nupkg 2>/dev/null)" ]; then
echo "No new packages to publish."
exit 0
fi
for pkg in ./artifacts/*.nupkg; do
# Skip symbol packages
if [[ "$pkg" == *".symbols.nupkg" ]]; then
continue
fi