Skip to content

Instantly share code, notes, and snippets.

@narqo
Created May 17, 2018 20:09
Show Gist options
  • Save narqo/eb79dfcb0d0c191c766980928897ce86 to your computer and use it in GitHub Desktop.
Save narqo/eb79dfcb0d0c191c766980928897ce86 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
# Usage:
# > to_deploy.sh <branch> <base_branch>
branch=${1:-HEAD}
base=${2:-"origin/master"}
declare -r mains=$(go list -json ./... | jq --compact-output '. | select(.Name == "main") | {ImportPath: .ImportPath, Deps: .Deps}')
declare -r changed=($(git diff --name-only ${base}...${branch} \
| grep -v '_test.go$' \
| grep '.go$' \
| xargs -I % dirname % \
| sort -u \
))
to_deploy=()
for pkg in ${changed[@]}; do
to_deploy+=($(echo "$mains" | jq --raw-output ". | select(.Deps[] | endswith(\"$pkg\")) | .ImportPath"))
done
echo ${to_deploy[@]} | tr ' ' '\n' | sort -u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment