Last active
March 16, 2021 13:38
-
-
Save datfinesoul/b75f136041b5ced33ca29c875319b729 to your computer and use it in GitHub Desktop.
Merge a list of keys into a JSON map and clean up old entries
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
[*.bash] | |
indent_style = tab | |
indent_size = 2 | |
[*.{txt,json}] | |
indent_style = space | |
indent_size = 2 |
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
{ | |
"test-app1--main": [ | |
"v2-i50-builder", | |
"v1-i50-builder", | |
"v1-i51-builder" | |
], | |
"test-app2--main": [ | |
"v1-i51-builder" | |
], | |
"someapp--master": [ | |
"v1-i50-builder" | |
], | |
"another--one": [ | |
"v2-i50-builder" | |
] | |
} |
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
#!/usr/bin/env bash | |
tail -n1000 *.json *.txt | |
jq \ | |
--slurpfile manifest ./manifest.json \ | |
--rawfile updates ./updates.txt \ | |
--null-input \ | |
--arg builder "v1-i51-builder" \ | |
--from-file <(cat <<- DOC | |
# remove any entries that match $builder | |
(\$manifest[] | map_values(del(.. | select(. == \$builder)))) as \$current | |
# read the raw file lines into an array and strip empty lines | |
| (\$updates | split("\n") | map(select(.|length > 0)) | |
# create a updates object using the current repo-branches and remaining items | |
| reduce .[] as \$item ({}; {(\$item): (\$current[\$item] + [\$builder])} + .)) as \$override | |
# do an object assign | |
| \$current + \$override | |
# remove empty entries | |
| del(.[] | select(. | length == 0)) | |
DOC | |
) |
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
test-app1--main | |
another--one | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment