|
| 1 | +name: NuGet Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Build & Test |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Setup .NET |
| 19 | + uses: actions/setup-dotnet@v4 |
| 20 | + with: |
| 21 | + dotnet-version: '8.0.x' |
| 22 | + |
| 23 | + - name: Restore |
| 24 | + run: dotnet restore src/NativeWebSocket/NativeWebSocket.csproj |
| 25 | + |
| 26 | + - name: Build |
| 27 | + run: dotnet build src/NativeWebSocket/NativeWebSocket.csproj -c Release --no-restore |
| 28 | + |
| 29 | + publish: |
| 30 | + name: Publish to NuGet |
| 31 | + runs-on: ubuntu-latest |
| 32 | + needs: [build] |
| 33 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 2 |
| 38 | + |
| 39 | + - name: Setup .NET |
| 40 | + uses: actions/setup-dotnet@v4 |
| 41 | + with: |
| 42 | + dotnet-version: '8.0.x' |
| 43 | + |
| 44 | + - name: Check for version change |
| 45 | + id: version |
| 46 | + run: | |
| 47 | + CURRENT=$(grep '<Version>' src/NativeWebSocket/NativeWebSocket.csproj | sed 's/.*<Version>\(.*\)<\/Version>.*/\1/') |
| 48 | + PREVIOUS=$(git show HEAD~1:src/NativeWebSocket/NativeWebSocket.csproj 2>/dev/null | grep '<Version>' | sed 's/.*<Version>\(.*\)<\/Version>.*/\1/' || echo "") |
| 49 | + echo "current=$CURRENT" >> $GITHUB_OUTPUT |
| 50 | + echo "previous=$PREVIOUS" >> $GITHUB_OUTPUT |
| 51 | + if [ "$CURRENT" != "$PREVIOUS" ]; then |
| 52 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 53 | + echo "Version changed: $PREVIOUS -> $CURRENT" |
| 54 | + else |
| 55 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 56 | + echo "Version unchanged: $CURRENT" |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Pack NativeWebSocket |
| 60 | + if: steps.version.outputs.changed == 'true' |
| 61 | + run: dotnet pack src/NativeWebSocket/NativeWebSocket.csproj -c Release -o packages/ |
| 62 | + |
| 63 | + - name: Pack NativeWebSocket.MonoGame |
| 64 | + if: steps.version.outputs.changed == 'true' |
| 65 | + run: dotnet pack integrations/MonoGame/NativeWebSocket.MonoGame.csproj -c Release -o packages/ |
| 66 | + |
| 67 | + - name: Publish to NuGet |
| 68 | + if: steps.version.outputs.changed == 'true' |
| 69 | + run: dotnet nuget push packages/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate |
0 commit comments