Skip to content

Commit e22c15b

Browse files
committed
attempted fix
1 parent 7e1d530 commit e22c15b

File tree

1 file changed

+58
-24
lines changed

1 file changed

+58
-24
lines changed

.github/workflows/release.yml

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,67 +34,101 @@ jobs:
3434
- name: Build x64 Release
3535
run: msbuild /m /p:Configuration=${{ env.BUILD_CONFIGURATION }} /p:Platform=${{ env.PLATFORM }} ${{ env.SOLUTION_FILE_PATH }}
3636

37-
- name: Determine version and create tag if needed
37+
- name: Determine version and create tag if needed (with logging)
3838
id: version
3939
shell: cmd
4040
run: |
4141
@echo off
4242
setlocal enabledelayedexpansion
43-
REM -- Attempt to retrieve the latest tag (assumed x.y.z format); suppress errors.
44-
for /f "delims=" %%t in ('git describe --tags --abbrev=0 2^>nul') do set LATEST_TAG=%%t
43+
44+
echo -------------------------------
45+
echo Starting version detection...
46+
echo -------------------------------
47+
48+
REM -- Get the latest tag merged into HEAD, sorted by version.
49+
set "LATEST_TAG="
50+
for /f "delims=" %%t in ('git tag --merged HEAD --sort=-v:refname') do (
51+
set "LATEST_TAG=%%t"
52+
echo Found merged tag: %%t
53+
goto GotLatestTag
54+
)
55+
:GotLatestTag
56+
if not defined LATEST_TAG (
57+
echo No merged tags found on HEAD.
58+
) else (
59+
echo Latest merged tag is: !LATEST_TAG!
60+
)
4561
62+
REM If no tag is defined, default to 0.0.0.
4663
if not defined LATEST_TAG (
4764
echo No tag found. Defaulting to 0.0.0.
4865
set "LATEST_TAG=0.0.0"
49-
REM Count all commits and subtract 1 so that the very first commit remains 0.0.0.
66+
REM Count all commits and subtract 1 (first commit remains 0.0.0).
5067
for /f %%i in ('git rev-list HEAD --count') do set ALL_COUNT=%%i
68+
echo Total commits found: !ALL_COUNT!
5169
set /a COMMITS_SINCE=!ALL_COUNT! - 1
5270
if !COMMITS_SINCE! lss 0 set COMMITS_SINCE=0
71+
echo Computed commits since tag: !COMMITS_SINCE!
5372
) else (
54-
REM If a tag exists, count the commits from that tag to HEAD.
73+
REM If a tag exists, count commits from that tag to HEAD.
5574
for /f %%i in ('git rev-list !LATEST_TAG!..HEAD --count') do set COMMITS_SINCE=%%i
75+
echo Commits since tag !LATEST_TAG!: !COMMITS_SINCE!
5676
)
5777
58-
echo Latest tag: !LATEST_TAG!
59-
echo Commits since latest tag: !COMMITS_SINCE!
78+
echo -------------------------------
79+
echo Finished counting commits.
80+
echo -------------------------------
6081
61-
REM If a tag exists (other than the default) then check if HEAD is tagged.
62-
if not "!LATEST_TAG!"=="0.0.0" (
63-
for /f %%i in ('git rev-list -n 1 !LATEST_TAG!') do set TAG_COMMIT=%%i
64-
for /f %%i in ('git rev-parse HEAD') do set CURRENT_COMMIT=%%i
65-
echo Tag commit: !TAG_COMMIT!
66-
echo Current commit: !CURRENT_COMMIT!
67-
if "!TAG_COMMIT!"=="!CURRENT_COMMIT!" (
68-
echo HEAD is tagged. Using existing version !LATEST_TAG!.
69-
set "VERSION=!LATEST_TAG!"
70-
goto WriteOutput
82+
REM Check if HEAD is already tagged with the current LATEST_TAG.
83+
set "HEAD_TAG="
84+
for /f %%i in ('git tag --points-at HEAD') do (
85+
echo Found tag on HEAD: %%i
86+
if "%%i"=="!LATEST_TAG!" (
87+
set "HEAD_TAG=%%i"
7188
)
72-
) else (
73-
REM If using default tag and no new commits, keep 0.0.0.
89+
)
90+
if defined HEAD_TAG (
91+
echo HEAD is already tagged with !LATEST_TAG!. Reusing that version.
92+
set "VERSION=!LATEST_TAG!"
93+
goto WriteOutput
94+
)
95+
96+
REM In the default case for 0.0.0, if there are no new commits, keep version 0.0.0.
97+
if "!LATEST_TAG!"=="0.0.0" (
7498
if "!COMMITS_SINCE!"=="0" (
99+
echo No new commits since base tag 0.0.0. Keeping version 0.0.0.
75100
set "VERSION=0.0.0"
76101
goto WriteOutput
77102
)
78103
)
79104
80-
REM Otherwise, split LATEST_TAG into MAJOR.MINOR.PATCH.
105+
REM Otherwise, split LATEST_TAG into MAJOR, MINOR, and PATCH.
106+
echo Splitting LATEST_TAG (!LATEST_TAG!) into major, minor, and patch.
81107
for /f "tokens=1-3 delims=." %%a in ("!LATEST_TAG!") do (
82108
set MAJOR=%%a
83109
set MINOR=%%b
84110
set PATCH=%%c
85111
)
112+
echo Major: !MAJOR!, Minor: !MINOR!, Patch: !PATCH!
113+
86114
set /a NEW_PATCH=!PATCH! + !COMMITS_SINCE!
87115
set "VERSION=!MAJOR!.!MINOR!.!NEW_PATCH!"
88-
echo New version: !VERSION!
116+
echo New version computed: !VERSION!
89117
90-
REM Create a lightweight tag on HEAD and push it.
118+
REM Create a lightweight tag on HEAD (so no annotated tag/committer identity required) and push it.
119+
echo Tagging HEAD with version !VERSION!
91120
git tag !VERSION!
121+
echo Pushing tag !VERSION! to origin...
92122
git push origin !VERSION!
123+
echo Tag !VERSION! pushed successfully.
93124
94125
:WriteOutput
95-
REM Write the computed version to the GitHub output environment file.
126+
REM Write the computed version to GitHub Actions' output file.
96127
echo version=!VERSION!>> %GITHUB_OUTPUT%
97-
128+
echo -------------------------------
129+
echo Version determination complete: !VERSION!
130+
echo -------------------------------
131+
98132
99133
- name: Rename release package with version
100134
shell: cmd

0 commit comments

Comments
 (0)