Skip to content

Commit f3839dc

Browse files
committed
chore: enhance update summary for dependency changes and improve change detection logic
1 parent 7dc68b5 commit f3839dc

File tree

1 file changed

+55
-44
lines changed

1 file changed

+55
-44
lines changed

.github/workflows/update-booster-dependencies.yml

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -206,72 +206,83 @@ jobs:
206206
echo "" >> update-summary.md
207207
208208
# Node.js changes
209-
CURRENT_NODE=$(git diff HEAD booster/.ddev/config.yaml | grep -A1 "^-nodejs_version" | tail -1 | sed 's/.*"\(.*\)"/\1/' || echo "")
210-
NEW_NODE="${{ steps.node-version.outputs.latest }}"
211-
if [ -n "$CURRENT_NODE" ] && [ "$CURRENT_NODE" != "$NEW_NODE" ]; then
209+
if git diff --quiet HEAD booster/.ddev/config.yaml; then
210+
NODE_CHANGED=false
211+
else
212+
NODE_CHANGED=true
213+
CURRENT_NODE=$(git diff HEAD booster/.ddev/config.yaml | grep "^-nodejs_version" | sed 's/.*"\(.*\)".*/\1/')
214+
NEW_NODE="${{ steps.node-version.outputs.latest }}"
212215
echo "### Node.js" >> update-summary.md
213216
echo "- Updated from \`$CURRENT_NODE\` to \`$NEW_NODE\`" >> update-summary.md
214217
echo "- Updated \`@types/node\` to match" >> update-summary.md
215218
echo "" >> update-summary.md
216219
fi
217220
218221
# pnpm changes
219-
if git diff --quiet HEAD booster/package.json; then
220-
:
221-
else
222-
echo "### Package Manager" >> update-summary.md
223-
echo "- Updated pnpm to \`${{ steps.pnpm-version.outputs.latest }}\`" >> update-summary.md
224-
echo "" >> update-summary.md
222+
PNPM_CHANGED=false
223+
if ! git diff --quiet HEAD booster/package.json; then
224+
# Check if packageManager field changed
225+
OLD_PNPM=$(git diff HEAD booster/package.json | grep "^-.*packageManager" | sed 's/.*"pnpm@\([^"]*\)".*/\1/')
226+
NEW_PNPM=$(git diff HEAD booster/package.json | grep "^+.*packageManager" | sed 's/.*"pnpm@\([^"]*\)".*/\1/')
227+
228+
if [ -n "$OLD_PNPM" ] && [ -n "$NEW_PNPM" ] && [ "$OLD_PNPM" != "$NEW_PNPM" ]; then
229+
PNPM_CHANGED=true
230+
echo "### Package Manager" >> update-summary.md
231+
echo "- Updated pnpm from \`$OLD_PNPM\` to \`$NEW_PNPM\`" >> update-summary.md
232+
echo "" >> update-summary.md
233+
fi
225234
fi
226235
227236
# PHP package changes
228237
if [ "${{ steps.php-updates.outputs.has_updates }}" == "true" ]; then
229-
echo "### PHP Packages" >> update-summary.md
230-
231-
# Get current versions from git
232-
git diff HEAD booster/composer.json > /tmp/composer-diff.txt || true
233-
234-
if [ -s /tmp/composer-diff.txt ]; then
235-
# Parse the diff to extract package names and versions
236-
grep '^[+-]' /tmp/composer-diff.txt | grep -v '^[+-][+-][+-]' | grep '"' | while IFS= read -r line; do
237-
if [[ $line =~ \"([^\"]+)\":[[:space:]]*\"([^\"]+)\" ]]; then
238-
PACKAGE="${BASH_REMATCH[1]}"
239-
VERSION="${BASH_REMATCH[2]}"
240-
241-
if [[ $line =~ ^- ]]; then
242-
OLD_VERSION="$VERSION"
243-
elif [[ $line =~ ^+ ]]; then
244-
NEW_VERSION="$VERSION"
245-
if [ -n "$OLD_VERSION" ]; then
246-
echo "- \`$PACKAGE\`: $OLD_VERSION → $NEW_VERSION" >> update-summary.md
247-
OLD_VERSION=""
248-
fi
249-
fi
238+
if ! git diff --quiet HEAD booster/composer.json; then
239+
echo "### PHP Packages" >> update-summary.md
240+
241+
# Parse composer.json diff for package changes
242+
git diff HEAD booster/composer.json | grep -E '^\-[[:space:]]+"[^"]+": "\^' > /tmp/old-packages.txt || true
243+
git diff HEAD booster/composer.json | grep -E '^\+[[:space:]]+"[^"]+": "\^' > /tmp/new-packages.txt || true
244+
245+
# Process each changed package
246+
while IFS= read -r old_line; do
247+
PACKAGE=$(echo "$old_line" | sed -n 's/.*"\([^"]*\)": "\^\([^"]*\)".*/\1/p')
248+
OLD_VER=$(echo "$old_line" | sed -n 's/.*"\([^"]*\)": "\^\([^"]*\)".*/\2/p')
249+
250+
# Find matching new version
251+
NEW_VER=$(grep "\"$PACKAGE\"" /tmp/new-packages.txt | sed -n 's/.*"\^\([^"]*\)".*/\1/p' || echo "")
252+
253+
if [ -n "$NEW_VER" ] && [ "$OLD_VER" != "$NEW_VER" ]; then
254+
echo "- \`$PACKAGE\`: ^$OLD_VER → ^$NEW_VER" >> update-summary.md
250255
fi
251-
done
256+
done < /tmp/old-packages.txt
252257
253-
# If no changes were parsed, check if there are any at all
254-
if ! grep -q "^- \`" update-summary.md 2>/dev/null; then
255-
echo "- Updated to latest versions" >> update-summary.md
256-
fi
257-
echo "" >> update-summary.md
258-
else
259-
echo "- No changes detected" >> update-summary.md
260258
echo "" >> update-summary.md
261259
fi
262260
fi
263261
264262
# NPM package changes
263+
NPM_CHANGED=false
265264
if [ "${{ steps.npm-updates.outputs.has_updates }}" == "true" ]; then
266-
echo "### NPM Packages (package.json)" >> update-summary.md
267-
echo "Updated to latest versions. See \`package.json\` for details." >> update-summary.md
268-
echo "" >> update-summary.md
265+
if ! git diff --quiet HEAD booster/package.json; then
266+
NPM_CHANGED=true
267+
echo "### NPM Packages" >> update-summary.md
268+
echo "Updated devDependencies to latest versions. See \`package.json\` for details." >> update-summary.md
269+
echo "" >> update-summary.md
270+
fi
269271
fi
270272
273+
# Files Changed - only list files that actually changed
271274
echo "### Files Changed" >> update-summary.md
272-
echo "- \`booster/.ddev/config.yaml\` (Node.js version)" >> update-summary.md
273-
echo "- \`booster/package.json\` (pnpm, @types/node, devDependencies)" >> update-summary.md
274-
echo "- \`booster/composer.json\` (PHP package versions)" >> update-summary.md
275+
if [ "$NODE_CHANGED" = true ]; then
276+
echo "- \`booster/.ddev/config.yaml\` (Node.js version)" >> update-summary.md
277+
fi
278+
if [ "$PNPM_CHANGED" = true ] || [ "$NPM_CHANGED" = true ] || [ "$NODE_CHANGED" = true ]; then
279+
echo "- \`booster/package.json\`" >> update-summary.md
280+
fi
281+
if [ "${{ steps.php-updates.outputs.has_updates }}" == "true" ]; then
282+
if ! git diff --quiet HEAD booster/composer.json; then
283+
echo "- \`booster/composer.json\`" >> update-summary.md
284+
fi
285+
fi
275286
276287
cat update-summary.md
277288

0 commit comments

Comments
 (0)