Build & Publish NuGet (Tag Release) #2
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 }}" | |
| # Build solution in Release | |
| - name: Build | |
| run: dotnet build "${{ steps.solution.outputs.SOLUTION_PATH }}" --configuration Release --no-restore | |
| # Run ALL tests in the solution | |
| - name: Test | |
| run: dotnet test "${{ steps.solution.outputs.SOLUTION_PATH }}" --configuration Release --no-build --verbosity normal | |
| # Pack all relevant projects into ./artifacts with unified version | |
| - name: Pack FluentAAS Builder | |
| run: dotnet pack src/FluentAas.Builder/FluentAas.Builder.csproj \ | |
| -c Release -o ./artifacts \ | |
| /p:PackageVersion=${{ steps.version.outputs.FULL_VERSION }} | |
| - name: Pack FluentAAS Core | |
| run: dotnet pack src/FluentAas.Core/FluentAas.Core.csproj \ | |
| -c Release -o ./artifacts \ | |
| /p:PackageVersion=${{ steps.version.outputs.FULL_VERSION }} | |
| - name: Pack FluentAAS IO | |
| run: dotnet pack src/FluentAas.IO/FluentAas.IO.csproj \ | |
| -c Release -o ./artifacts \ | |
| /p:PackageVersion=${{ steps.version.outputs.FULL_VERSION }} | |
| - name: Pack FluentAAS Templates | |
| run: dotnet pack src/FluentAas.Templates/FluentAas.Templates.csproj \ | |
| -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" | |
| failOnError: "true" | |
| # Upload artifacts to the workflow run (extra manual download option) | |
| - name: Upload NuGet Artifacts | |
| uses: actions/upload-artifact@v4 | |
| 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 }} |