ci: use majorMinorPatch for clean semver tags#91
Conversation
semVer includes pre-release height on non-main branches, resulting in tags like v1.0.0-101. On main, we want clean semver tags like v1.0.1, which comes from the majorMinorPatch output. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🏗️ PR Added to Squad Triage QueueThis PR has been labeled with Next steps:
|
SummarySummary
CoverageAppHost - 0%
Domain - 87.2%
ServiceDefaults - 0%
Web - 68.7%
|
|
There was a problem hiding this comment.
Pull request overview
Adjusts CI tag creation to use a “clean” SemVer tag (no pre-release height) when tagging builds on main, aligning release tags with v{major}.{minor}.{patch}.
Changes:
- Switch Git tag value from
steps.gitversion.outputs.semVertosteps.gitversion.outputs.majorMinorPatchin themainpush tagging step.
| TAG="v${{ steps.gitversion.outputs.majorMinorPatch }}" | ||
| echo "Creating tag: $TAG" | ||
| git tag "$TAG" || echo "Tag already exists: $TAG" | ||
| git push origin "$TAG" || echo "Tag already pushed" |
There was a problem hiding this comment.
Determine Version runs with continue-on-error: true, but the tag step uses steps.gitversion.outputs.majorMinorPatch without a fallback/validation. If GitVersion fails or outputs are empty, this will attempt to tag/push v (or an empty tag) and the || echo ... masking will hide the failure. Consider explicitly validating the version output is non-empty before tagging, and avoid swallowing non-"already exists" failures (e.g., fail the job or check whether the tag exists and points at the current commit).
| TAG="v${{ steps.gitversion.outputs.majorMinorPatch }}" | |
| echo "Creating tag: $TAG" | |
| git tag "$TAG" || echo "Tag already exists: $TAG" | |
| git push origin "$TAG" || echo "Tag already pushed" | |
| set -euo pipefail | |
| TAG="v${{ steps.gitversion.outputs.majorMinorPatch }}" | |
| if [ -z "$TAG" ] || [ "$TAG" = "v" ]; then | |
| echo "Error: GitVersion output 'majorMinorPatch' is empty; refusing to create or push tag." | |
| exit 1 | |
| fi | |
| CURRENT_COMMIT="$(git rev-parse HEAD)" | |
| echo "Ensuring tag exists for current commit: $TAG -> $CURRENT_COMMIT" | |
| if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then | |
| TAG_COMMIT="$(git rev-list -n 1 "$TAG")" | |
| if [ "$TAG_COMMIT" = "$CURRENT_COMMIT" ]; then | |
| echo "Tag already exists and points to the current commit: $TAG" | |
| exit 0 | |
| fi | |
| echo "Error: Tag $TAG already exists but points to $TAG_COMMIT instead of $CURRENT_COMMIT." | |
| exit 1 | |
| fi | |
| git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null 2>&1 && { | |
| echo "Error: Tag $TAG already exists on origin but is not present locally. Fetch tags and verify its target before retrying." | |
| exit 1 | |
| } | |
| git tag "$TAG" | |
| git push origin "$TAG" |
GitVersion's semVer output includes pre-release height (e.g. v1.0.0-101).
On main, we want clean v1.0.1 format, which comes from majorMinorPatch.
This ensures the first post-sprint release is tagged v1.0.1, not v1.0.0-{height}.