name: Publish NuGet Packages on: pull_request: branches: - main workflow_dispatch: jobs: publish: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 - name: Setup .NET uses: actions/setup-dotnet@v3 with: dotnet-version: 10.0.x - name: Restore dependencies run: dotnet restore - name: Build all projects run: dotnet build -c Release - name: Pack all projects run: | for projfile in $(find . -name "*.csproj"); do if grep -q "True" "$projfile"; then echo "Packing $projfile..." if ! dotnet pack "$projfile" -c Release -o ./artifacts; then echo "Failed to pack $projfile" fi fi done - name: Publish all packages env: NUGET_API_KEY: ${{ secrets.NUGET_TOKEN }} run: | set +e for projfile in $(find . -name "*.csproj"); do if grep -q "True" "$projfile"; then projname=$(basename "$projfile" .csproj) echo "Checking $projname..." pkg=$(find ./artifacts -maxdepth 1 -type f \ -regex "./artifacts/${projname}\.[0-9][^/]*\.nupkg" \ ! -name "*.symbols.nupkg" | sort -V | tail -n1) if [ -n "$pkg" ]; then echo "Pushing $pkg" dotnet nuget push "$pkg" \ --source "https://git.personalnas.com/api/packages/Misaki/nuget/index.json" \ --api-key "$NUGET_API_KEY" \ --skip-duplicate else echo "No package found for $projname" fi fi done