ci: enable automatic GitVersion tag creation on main - #88
Conversation
When CI runs on main after merge, create and push the git tag based on GitVersion-determined semver. This enables v1.0.1, v1.0.2, etc. to be automatically tagged without manual intervention. 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
Adds automatic git tag creation to the existing CI workflow so pushes to main can produce a v{semver} tag derived from GitVersion, enabling a release flow based on tags.
Changes:
- Add a CI step that tags the current commit on
mainwithv${{ steps.gitversion.outputs.semVer }}. - Push the created tag back to
originfrom CI.
| 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.
The || echo ... fallbacks on git tag/git push will mask real failures (e.g., permission issues, remote rejection because the tag already exists, or trying to push a tag that wasn't created locally). This can make the workflow appear successful even when no tag was pushed. Prefer explicit existence checks (local+remote) and only treat "already exists" as success; otherwise fail the step so release automation doesn't silently break.
| echo "Creating tag: $TAG" | |
| git tag "$TAG" || echo "Tag already exists: $TAG" | |
| git push origin "$TAG" || echo "Tag already pushed" | |
| echo "Ensuring tag exists locally and remotely: $TAG" | |
| if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then | |
| echo "Tag already exists locally: $TAG" | |
| else | |
| echo "Creating local tag: $TAG" | |
| git tag "$TAG" | |
| fi | |
| if git ls-remote --tags origin "refs/tags/$TAG" | grep -q "refs/tags/$TAG$"; then | |
| echo "Tag already exists on remote: $TAG" | |
| else | |
| echo "Pushing tag to remote: $TAG" | |
| git push origin "$TAG" | |
| fi |
| - name: Create and Push Git Tag | ||
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| TAG="v${{ steps.gitversion.outputs.semVer }}" | ||
| 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.
This step attempts to git push origin "$TAG", but the job's workflow token permissions are currently contents: read (see job-level permissions earlier in this file). With read-only contents permissions, pushing tags will be rejected. Update the workflow/job permissions to contents: write (or move tagging into a separate job with elevated permissions) so the tag push can succeed.
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| TAG="v${{ steps.gitversion.outputs.semVer }}" |
There was a problem hiding this comment.
TAG="v${{ steps.gitversion.outputs.semVer }}" relies on the gitversion step outputs, but the GitVersion setup/execute steps are configured with continue-on-error: true. If GitVersion fails, semVer can be empty and this step would create/push an invalid tag like v. Add a guard (e.g., require steps.gitversion.outcome == 'success' and a non-empty semVer) or fail the job when GitVersion can't determine a version on main.
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TAG="v${{ steps.gitversion.outputs.semVer }}" | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.gitversion.outcome == 'success' && steps.gitversion.outputs.semVer != '' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| SEMVER="${{ steps.gitversion.outputs.semVer }}" | |
| if [ -z "$SEMVER" ]; then | |
| echo "GitVersion did not produce a semVer output; refusing to create a tag." | |
| exit 1 | |
| fi | |
| TAG="v$SEMVER" |
Add step to CI workflow that creates and pushes git tags for each commit to main, using GitVersion-determined semver.
This completes the v1.0.1 release flow:
Closes: versioning automation setup