Enhances command registration with logging and validation #9
Workflow file for this run
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 and Publish NuGet | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| tags: | |
| - 'v*.*.*' | |
| pull_request: | |
| branches: | |
| - main | |
| - master | |
| workflow_dispatch: | |
| env: | |
| DOTNET_VERSION: '9.0.x' | |
| PROJECT_PATH: 'src/CommandQuery.Framing/CommandQuery.Framing.csproj' | |
| NUGET_OUTPUT: 'src/CommandQuery.Framing/nuget' | |
| jobs: | |
| build-and-test: | |
| name: Build and Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required for versioning | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build solution | |
| run: dotnet build --configuration Release --no-restore | |
| - name: Run tests | |
| run: dotnet test --configuration Release --no-build --verbosity normal | |
| - name: Determine version | |
| id: version | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| # Use tag version (e.g., v1.0.11 -> 1.0.11) | |
| VERSION="${GITHUB_REF#refs/tags/v}" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "suffix=" >> $GITHUB_OUTPUT | |
| else | |
| # Read base version from csproj | |
| BASE_VERSION=$(grep -oP '<Version>\K[^<]+' ${{ env.PROJECT_PATH }}) | |
| # Use build number for pre-release versions | |
| BUILD_NUMBER=${{ github.run_number }} | |
| VERSION="$BASE_VERSION" | |
| SUFFIX="ci.$BUILD_NUMBER" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "suffix=$SUFFIX" >> $GITHUB_OUTPUT | |
| fi | |
| echo "Building version: $VERSION${SUFFIX:+-$SUFFIX}" | |
| shell: bash | |
| - name: Pack NuGet package | |
| run: | | |
| if [ -z "${{ steps.version.outputs.suffix }}" ]; then | |
| dotnet pack ${{ env.PROJECT_PATH }} \ | |
| --configuration Release \ | |
| --no-build \ | |
| --output ${{ env.NUGET_OUTPUT }} \ | |
| /p:Version=${{ steps.version.outputs.version }} | |
| else | |
| dotnet pack ${{ env.PROJECT_PATH }} \ | |
| --configuration Release \ | |
| --no-build \ | |
| --output ${{ env.NUGET_OUTPUT }} \ | |
| /p:Version=${{ steps.version.outputs.version }} \ | |
| /p:VersionSuffix=${{ steps.version.outputs.suffix }} | |
| fi | |
| shell: bash | |
| - name: Upload NuGet package artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: ${{ env.NUGET_OUTPUT }}/*.nupkg | |
| if-no-files-found: error | |
| - name: Upload symbol package artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: symbol-package | |
| path: ${{ env.NUGET_OUTPUT }}/*.snupkg | |
| if-no-files-found: error | |
| publish-nuget: | |
| name: Publish to NuGet.org | |
| needs: build-and-test | |
| runs-on: ubuntu-latest | |
| environment: production | |
| if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') | |
| steps: | |
| - name: Download NuGet package | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: packages | |
| - name: Download symbol package | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: symbol-package | |
| path: packages | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Publish NuGet package | |
| run: | | |
| dotnet nuget push packages/*.nupkg \ | |
| --api-key ${{ secrets.NUGET_API_KEY }} \ | |
| --source https://api.nuget.org/v3/index.json \ | |
| --skip-duplicate | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| - name: Publish symbol package | |
| run: | | |
| dotnet nuget push packages/*.snupkg \ | |
| --api-key ${{ secrets.NUGET_API_KEY }} \ | |
| --source https://api.nuget.org/v3/index.json \ | |
| --skip-duplicate | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| - name: Create GitHub Release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| packages/*.nupkg | |
| packages/*.snupkg | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update README version | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| run: | | |
| # Checkout the repository to make changes | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| # Extract version from tag | |
| VERSION="${GITHUB_REF#refs/tags/v}" | |
| # Clone the repository | |
| git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git repo | |
| cd repo | |
| # Update README.md | |
| sed -i "s/\*\*Current Version:\*\* [0-9]\+\.[0-9]\+\.[0-9]\+/**Current Version:** $VERSION/" README.md | |
| # Commit and push if there are changes | |
| if git diff --quiet; then | |
| echo "No changes to README.md" | |
| else | |
| git add README.md | |
| git commit -m "chore: update README version to $VERSION [skip ci]" | |
| git push origin HEAD:main || git push origin HEAD:master || echo "Could not push to main/master" | |
| fi | |
| shell: bash | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |