Fixed helper and default setup executed successfully

This commit is contained in:
Nikola Jokic 2023-12-07 12:54:26 +01:00
parent a9b60e4565
commit 416c9942f1
No known key found for this signature in database
GPG Key ID: 1115F751E6A09850
3 changed files with 37 additions and 15 deletions

View File

@ -35,9 +35,30 @@ function env_test() {
fi fi
} }
function usage() {
echo "Usage: $0 [test_name]"
echo " test_name: the name of the test to run"
echo " if not specified, all tests will be run"
echo " test_name should be the name of the test file without the .test.sh suffix"
echo ""
exit 1
}
function main() { function main() {
local failed=() local failed=()
env_test
if [[ -z "${1}" ]]; then
echo "Running all tests"
set_targets
elif [[ -f "${TEST_DIR}/${1}.test.sh" ]]; then
echo "Running test ${1}"
TARGETS=("${1}.test.sh")
else
usage
fi
for target in "${TARGETS[@]}"; do for target in "${TARGETS[@]}"; do
echo "============================================================" echo "============================================================"
test="${TEST_DIR}/${target}" test="${TEST_DIR}/${target}"
@ -68,8 +89,4 @@ function main() {
fi fi
} }
set_targets main $@
env_test
main

View File

@ -61,7 +61,7 @@ function main() {
install_arc install_arc
install_scale_set || failed+=("install_scale_set") install_scale_set || failed+=("install_scale_set")
run_workflow || failed+=("run_workflow") WORKFLOW_FILE="${WORKFLOW_FILE}" SCALE_SET_NAME="${SCALE_SET_NAME}" run_workflow || failed+=("run_workflow")
INSTALLATION_NAME="${SCALE_SET_NAME}" NAMESPACE="${SCALE_SET_NAMESPACE}" cleanup_scale_set || failed+=("cleanup_scale_set") INSTALLATION_NAME="${SCALE_SET_NAME}" NAMESPACE="${SCALE_SET_NAMESPACE}" cleanup_scale_set || failed+=("cleanup_scale_set")
delete_cluster delete_cluster

View File

@ -99,7 +99,7 @@ function wait_for_scale_set() {
function cleanup_scale_set() { function cleanup_scale_set() {
helm uninstall "${INSTALLATION_NAME}" --namespace "${NAMESPACE}" --debug helm uninstall "${INSTALLATION_NAME}" --namespace "${NAMESPACE}" --debug
kubectl wait --timeout=10s --for=delete AutoScalingRunnerSet -n "${NAMESPACE}" -l app.kubernetes.io/instance="${INSTALLATION_NAME}" --ignore-not-found kubectl wait --timeout=10s --for=delete AutoScalingRunnerSet -n "${NAMESPACE}" -l app.kubernetes.io/instance="${INSTALLATION_NAME}"
} }
function install_openebs() { function install_openebs() {
@ -127,12 +127,9 @@ function print_results() {
function run_workflow() { function run_workflow() {
echo "Checking if the workflow file exists" echo "Checking if the workflow file exists"
gh workflow view -R "${TARGET_ORG}/${TARGET_REPO}" "${workflow_file}" || return 1 gh workflow view -R "${TARGET_ORG}/${TARGET_REPO}" "${WORKFLOW_FILE}" || return 1
echo "Getting run count before a new run" local queue_time="$(date -u +%FT%TZ)"
local target_run_count=$(($(gh run list -R "${TARGET_ORG}/${TARGET_REPO}" --workflow "${WORKFLOW_FILE}" --limit 1 --jq '. | length') + 1))
local queue_time=$(date +%FT%TZ)
echo "Running workflow ${workflow_file}" echo "Running workflow ${workflow_file}"
gh workflow run -R "${TARGET_ORG}/${TARGET_REPO}" "${WORKFLOW_FILE}" --ref main -f arc_name="${SCALE_SET_NAME}" || return 1 gh workflow run -R "${TARGET_ORG}/${TARGET_REPO}" "${WORKFLOW_FILE}" --ref main -f arc_name="${SCALE_SET_NAME}" || return 1
@ -145,16 +142,24 @@ function run_workflow() {
echo "Timeout waiting for run to start" echo "Timeout waiting for run to start"
return 1 return 1
fi fi
run_id=$(gh run list -R "${TARGET_ORG}/${TARGET_REPO}" --workflow "${WORKFLOW_FILE}" --created ">${queue_time}" --json "name,databaseId" --jq ".[] | select(.name | contains(\"${SCALE_SET_NAME}\")) | .databaseId")
run_id=$(gh run list -R "${TARGET_ORG}/${TARGET_REPO} --workflow ${WORKFLOW_FILE} --created ">${queue_time}" --json name,databaseId --jq '.[] | select(.name | contains("${SCALE_SET_NAME}"))'") echo "Run ID: ${run_id}"
if [ -n "$run_id" ]; then if [ -n "$run_id" ]; then
echo "Run found: $run_id" echo "Run found: $run_id"
break break
fi fi
echo "Run not found yet, waiting 5 seconds"
sleep 5 sleep 5
count=$((count+1)) count=$((count+1))
done done
echo "Waiting for run to complete" echo "Waiting for run to complete"
gh run watch "${run_id}" -R "${TARGET_ORG}/${TARGET_REPO}" --exit-status local code=$(gh run watch "${run_id}" -R "${TARGET_ORG}/${TARGET_REPO}" --exit-status)
if [[ "${code}" -ne 0 ]]; then
echo "Run failed with exit code ${code}"
return 1
fi
echo "Run completed successfully"
} }