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