Update publish.yml #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish NuGet Package | |
| on: | |
| push: | |
| branches: | |
| - master | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '9.0.x' | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Get the version from the .csproj file | |
| id: get_version | |
| run: | | |
| VERSION=$(grep -oPm1 "(?<=<Version>)[^<]+" src/SetSharp/SetSharp.csproj) | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| - name: Get the latest published version from NuGet | |
| id: get_latest_version | |
| run: | | |
| PACKAGE_ID="SetSharp" | |
| LATEST_VERSION=$(curl -s https://api.nuget.org/v3-flatcontainer/${PACKAGE_ID,,}/index.json | jq -r '.versions | last') | |
| echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV | |
| - name: Compare versions | |
| id: version_check | |
| run: | | |
| if [ "$VERSION" != "$LATEST_VERSION" ]; then | |
| echo "New version detected: $VERSION" | |
| echo "run_publish=true" >> $GITHUB_ENV | |
| else | |
| echo "No new version detected" | |
| echo "run_publish=false" >> $GITHUB_ENV | |
| - name: Build | |
| if: env.run_publish == 'true' | |
| run: dotnet build --configuration Release --no-restore | |
| - name: Pack | |
| if: env.run_publish == 'true' | |
| run: dotnet pack src/SetSharp/SetSharp.csproj --configuration Release --no-build | |
| - name: Publish to NuGet | |
| if: env.run_publish == 'true' | |
| run: dotnet nuget push "src/SetSharp/bin/Release/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json" |