Skip to content

Commit c6c99c3

Browse files
committed
Refactor tag-release workflow to improve initial release handling
- Updated the tag-release workflow to use explicit diff commands for analyzing changes since the last release, enhancing clarity and reliability. - Introduced handling for initial releases, allowing for accurate statistics without requiring a commit range. - Removed deprecated range syntax in favor of more explicit commands for better maintainability.
1 parent b274e29 commit c6c99c3

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

‎.github/workflows/tag-release.yml‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,31 @@ jobs:
7171
7272
if [ -z "$LAST_TAG" ]; then
7373
echo "No previous release found, analyzing all commits"
74-
COMMIT_RANGE="$(git rev-list --max-parents=0 HEAD)..HEAD"
7574
LAST_TAG="initial"
75+
# For initial release, use different commands that don't require a range
76+
FILES_CHANGED=$(git ls-files | wc -l)
77+
COMMITS_COUNT=$(git rev-list --count HEAD)
78+
# Get stats by diffing empty tree against HEAD
79+
EMPTY_TREE=$(git hash-object -t tree /dev/null)
80+
ADDITIONS=$(git diff --shortstat "$EMPTY_TREE" HEAD | grep -oE '[0-9]+ insertions?' | grep -oE '[0-9]+' || echo "0")
81+
DELETIONS=$(git diff --shortstat "$EMPTY_TREE" HEAD | grep -oE '[0-9]+ deletions?' | grep -oE '[0-9]+' || echo "0")
82+
COMMIT_MESSAGES=$(git log --oneline --no-color HEAD | head -30)
83+
DETAILED_CHANGES=$(git diff --name-status --no-color "$EMPTY_TREE" HEAD | head -50)
84+
PR_REFS=$(git log --oneline --no-color HEAD | grep -oE '#[0-9]+' | sort -u | head -10 || echo "")
7685
else
77-
COMMIT_RANGE="$LAST_TAG..HEAD"
7886
echo "Analyzing changes since last release: $LAST_TAG"
87+
# Use explicit two-commit diff syntax instead of range syntax
88+
FILES_CHANGED=$(git diff --name-only "$LAST_TAG" HEAD | wc -l)
89+
COMMITS_COUNT=$(git rev-list --count "$LAST_TAG"..HEAD)
90+
ADDITIONS=$(git diff --shortstat "$LAST_TAG" HEAD | grep -oE '[0-9]+ insertions?' | grep -oE '[0-9]+' || echo "0")
91+
DELETIONS=$(git diff --shortstat "$LAST_TAG" HEAD | grep -oE '[0-9]+ deletions?' | grep -oE '[0-9]+' || echo "0")
92+
COMMIT_MESSAGES=$(git log --oneline --no-color "$LAST_TAG"..HEAD | head -30)
93+
DETAILED_CHANGES=$(git diff --name-status --no-color "$LAST_TAG" HEAD | head -50)
94+
PR_REFS=$(git log --oneline --no-color "$LAST_TAG"..HEAD | grep -oE '#[0-9]+' | sort -u | head -10 || echo "")
7995
fi
8096
81-
# Get change statistics
82-
FILES_CHANGED=$(git diff --name-only $COMMIT_RANGE | wc -l)
83-
COMMITS_COUNT=$(git rev-list --count $COMMIT_RANGE)
84-
ADDITIONS=$(git diff --shortstat $COMMIT_RANGE | grep -oE '[0-9]+ insertions?' | grep -oE '[0-9]+' || echo "0")
85-
DELETIONS=$(git diff --shortstat $COMMIT_RANGE | grep -oE '[0-9]+ deletions?' | grep -oE '[0-9]+' || echo "0")
86-
87-
# Get commit messages (limit to prevent memory issues)
88-
COMMIT_MESSAGES=$(git log --oneline --no-color $COMMIT_RANGE | head -30)
89-
90-
# Get file changes (limit to prevent memory issues)
91-
DETAILED_CHANGES=$(git diff --name-status --no-color $COMMIT_RANGE | head -50)
92-
93-
# Get PR references from commit messages
94-
PR_REFS=$(git log --oneline --no-color $COMMIT_RANGE | grep -oE '#[0-9]+' | sort -u | head -10 || echo "")
95-
9697
# Save outputs
9798
echo "last_tag=$LAST_TAG" >> $GITHUB_OUTPUT
98-
echo "commit_range=$COMMIT_RANGE" >> $GITHUB_OUTPUT
9999
echo "files_changed=$FILES_CHANGED" >> $GITHUB_OUTPUT
100100
echo "commits_count=$COMMITS_COUNT" >> $GITHUB_OUTPUT
101101
echo "additions=$ADDITIONS" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)