diff --git a/CHANGELOG.md b/CHANGELOG.md index a4ea861..cd75079 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,3 +73,18 @@ Improves the changelog comparison logic to ensure more accurate change detection ### Technical Details - Updated internal comparison logic for more reliable changelog state detection + + +## [1.1.2] - August 2025 + +Improves the changelog comparison functionality by implementing a more accurate git diff-based approach, ensuring more reliable change detection and version tracking. + +### Fixed +- Enhanced changelog comparison accuracy using git diff for more precise change detection + +### Technical Details +- Implemented git diff-based comparison logic for improved changelog state tracking +- Added comprehensive test coverage for changelog comparison scenarios + + + diff --git a/action.yml b/action.yml index 5c16c62..6b43aea 100644 --- a/action.yml +++ b/action.yml @@ -456,20 +456,14 @@ runs: git fetch origin "$BASE_BRANCH" echo "Comparing with origin/$BASE_BRANCH..." - # First, get the content from the base branch - BASE_CONTENT=$(git show "origin/$BASE_BRANCH:${{ inputs.changelog_path }}" 2>/dev/null || echo "") - # Then compare with the current working file - CURRENT_CONTENT=$(cat "${{ inputs.changelog_path }}" 2>/dev/null || echo "") - - if [ "$BASE_CONTENT" = "$CURRENT_CONTENT" ]; then + if git diff --quiet FETCH_HEAD -- "${{ inputs.changelog_path }}"; then echo "has_changes=false" >> $GITHUB_OUTPUT echo "DEBUG: No differences from base branch" else echo "has_changes=true" >> $GITHUB_OUTPUT echo "DEBUG: Changelog differs from base branch" echo "Diff preview:" - # Show the diff between base branch and working directory - git show "origin/$BASE_BRANCH:${{ inputs.changelog_path }}" | diff -u - "${{ inputs.changelog_path }}" || true + git diff FETCH_HEAD -- "${{ inputs.changelog_path }}" fi else # For non-PR events, check local changes diff --git a/test-fix.sh b/test-fix.sh new file mode 100644 index 0000000..8030e82 --- /dev/null +++ b/test-fix.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Test script to verify the changelog comparison fix + +echo "Testing changelog comparison logic..." + +# Create a test changelog +TEST_CHANGELOG="test-changelog.md" +echo "# Test Changelog" > $TEST_CHANGELOG +echo "" >> $TEST_CHANGELOG +echo "## [1.0.0] - January 2025" >> $TEST_CHANGELOG +echo "Initial version" >> $TEST_CHANGELOG + +# Simulate base branch content +BASE_CONTENT="# Test Changelog + +## [1.0.0] - January 2025 +Initial version" + +# Simulate current working directory content (with new changes) +CURRENT_CONTENT="# Test Changelog + +## [1.0.1] - January 2025 +New feature added + +## [1.0.0] - January 2025 +Initial version" + +# Write current content to file +echo "$CURRENT_CONTENT" > $TEST_CHANGELOG + +# Test the comparison logic +echo "Base content:" +echo "$BASE_CONTENT" +echo "" +echo "Current content:" +echo "$CURRENT_CONTENT" +echo "" + +# Compare +if [ "$BASE_CONTENT" = "$CURRENT_CONTENT" ]; then + echo "Result: No changes detected (WRONG - this is the bug)" +else + echo "Result: Changes detected (CORRECT)" +fi + +# Cleanup +rm -f $TEST_CHANGELOG + +echo "Test complete!"