Last active
June 15, 2024 00:34
-
-
Save bukowa/f2346d23a7b87f179756471d3bf9472e to your computer and use it in GitHub Desktop.
grab github changed files to json array with jq
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 -l | |
set -euxo pipefail | |
# Source first argument if it exists | |
if [ -n "${1-}" ]; then | |
set -o allexport | |
source "$1" | |
set +o allexport | |
fi | |
# Build json array of untracked and tracked files | |
GIT_UNTRACKED_CHANGES=$(git ls-files --others --exclude-standard | jq -R -s -c 'split("\n")[:-1]') | |
GIT_TRACKED_CHANGES=$(git diff --name-only | jq -R -s -c 'split("\n")[:-1]') | |
# Group the untracked and tracked files | |
GIT_CHANGED_FILES=$(echo "$GIT_UNTRACKED_CHANGES" "$GIT_TRACKED_CHANGES" | jq -s -c 'add | unique') | |
# Check if the changelog file has changed | |
GIT_HAS_CHANGELOG_CHANGED=$(echo $GIT_CHANGED_FILES | jq -r --arg target "$GIT_CLIFF_OUTPUT" '.[] | select(. == $target)') | |
# Exit if no changes are detected | |
if [ -z "$GIT_HAS_CHANGELOG_CHANGED" ]; then | |
echo "No changes detected after generating the changelog." | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment