@@ -143,9 +143,65 @@ jobs:
143143 id : check-changes
144144 run : |
145145 # Check if there are any changes that require versioning
146- CHANGED_PACKAGES=$(melos list --since=HEAD~1 --json | jq -r '.[].name' | wc -l)
146+ echo "🔍 Checking for changes requiring versioning..."
147+
148+ # Try different strategies to detect changes
149+ CHANGED_PACKAGES=0
150+
151+ # Strategy 1: Check against last tag (for normal releases)
152+ LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
153+ if [ -n "$LAST_TAG" ]; then
154+ echo "📌 Last tag found: $LAST_TAG"
155+ CHANGED_PACKAGES=$(melos list --since="$LAST_TAG" --json 2>/dev/null | jq -r '.[].name' | wc -l || echo "0")
156+ echo "📦 Found $CHANGED_PACKAGES packages with changes since $LAST_TAG"
157+ fi
158+
159+ # Strategy 2: If no changes found or no tags, check against develop branch merge base
160+ if [ "$CHANGED_PACKAGES" -eq 0 ]; then
161+ echo "🔄 No changes found with tags, trying merge-base with develop..."
162+ MERGE_BASE=$(git merge-base HEAD origin/develop 2>/dev/null || echo "")
163+ if [ -n "$MERGE_BASE" ] && [ "$MERGE_BASE" != "$(git rev-parse HEAD)" ]; then
164+ echo "🔗 Merge base with develop: $MERGE_BASE"
165+ CHANGED_PACKAGES=$(melos list --since="$MERGE_BASE" --json 2>/dev/null | jq -r '.[].name' | wc -l || echo "0")
166+ echo "📦 Found $CHANGED_PACKAGES packages with changes since merge base"
167+ fi
168+ fi
169+
170+ # Strategy 3: If still no changes, check if this is first release (no previous packages published)
171+ if [ "$CHANGED_PACKAGES" -eq 0 ]; then
172+ echo "🆕 Checking if this is a first release..."
173+ # Count all packages (for first release, we want to publish everything)
174+ ALL_PACKAGES=$(melos list --json 2>/dev/null | jq -r '.[].name' | wc -l || echo "0")
175+
176+ # Check if any packages exist - if yes, this might be first release
177+ if [ "$ALL_PACKAGES" -gt 0 ]; then
178+ echo "📦 Found $ALL_PACKAGES total packages"
179+ # Check if we have any git tags at all
180+ TAG_COUNT=$(git tag -l | wc -l || echo "0")
181+ if [ "$TAG_COUNT" -eq 0 ]; then
182+ echo "🎉 No previous tags found - treating as first release"
183+ CHANGED_PACKAGES=$ALL_PACKAGES
184+ else
185+ echo "🔍 Tags exist but no changes detected - checking HEAD~1 as fallback"
186+ CHANGED_PACKAGES=$(melos list --since=HEAD~1 --json 2>/dev/null | jq -r '.[].name' | wc -l || echo "0")
187+ fi
188+ fi
189+ fi
190+
147191 echo "changed_packages=$CHANGED_PACKAGES" >> $GITHUB_OUTPUT
148- echo "📦 Found $CHANGED_PACKAGES packages with changes"
192+ echo "✅ Final result: $CHANGED_PACKAGES packages with changes"
193+
194+ # Debug: List the changed packages if any
195+ if [ "$CHANGED_PACKAGES" -gt 0 ]; then
196+ echo "📋 Changed packages:"
197+ if [ -n "$LAST_TAG" ]; then
198+ melos list --since="$LAST_TAG" --long 2>/dev/null || echo "Unable to list changed packages"
199+ elif [ -n "$MERGE_BASE" ] && [ "$MERGE_BASE" != "$(git rev-parse HEAD)" ]; then
200+ melos list --since="$MERGE_BASE" --long 2>/dev/null || echo "Unable to list changed packages"
201+ else
202+ melos list --long 2>/dev/null || echo "Unable to list packages"
203+ fi
204+ fi
149205
150206 - name : 🔄 Version packages
151207 if : steps.check-changes.outputs.changed_packages > 0
0 commit comments