
# Check if we are pushing a tag
while read local_ref local_sha remote_ref remote_sha
do
  if [[ "$remote_ref" == refs/tags/v* ]]; then
    TAG=${remote_ref#refs/tags/}
    echo "🏷️ Tag detected: $TAG, syncing versions..."
    pnpm sync-versions "$TAG"
    
    # Stage the changed files (excluding ignored files like .env)
    git add package.json packages/*/package.json apps/*/package.json .env.example
    
    echo "⚠️ package.json and .env files updated to match tag $TAG."
    echo "⚠️ Note: You might need to push again if these changes were not already in your commit/tag."
  fi
done
