Normalize NuGet package version from release tags in publish workflow#20
Conversation
Agent-Logs-Url: https://github.com/IoTSharp/MQTTnet.AspNetCore.Routing/sessions/a8f38bdb-01d6-4f99-8cae-8c335fa953de Co-authored-by: maikebing <3445167+maikebing@users.noreply.github.com>
Agent-Logs-Url: https://github.com/IoTSharp/MQTTnet.AspNetCore.Routing/sessions/a8f38bdb-01d6-4f99-8cae-8c335fa953de Co-authored-by: maikebing <3445167+maikebing@users.noreply.github.com>
Agent-Logs-Url: https://github.com/IoTSharp/MQTTnet.AspNetCore.Routing/sessions/a8f38bdb-01d6-4f99-8cae-8c335fa953de Co-authored-by: maikebing <3445167+maikebing@users.noreply.github.com>
Agent-Logs-Url: https://github.com/IoTSharp/MQTTnet.AspNetCore.Routing/sessions/a8f38bdb-01d6-4f99-8cae-8c335fa953de Co-authored-by: maikebing <3445167+maikebing@users.noreply.github.com>
Agent-Logs-Url: https://github.com/IoTSharp/MQTTnet.AspNetCore.Routing/sessions/a8f38bdb-01d6-4f99-8cae-8c335fa953de Co-authored-by: maikebing <3445167+maikebing@users.noreply.github.com>
Agent-Logs-Url: https://github.com/IoTSharp/MQTTnet.AspNetCore.Routing/sessions/a8f38bdb-01d6-4f99-8cae-8c335fa953de Co-authored-by: maikebing <3445167+maikebing@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates the publish GitHub Actions workflow to derive a NuGet-compatible package version from release tags (e.g., v0.5.0 → 0.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_VERSIONfrom the release tag/ref name. - Pass the normalized version into
dotnet buildanddotnet packvia-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-]+)*)?$' |
There was a problem hiding this comment.
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.
| env: | ||
| RAW_TAG: ${{ github.event.release.tag_name || github.ref_name }} | ||
| run: | |
There was a problem hiding this comment.
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.
Release tags are created with a leading
v(for examplev0.5.0), but the published NuGet package version should be0.5.0. This updates the publish workflow to derive a valid package version from the tag before packing and publishing.Version normalization
github.event.release.tag_nameorgithub.ref_namevbefore invokingdotnet buildanddotnet packVersion validation
v, or does not produce a valid semantic versionPublish behavior