Created
August 3, 2018 21:33
-
-
Save dvejmz/74c42346e6ee67830bb8b0cbb18e2794 to your computer and use it in GitHub Desktop.
Get the latest tag for every git repo in a directory
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 | |
function is_git_repo() { | |
ls .git &> /dev/null | |
} | |
function get_latest_tag_for_repo() { | |
pushd ${1} &> /dev/null | |
is_git_repo | |
local is_git_repo=$? | |
if [[ ${is_git_repo} != 0 ]]; then | |
popd &> /dev/null | |
return 0 | |
fi | |
echo "$(basename ${1}) $(git describe --tags --always)" | |
popd &> /dev/null | |
} | |
export -f get_latest_tag_for_repo is_git_repo | |
REPOS_PATH="${REPOS_PATH:=./}" | |
# Check if GNU parallell is installed | |
command -v parallel &> /dev/null | |
HAS_GNU_PARALLEL_RC=$? | |
# Pull all repos under the directory simultaneously | |
if [[ ${HAS_GNU_PARALLEL_RC} == 0 ]]; then | |
ls -d ${REPOS_PATH}/*/ | parallel get_latest_tag_for_repo | |
else | |
for dir in $(ls -d ${REPOS_PATH}/*/); do | |
(get_latest_tag_for_repo ${dir}) & | |
done | |
# Wait for all jobs to complete | |
while [[ ! -z $(jobs -r) ]]; do | |
sleep 1 | |
done | |
fi | |
echo "Done." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment