ci: make ci matrix from find-apps.sh

This commit is contained in:
Zaiming (Stone) Shi 2022-11-18 19:06:51 +01:00
parent 3d75a1db3b
commit 06cb7aeb48
1 changed files with 56 additions and 33 deletions

View File

@ -8,25 +8,18 @@ cd -P -- "$(dirname -- "$0")/.."
help() { help() {
echo echo
echo "-h|--help: To display this usage info" echo "-h|--help: To display this usage info"
echo "--ct fast|docker: Print apps which needs docker-compose to run ct" echo "--ci fast|docker: Print apps in json format for github ci mtrix"
echo "--json: Print apps in json"
} }
WANT_JSON='no' CI='fast'
CT='novalue'
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
case $1 in case $1 in
-h|--help) -h|--help)
help help
exit 0 exit 0
;; ;;
--json) --ci)
WANT_JSON='yes' CI="$2"
shift 1
;;
--ct)
CT="$2"
shift 2 shift 2
;; ;;
*) *)
@ -52,27 +45,57 @@ CE="$(find_app 'apps')"
EE="$(find_app 'lib-ee')" EE="$(find_app 'lib-ee')"
APPS_ALL="$(echo -e "${CE}\n${EE}")" APPS_ALL="$(echo -e "${CE}\n${EE}")"
if [ "$CT" = 'novalue' ]; then if [ "$CI" = 'no' ]; then
RESULT="${APPS_ALL}" echo "${APPS_ALL}"
else exit 0
APPS_NORMAL_CT=( )
APPS_DOCKER_CT=( )
for app in ${APPS_ALL}; do
if [ -f "${app}/docker-ct" ]; then
APPS_DOCKER_CT+=("$app")
else
APPS_NORMAL_CT+=("$app")
fi
done
if [ "$CT" = 'docker' ]; then
RESULT="${APPS_DOCKER_CT[*]}"
else
RESULT="${APPS_NORMAL_CT[*]}"
fi
fi fi
if [ "$WANT_JSON" = 'yes' ]; then ##################################################
echo "${RESULT}" | xargs | tr -d '\n' | jq -R -s -c 'split(" ")' ###### now deal with the github action's matrix.
else ##################################################
echo "${RESULT}" | xargs
dimensions() {
app="$1"
if [ -f "${app}/docker-ct" ]; then
if [[ "$CI" != 'docker' ]]; then
return
fi fi
else
if [[ "$CI" != 'fast' ]]; then
return
fi
fi
case "${app}" in
apps/*)
profile='emqx'
;;
lib-ee/*)
profile='emqx-enterprise'
;;
*)
echo "unknown app: $app"
exit 1
;;
esac
echo -n "$app $profile" | jq -R -s -c 'split(" ")'
}
matrix() {
first_row='yes'
for app in ${APPS_ALL}; do
row="$(dimensions "$app")"
if [ -z "$row" ]; then
continue
fi
if [ "$first_row" = 'yes' ]; then
first_row='no'
echo -n "$row"
else
echo -n ",${row}"
fi
done
}
echo -n '['
matrix
echo ']'