publish_nuget.yml #8
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
| # This workflow will build, pack and deploy the solution on Nuget | |
| name: 'publish_nuget.yml' | |
| on: | |
| push: | |
| tags: | |
| - '[0-9]+.[0-9]+.[0-9]+' | |
| workflow_dispatch: # Allows manual triggering | |
| inputs: | |
| version: | |
| description: 'NuGet package version (SemVer)' | |
| required: true | |
| default: '1.0.0' | |
| publish_to_nuget: | |
| description: 'Publish to NuGet.org?' | |
| required: false | |
| type: boolean | |
| default: true | |
| jobs: | |
| publish: | |
| if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| # Only validate tag is on master for auto-triggered runs | |
| - name: Validate Tag Position (Auto-Trigger Only) | |
| if: github.event_name == 'push' | |
| run: | | |
| TAG_COMMIT=$(git rev-parse ${{ github.ref }}) | |
| BASE=$(git merge-base HEAD origin/master) | |
| # Allow tag to be ahead of master (new commits since tagging) | |
| # But reject if tag is behind or on a different branch | |
| if git merge-base --is-ancestor $BASE $TAG_COMMIT; then | |
| echo "Tag validation passed" | |
| else | |
| echo "ERROR: Tag appears to be on wrong branch" | |
| exit 1 | |
| fi | |
| - name: Setup .NET 10. | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: latest | |
| - name: Build | |
| run: dotnet build --configuration Release | |
| - name: Pack NuGet Package | |
| run: | | |
| # Use the version from tag or workflow_dispatch input | |
| VERSION=${{ github.ref_name == '' && inputs.version || github.ref_name }} | |
| dotnet pack src/Html2OpenXml/HtmlToOpenXml.csproj --configuration Release --output ./nupkg \ | |
| -p Version=$VERSION | |
| - name: Push to NuGet.org | |
| if: inputs.publish_to_nuget | |
| run: | | |
| # Ensure we have packages to push | |
| if [ ! -f "./nupkg/*.nupkg" ]; then | |
| echo "ERROR: No .nupkg files found in ./nupkg/" | |
| exit 1 | |
| fi | |
| dotnet nuget push ./nupkg/*.nupkg \ | |
| --api-key $NUGET_API_KEY \ | |
| -s https://api.nuget.org/v3/index.json | |
| - name: Create GitHub Release | |
| run: | | |
| VERSION=${{ github.ref_name == '' && inputs.version || github.ref_name }} | |
| gh release create "$VERSION" \ | |
| --title "Release $VERSION" \ | |
| *.nupkg \ | |
| --generate-notes \ | |
| --draft # Set to false when ready to publish |