@@ -173,20 +173,95 @@ jobs:
173173 echo "Package count:"
174174 find Cyaim.WebSocketServer/artifacts -name "*.nupkg" -type f | wc -l
175175
176+ - name : Verify NuGet API Key
177+ if : steps.check_commit.outputs.trigger_release == 'true'
178+ run : |
179+ if [ -z "$NUGET_APIKEY" ]; then
180+ echo "❌ Error: NUGET_APIKEY secret is not set!"
181+ echo "Please set the NUGET_APIKEY secret in GitHub repository settings."
182+ echo "Go to: Settings → Secrets and variables → Actions → New repository secret"
183+ exit 1
184+ else
185+ echo "✅ NUGET_APIKEY secret is set (length: ${#NUGET_APIKEY} characters)"
186+ fi
187+ env :
188+ NUGET_APIKEY : ${{ secrets.NUGET_APIKEY }}
189+
190+ - name : Configure NuGet source
191+ if : steps.check_commit.outputs.trigger_release == 'true'
192+ run : |
193+ echo "Configuring NuGet source..."
194+ # 移除可能存在的默认源
195+ dotnet nuget remove source "nuget.org" 2>/dev/null || true
196+ # 添加正确的 NuGet 源
197+ dotnet nuget add source "https://api.nuget.org/v3/index.json" \
198+ --name "nuget.org" \
199+ --username "GitHubActions" \
200+ --password "$NUGET_APIKEY" \
201+ --store-password-in-clear-text || true
202+ echo "✅ NuGet source configured"
203+ env :
204+ NUGET_APIKEY : ${{ secrets.NUGET_APIKEY }}
205+
176206 - name : Push to NuGet
177207 if : steps.check_commit.outputs.trigger_release == 'true'
178208 working-directory : Cyaim.WebSocketServer/artifacts
209+ env :
210+ NUGET_APIKEY : ${{ secrets.NUGET_APIKEY }}
179211 run : |
180212 # 推送所有包到 NuGet
213+ PUSH_COUNT=0
214+ SUCCESS_COUNT=0
215+ FAIL_COUNT=0
216+
217+ # 确保只推送可发布的包(排除 Sample 和 Tests)
181218 for package in *.nupkg; do
182219 if [ -f "$package" ]; then
183- echo "Pushing $package to NuGet..."
184- dotnet nuget push "$package" \
220+ # 排除示例和测试包
221+ if [[ "$package" == *"Sample"* ]] || [[ "$package" == *"Tests"* ]] || [[ "$package" == *"Example"* ]]; then
222+ echo "⊘ Skipping (Sample/Tests): $package"
223+ continue
224+ fi
225+
226+ PUSH_COUNT=$((PUSH_COUNT + 1))
227+ echo ""
228+ echo "[$PUSH_COUNT] Pushing $package to NuGet..."
229+ echo " Source: https://api.nuget.org/v3/index.json"
230+
231+ # 使用环境变量中的 API Key 和明确的源
232+ if dotnet nuget push "$package" \
185233 --source "https://api.nuget.org/v3/index.json" \
186- --api-key "${{ secrets.NUGET_APIKEY }}" \
187- --skip-duplicate || echo "⚠️ Failed to push $package (may already exist)"
234+ --api-key "$NUGET_APIKEY" \
235+ --skip-duplicate \
236+ --no-symbols; then
237+ echo " ✅ Successfully pushed: $package"
238+ SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
239+ else
240+ EXIT_CODE=$?
241+ if [ $EXIT_CODE -eq 0 ]; then
242+ echo " ⊘ Skipped (already exists): $package"
243+ else
244+ echo " ❌ Failed to push: $package (exit code: $EXIT_CODE)"
245+ FAIL_COUNT=$((FAIL_COUNT + 1))
246+ fi
247+ fi
188248 fi
189249 done
250+
251+ echo ""
252+ echo "=== Push Summary ==="
253+ echo "Total packages: $PUSH_COUNT"
254+ echo "Success: $SUCCESS_COUNT"
255+ echo "Failed: $FAIL_COUNT"
256+
257+ if [ $FAIL_COUNT -gt 0 ]; then
258+ echo "⚠️ Some packages failed to push. Check the errors above."
259+ echo "Common issues:"
260+ echo " 1. NUGET_APIKEY secret not set or incorrect"
261+ echo " 2. API Key expired or invalid"
262+ echo " 3. Package already exists (if not using --skip-duplicate)"
263+ exit 1
264+ fi
190265
191266 - name : Create GitHub Release
192267 if : steps.check_commit.outputs.trigger_release == 'true'
0 commit comments