Created
January 19, 2024 16:50
-
-
Save krisahil/ac10a935c22f36a23dba385aa859ca61 to your computer and use it in GitHub Desktop.
Convert "composer diff" output to CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Converts the JSON from `composer diff` to CSV rows, filtered for only | |
# Drupal-related projects. | |
# Here's what this script does, line by line: | |
# 1) Runs `composer diff` for the current code against latest `develop` branch. | |
# 2) Skips the first line, because I can't figure out how to suppress it (on my | |
# local, the line is: `ComposerInContainer\Composer\ScriptHandler::preInstallUpdateCommand`. | |
# 3) Grabs the `packages` list, which is the prod packages list. Converts each | |
# item in the list from an object to an array. (This is the first `jq` | |
# incantation.) | |
# 4) Bundles this list of objects into an array of objects. Thanks to | |
# https://stackoverflow.com/a/74190661. | |
# 5) More `jq` magic. I won't even try to explain this one. See | |
# https://stackoverflow.com/a/32965227. | |
# 6) Includes only Drupal and DXP packages. | |
fin composer diff origin/develop HEAD --format=json \ | |
| tail -n +2 \ | |
| jq '.packages | to_entries[] | [.value] | .[]' \ | |
| jq -s '.' \ | |
| jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv' \ | |
| grep 'drupal\|dxp' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment