Skip to content

Normalize NuGet package version from release tags in publish workflow#20

Merged
maikebing merged 6 commits into
masterfrom
copilot/modify-ci-for-nuget-release
Apr 18, 2026
Merged

Normalize NuGet package version from release tags in publish workflow#20
maikebing merged 6 commits into
masterfrom
copilot/modify-ci-for-nuget-release

Conversation

Copilot AI commented Apr 18, 2026

Copy link
Copy Markdown

Release tags are created with a leading v (for example v0.5.0), but the published NuGet package version should be 0.5.0. This updates the publish workflow to derive a valid package version from the tag before packing and publishing.

  • Version normalization

    • Resolve the package version from github.event.release.tag_name or github.ref_name
    • Strip a leading v before invoking dotnet build and dotnet pack
  • Version validation

    • Fail early when the tag is empty, is only v, or does not produce a valid semantic version
    • Keep invalid release tags from producing incorrectly versioned NuGet artifacts
  • Publish behavior

    • Ensure packaged artifacts use the normalized version rather than the raw Git tag
- name: Resolve package version
  env:
    RAW_TAG: ${{ github.event.release.tag_name || github.ref_name }}
  run: |
    PACKAGE_VERSION="${RAW_TAG#v}"
    echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> "$GITHUB_ENV"

- name: Pack
  run: dotnet pack ... -p:Version="$PACKAGE_VERSION"

Copilot AI and others added 6 commits April 18, 2026 10:58
@maikebing maikebing marked this pull request as ready for review April 18, 2026 11:05
Copilot AI review requested due to automatic review settings April 18, 2026 11:05
@maikebing maikebing merged commit 38bd6e6 into master Apr 18, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the publish GitHub Actions workflow to derive a NuGet-compatible package version from release tags (e.g., v0.5.00.5.0) and pass it into dotnet build / dotnet pack to ensure published artifacts use the normalized version.

Changes:

  • Add a workflow step to extract and validate PACKAGE_VERSION from the release tag/ref name.
  • Pass the normalized version into dotnet build and dotnet pack via -p:Version=....

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

env:
RAW_TAG: ${{ github.event.release.tag_name || github.ref_name }}
run: |
NUGET_VERSION_PATTERN='^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z-]+)*(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$'

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version validation regex is more permissive than NuGet/SemVer rules and will accept versions that dotnet pack will later reject (e.g., 1.2.3.alpha without a - prerelease separator, and potentially versions with leading zeros like 01.2.3). Consider tightening the pattern to SemVer 2.0.0 rules (including 0|[1-9][0-9]* for numeric identifiers and making prerelease start with -), or validate using NuGet's own version parser so the early-fail behavior matches what packing will accept.

Copilot uses AI. Check for mistakes.
Comment on lines +36 to +38
env:
RAW_TAG: ${{ github.event.release.tag_name || github.ref_name }}
run: |

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With workflow_dispatch, github.ref_name will usually be a branch name (e.g., main), so RAW_TAG will not be a version tag and this workflow will now fail validation on manual runs. If manual dispatch is intended to remain usable, consider adding an explicit workflow input for the version/tag (and prefer that over ref_name), or only applying this tag-based derivation on release/tag contexts.

Copilot uses AI. Check for mistakes.
@maikebing maikebing deleted the copilot/modify-ci-for-nuget-release branch April 18, 2026 11:09
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.

3 participants