Build & Publish NuGet (Tag Release) #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: Build & Publish NuGet | |
| on: | |
| push: | |
| branches: | |
| - release # run when pushing to the release branch | |
| workflow_dispatch: # optional manual trigger | |
| jobs: | |
| build-pack-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: '9.0.x' | |
| # Read base version from central config file and build full version | |
| - name: Determine version | |
| id: version | |
| run: | | |
| BASE_VERSION=$(cat VERSION.txt) | |
| echo "Base version: $BASE_VERSION" | |
| FULL_VERSION="$BASE_VERSION.${GITHUB_RUN_NUMBER}" | |
| echo "Full version: $FULL_VERSION" | |
| echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_OUTPUT | |
| echo "FULL_VERSION=$FULL_VERSION" >> $GITHUB_OUTPUT | |
| # Find solution file dynamically (first .sln we encounter) | |
| - name: Locate solution file | |
| id: solution | |
| run: | | |
| SOLUTION=$(find . -maxdepth 5 -name "*.sln" | head -n 1) | |
| if [ -z "$SOLUTION" ]; then | |
| echo "❌ No solution file (*.sln) found in the repo." | |
| exit 1 | |
| fi | |
| echo "Found solution: $SOLUTION" | |
| echo "SOLUTION_PATH=$SOLUTION" >> $GITHUB_OUTPUT | |
| # Restore using the solution | |
| - name: Restore | |
| run: dotnet restore "${{ steps.solution.outputs.SOLUTION_PATH }}" | |
| # Pack all packable projects in the solution into ./artifacts with unified version | |
| - name: Pack all NuGet projects | |
| run: dotnet pack "./FluentAAS/FluentAAS.sln" -c Release -o ./artifacts /p:PackageVersion=${{ steps.version.outputs.FULL_VERSION }} | |
| # Publish NuGet packages to nuget.org | |
| - name: Publish to NuGet | |
| run: dotnet nuget push "artifacts/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json" --skip-duplicate | |
| # Build changelog / release notes automatically using release-changelog-builder | |
| - name: Build Changelog | |
| id: build_changelog | |
| uses: mikepenz/release-changelog-builder-action@v6 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| fetchReleaseInformation: "true" | |
| # Upload artifacts to the workflow run (extra manual download option) | |
| - name: Upload NuGet Artifacts | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: nuget-packages-${{ steps.version.outputs.FULL_VERSION }} | |
| path: ./artifacts/*.nupkg | |
| # Create GitHub Release with generated changelog and attach .nupkg files | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.version.outputs.FULL_VERSION }} | |
| name: FluentAAS v${{ steps.version.outputs.FULL_VERSION }} | |
| body: ${{ steps.build_changelog.outputs.changelog }} | |
| files: ./artifacts/*.nupkg | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |