Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Jun 26, 2025

Automate release notes and version from GitHub releases

Summary

This PR eliminates the need to manually maintain version numbers and release notes in the csproj file by automating them through GitHub releases. When a new release is created on GitHub, the workflow will now:

  1. Extract the version number from the release tag (handling 'v' prefix automatically)
  2. Use the release description as PackageReleaseNotes via a file-based approach to safely handle quotes and newlines
  3. Pass these values to dotnet pack via MSBuild properties

The hardcoded Version and PackageReleaseNotes properties have been removed from the csproj file, making the release process much more streamlined.

Key Changes:

  • Modified GitHub Actions workflow to extract version from github.event.release.tag_name
  • Added safe release notes handling by writing to file first, then reading with cat
  • Updated dotnet pack command to use MSBuild properties -p:Version and -p:PackageReleaseNotes
  • Removed hardcoded version (2.7.0) and release notes (24 lines) from csproj

Review & Testing Checklist for Human

  • 🔴 CRITICAL: Test end-to-end release workflow - Create a test release on GitHub with version tag (e.g., "v2.8.0-test") and verify the NuGet package is published with correct version and release notes extracted from the release
  • 🟡 Test version tag extraction with edge cases - Try different tag formats like "v2.8.0", "2.8.0", "2.8.0-beta", "v2.8.0-rc1" to ensure version extraction works correctly
  • 🟡 Test release notes with problematic content - Create a test release with release notes containing quotes, newlines, apostrophes, and special characters to ensure the file-based approach handles them safely
  • 🟡 Verify NuGet package metadata - After publishing, check the NuGet package on nuget.org to confirm version and release notes appear correctly in the package details
  • 🟢 Confirm local builds still work - Verify that local dotnet build and dotnet pack commands still work (they should use default version 1.0.0 without the properties)

Diagram

graph TD
    A[GitHub Release Created] --> B[dotnetcore.yml Workflow]
    B --> C[Extract Version Step]
    B --> D[Write Release Notes Step]
    B --> E[Package Step]
    B --> F[Publish Step]
    
    C --> G[github.event.release.tag_name]
    C --> H[Strip v prefix]
    C --> I[Output version variable]
    
    D --> J[github.event.release.body]
    D --> K[Write to release-notes.txt]
    
    K --> E
    I --> E
    E --> L[Read from file with cat]
    E --> M[dotnet pack with MSBuild props]
    
    N[PreMailer.Net.csproj] --> E
    
    style B fill:#90EE90
    style N fill:#90EE90
    style C fill:#87CEEB
    style D fill:#87CEEB
    style E fill:#87CEEB
    style F fill:#white
    style A fill:#white
    style G fill:#white
    style H fill:#white
    style I fill:#white
    style J fill:#white
    style K fill:#white
    style L fill:#white
    style M fill:#white
    
    subgraph Legend
        L1[Major Edit]:::major-edit
        L2[Minor Edit]:::minor-edit  
        L3[Context/No Edit]:::context
    end
    
    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#white
Loading

Notes

  • File-based approach: The release notes are now written to release-notes.txt first, then read with cat to safely handle quotes, newlines, and other special characters that could break shell command parsing
  • Version extraction: Handles the common 'v' prefix pattern (e.g., "v2.8.0" becomes "2.8.0") but should be tested with various tag formats
  • Local development impact: Local builds will now use default version (1.0.0) since the MSBuild properties are only provided during release builds
  • Workflow isolation: The release-specific steps only execute when github.event_name == 'release', so they won't affect regular PR builds
  • Addresses feedback: Updated based on @martinnormark's comment about safer PackageReleaseNotes handling

⚠️ Important: This PR changes the core release process and should be tested thoroughly with a test release before being used for production releases.

- Extract version from release tag, handling 'v' prefix
- Use release body as PackageReleaseNotes
- Pass values to dotnet pack via MSBuild properties
- Remove hardcoded Version and PackageReleaseNotes from csproj

Co-Authored-By: Martin <[email protected]>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@martinnormark
Copy link
Contributor

Handling PackageReleaseNotes — needs improvement

-p:PackageReleaseNotes="${{ github.event.release.body }}"

This can break if github.event.release.body includes:

  • Quotes (")
  • Line breaks (newlines)

✅ Fix: Use a multiline-safe input

Wrap the PackageReleaseNotes in single quotes in the shell to avoid breaking due to double quotes and preserve line breaks:

-p:PackageReleaseNotes='${{ github.event.release.body }}'

This works because GitHub will substitute the body literally, and single quotes in shell protect the contents from interpretation.

⚠️ Be aware: If the release notes contain single quotes ', this can still cause problems. A safer solution is to write the notes to a file and pass it via cat.


✅ Suggested Safe Version

- name: Extract version from tag
  if: ${{ github.event_name == 'release' }}
  id: version
  run: |
    TAG_NAME="${{ github.event.release.tag_name }}"
    VERSION=${TAG_NAME#v}
    echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Write release notes to file
  if: ${{ github.event_name == 'release' }}
  run: echo "${{ github.event.release.body }}" > release-notes.txt

- name: Package
  if: ${{ github.event_name == 'release' }}
  run: |
    RELEASE_NOTES=$(cat release-notes.txt)
    dotnet pack -c Release -o . PreMailer.Net/PreMailer.Net/PreMailer.Net.csproj \
      -p:Version="${{ steps.version.outputs.version }}" \
      -p:PackageReleaseNotes="$RELEASE_NOTES"

- name: Publish
  if: ${{ github.event_name == 'release' }}
  run: dotnet nuget push *.nupkg -k ${{ secrets.NUGET_APIKEY }} -s https://api.nuget.org/v3/index.json

- Write release notes to file first to avoid shell escaping issues
- Read from file using cat to safely handle quotes and line breaks
- Addresses feedback from @martinnormark on PR #433

Co-Authored-By: Martin <[email protected]>
@martinnormark martinnormark merged commit 24cb3a5 into main Jun 26, 2025
2 checks passed
@martinnormark martinnormark deleted the devin/1750961070-automate-release-notes branch June 26, 2025 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants