Skip to content

Commit

Permalink
Fixes and improvements
Browse files Browse the repository at this point in the history
- update github checkout action;
- fail on errors in pipes;
- get rid of 'xargs -I {}' to improve compatibility with non-Linux
  systems;
- fix bugs in git commands;
- rework '--keep-going' logic;
- add set_version_by_name and set_version_by_url commands
  • Loading branch information
asherikov committed May 2, 2024
1 parent 4f1b3af commit 7e62899
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
ubuntu20:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: ./install.sh tests
- run: make test

ubuntu22:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: ./install.sh tests
- run: make test
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ test: shellcheck
@${MAKE} wrap_test TEST=test_update TYPE=rosinstall
@${MAKE} wrap_test TEST=test_scrape TYPE=rosinstall
@${MAKE} wrap_test TEST=test_merge TYPE=rosinstall
@${MAKE} wrap_test TEST=test_set_version TYPE=rosinstall
@${MAKE} wrap_test TEST=test_update TYPE=repos
@${MAKE} wrap_test TEST=test_scrape TYPE=repos
@${MAKE} wrap_test TEST=test_merge TYPE=repos
@${MAKE} wrap_test TEST=test_set_version TYPE=repos

wrap_test:
@echo ""
Expand Down Expand Up @@ -42,6 +44,10 @@ test_merge:
./wshandler -t ${TYPE} -r tests/merge -p replace merge tests/merge_b/.${TYPE}
./wshandler -t ${TYPE} -r tests/merge status

test_set_version:
./wshandler -t ${TYPE} --root tests/update/ set_version_by_url https://github.com/asherikov/qpmad.git master
./wshandler -t ${TYPE} --root tests/update/ set_version_by_name qpmad_tag 1.3.0

shellcheck:
shellcheck ./wshandler
shellcheck ./install.sh
13 changes: 4 additions & 9 deletions tests/update/.repos
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ repositories:
staticoma:
type: git
url: https://github.com/asherikov/staticoma.git

staticoma_master:
type: git
url: https://github.com/asherikov/staticoma.git
version: master

staticoma_commit:
type: git
url: https://github.com/asherikov/staticoma.git
version: 4c7e4e2128a663b8e269ee000b9665762532d0e6

qpmad_tag:
type: git
url: https://github.com/asherikov/qpmad.git
version: 1.3.0

catkin:
type: git
url: https://github.com/ros-gbp/catkin-release.git
version: release/noetic/catkin/0.8.10-1

qpmad_tag:
type: git
url: https://github.com/asherikov/qpmad.git
version: 1.3.0
13 changes: 4 additions & 9 deletions tests/update/.rosinstall
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
- git:
local-name: staticoma
uri: https://github.com/asherikov/staticoma.git

- git:
local-name: staticoma_master
uri: https://github.com/asherikov/staticoma.git
version: master

- git:
local-name: staticoma_commit
uri: https://github.com/asherikov/staticoma.git
version: 4c7e4e2128a663b8e269ee000b9665762532d0e6

- git:
local-name: qpmad_tag
uri: https://github.com/asherikov/qpmad.git
version: 1.3.0

- git:
local-name: catkin
uri: https://github.com/ros-gbp/catkin-release.git
version: release/noetic/catkin/0.8.10-1

- git:
local-name: qpmad_tag
uri: https://github.com/asherikov/qpmad.git
version: 1.3.0
69 changes: 59 additions & 10 deletions wshandler
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
# shellcheck disable=SC2317

set -e
set -o pipefail


help()
Expand All @@ -22,6 +24,8 @@ help()
echo " [-j|--jobs <NUM_THREADS> {1}] clean"
echo " [-p|--policy {ask}|add|show] scrape"
echo " add git <NAME> <URL> <VERSION>"
echo " set_version_by_url <URL> <VERSION>"
echo " set_version_by_name <NAME> <VERSION>"
echo " remove <NAME>"
echo " [-p|--policy keep|replace] merge <FILENAME>"
exit "${EXIT_CODE}"
Expand Down Expand Up @@ -60,7 +64,7 @@ git_status()
{
echo "name|version (actual)|repository";
echo "----|----------------|----------";
"${WSH_WORKSPACE_TYPE}_git_repo_triplets" | "${WSH_XARGS[@]}" sh -c "${WSHANDLER} dir_git_status {}";
"${WSH_WORKSPACE_TYPE}_git_repo_triplets" | while read -r -a TRIPLET; do "${WSHANDLER[@]}" dir_git_status "${TRIPLET[@]}"; done
} | column -t -s '|'

echo
Expand All @@ -71,17 +75,17 @@ git_status()

git_update()
{
"${WSH_WORKSPACE_TYPE}_git_repo_triplets" | "${WSH_XARGS[@]}" --max-procs="${WSH_JOBS}" sh -c "${WSHANDLER} dir_git_update {} ${WSH_COMMAND_SUFFIX}"
"${WSH_WORKSPACE_TYPE}_git_repo_triplets" | "${WSH_XARGS[@]}" "${WSHANDLER[@]}" dir_git_update
}

git_clean()
{
"${WSH_WORKSPACE_TYPE}_git_repo_names" | "${WSH_XARGS[@]}" --max-procs="${WSH_JOBS}" rm -rf "${WSH_WORKSPACE_ROOT}/{}"
"${WSH_WORKSPACE_TYPE}_git_repo_names" | while read -r NAME; do rm -rf "${WSH_WORKSPACE_ROOT:?}/${NAME}"; done
}

git_scrape()
{
GIT_DIRS=$(find "${WSH_WORKSPACE_ROOT}" -type d -name ".git" -printf "%P\n" | sed "s=/.git==g" | sort)
GIT_DIRS=$(find "${WSH_WORKSPACE_ROOT}" -type d -name ".git" | while read -r DIR; do basename "$(dirname "${DIR}")"; done | sort)
UKNOWN_GIT_DIRS=$(comm -2 -3 <(echo "${GIT_DIRS}" | tr ' ' '\n') <("${WSH_WORKSPACE_TYPE}_git_repo_names" | sort))

for GIT_DIR in ${UKNOWN_GIT_DIRS}
Expand Down Expand Up @@ -139,7 +143,7 @@ dir_git_status()
then
cd "${GIT_DIR}"
# git status --porcelain | awk '{print $1}' | sort | uniq | tr -d '\n'
GIT_ACTUAL_VERSION=$(git describe --dirty --broken --all --long | tr -d '\n')
GIT_ACTUAL_VERSION=$(git describe --dirty --broken --all --long --always | tr -d '\n')
fi

echo "${NAME}|${GIT_VERSION} (${GIT_ACTUAL_VERSION})|${GIT_REPO}"
Expand All @@ -163,7 +167,8 @@ dir_git_update()
then
git checkout "${GIT_VERSION}"
fi
if ! (git show-ref --tags "${GIT_VERSION}" --quiet)
# if we are on a branch make sure that it is updated
if (git branch --show-current | grep "${GIT_VERSION}")
then
git pull
fi
Expand Down Expand Up @@ -220,7 +225,11 @@ check_workspace()
esac
fi

WSHANDLER="\"$(realpath "${BASH_SOURCE[0]}")\" -r \"${WSH_WORKSPACE_ROOT}\" -c \"${WSH_CACHE_DIR}\" -t \"${WSH_WORKSPACE_TYPE}\""
WSHANDLER=("$(realpath "${BASH_SOURCE[0]}")" -r "${WSH_WORKSPACE_ROOT}" -c "${WSH_CACHE_DIR}" -t "${WSH_WORKSPACE_TYPE}")
if [ -n "${WSH_KEEP_GOING}" ]
then
WSHANDLER+=("${WSH_KEEP_GOING}")
fi
}


Expand Down Expand Up @@ -316,14 +325,40 @@ execute_add()
"${WSH_WORKSPACE_TYPE}_$1_add" "$@"
}

set_version()
{
TARGET_MATCH="$2"
TARGET_VERSION="$3"

case $1 in
set_version_by_url) TYPE=REPO;;
set_version_by_name) TYPE=NAME;;
*) help 1;;
esac

for SOURCE_TYPE in ${WSH_SOURCE_TYPES}
do
"${WSH_WORKSPACE_TYPE}_${SOURCE_TYPE}_repo_triplets" \
| while read -r NAME REPO VERSION; \
do \
if [ "${TARGET_MATCH}" = "${!TYPE}" ];\
then \
echo "${NAME}: changing '${VERSION}' to '${TARGET_VERSION}'"; \
"${WSHANDLER[@]}" add "${SOURCE_TYPE}" "${NAME}" "${REPO}" "${TARGET_VERSION}"; \
exit; \
fi; \
done
done
}



WSH_SOURCE_TYPES="git"
WSH_COMMAND_POLICY=default
WSH_JOBS=1
WSH_INDENT=4
WSH_XARGS=(xargs --no-run-if-empty -I {})
WSH_COMMAND_SUFFIX=""
WSH_XARGS=(xargs --no-run-if-empty -L 1 --max-procs="${WSH_JOBS}")
WSH_KEEP_GOING=""
WSH_YQ_BINARY="yq"

while [[ $# -gt 0 ]]
Expand Down Expand Up @@ -358,7 +393,7 @@ do
shift; shift;;

-k|--keep-going)
WSH_COMMAND_SUFFIX="|| true"
WSH_KEEP_GOING="-k"
shift;;

status|update|clean|scrape)
Expand All @@ -371,6 +406,20 @@ do
"execute_$1" "${@:2}"
exit;;

set_version_by_url|set_version_by_name)
check_workspace "$1"
set_version "$1" "${@:2}"
exit;;

dir_*_update)
if [ -n "${WSH_KEEP_GOING}" ]
then
"$1" "${@:2}" || true
else
"$1" "${@:2}"
fi
exit;;

dir_*)
"$1" "${@:2}"
exit;;
Expand Down

0 comments on commit 7e62899

Please sign in to comment.