Update dotnet-desktop.yml #31
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: NuGet Release Automation | |
| on: | |
| push: | |
| branches: | |
| - master | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest # Use a Linux runner | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 # Fetch all history (tags and commits) | |
| - name: Setup .NET SDK | |
| uses: actions/setup-dotnet@v3 | |
| with: | |
| dotnet-version: '9.0' # Use your project's .NET version | |
| - name: Update Workloads | |
| run: dotnet workload update | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build project | |
| run: dotnet build --configuration Release | |
| - name: Install GitHub CLI | |
| shell: bash | |
| run: | | |
| type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y) | |
| curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ | |
| && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ | |
| && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ | |
| && sudo apt update \ | |
| && sudo apt install gh -y | |
| - name: Get Next Version and Create Tag | |
| id: get_version | |
| shell: bash | |
| run: | | |
| # Get the highest existing tag (if any) | |
| latestTag=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null) | |
| if [ -z "$latestTag" ]; then | |
| # If no tags exist, start with 3.4.0 | |
| nextVersion="3.4.0" | |
| else | |
| # If tags exist, increment based on the highest tag | |
| versionParts=(${latestTag//[^0-9.]/}) # Extract numbers and dots | |
| IFS='.' read -r -a versionArray <<< "$versionParts" | |
| major=${versionArray[0]} | |
| minor=${versionArray[1]} | |
| patch=${versionArray[2]} | |
| # Increment based on the highest tag. | |
| if (( major < 3 )) || (( major == 3 && minor < 4 )); then | |
| nextVersion="3.4.0" # Force to 3.4.0 if < 3.4.0 | |
| else | |
| ((minor++)) | |
| nextVersion="$major.$minor.0" | |
| fi | |
| fi | |
| # Create and push the tag | |
| git tag "v$nextVersion" | |
| git push origin "v$nextVersion" | |
| echo "NUGET_VERSION=$nextVersion" >> "$GITHUB_OUTPUT" | |
| - name: Pack NuGet package | |
| run: dotnet pack --configuration Release -o . /p:Version=${{ steps.get_version.outputs.NUGET_VERSION }} | |
| - name: Push NuGet package to NuGet.org | |
| run: dotnet nuget push "*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate | |
| working-directory: . | |
| - name: Create GitHub Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ steps.get_version.outputs.NUGET_VERSION }} | |
| release_name: Release v${{ steps.get_version.outputs.NUGET_VERSION }} | |
| body: "" # Empty body - no release notes | |
| draft: false | |
| prerelease: false |