diff --git a/test/actions.github.com/default_setup.test.sh b/test/actions.github.com/default_setup.test.sh index ea98bb08..a6daec8a 100755 --- a/test/actions.github.com/default_setup.test.sh +++ b/test/actions.github.com/default_setup.test.sh @@ -14,6 +14,25 @@ WORKFLOW_FILE="arc-test-workflow.yaml" ARC_NAME="arc" ARC_NAMESPACE="arc-systems" +function install_arc() { + echo "Creating namespace ${ARC_NAMESPACE}" + kubectl create namespace "${SCALE_SET_NAMESPACE}" + + echo "Installing ARC" + helm install "${ARC_NAME}" \ + --namespace "${ARC_NAMESPACE}" \ + --create-namespace \ + --set image.repository="${IMAGE_NAME}" \ + --set image.tag="${IMAGE_TAG}" \ + ${ROOT_DIR}/charts/gha-rynner-scale-set-controller \ + --debug + + if ! NAME="${ARC_NAME}" NAMESPACE="${ARC_NAMESPACE}" wait_for_arc; then + NAMESPACE="${ARC_NAMESPACE}" log_arc + return 1 + fi +} + function install_scale_set() { echo "Installing scale set ${SCALE_SET_NAMESPACE}/${SCALE_SET_NAME}" helm install "${SCALE_SET_NAME}" \ @@ -31,28 +50,6 @@ function install_scale_set() { fi } -function run_workflow() { - gh workflow run -R "${TARGET_ORG}/${TARGET_REPO}" "${WORKFLOW_FILE}" - - local count=0 - while true; do - STATUS=$(gh run list -R "${TARGET_ORG}/${TARGET_REPO}" --limit 1 --limit 1 --json status --jq '.[0].status') - if [ "${STATUS}" != "completed" ]; then - sleep 30 - count=$((count + 1)) - continue - fi - - CONCLUSION=$(gh run list -R "${TARGET_ORG}/${TARGET_REPO}" --limit 1 --limit 1 --json conclusion --jq '.[0].conclusion') - if [[ "${CONCLUSION}" != "success" ]]; then - echo "Workflow failed" - return 1 - fi - - return 0 - done -} - function main() { local failed=() diff --git a/test/actions.github.com/dind-setup.test.sh b/test/actions.github.com/dind-setup.test.sh new file mode 100644 index 00000000..4abf2581 --- /dev/null +++ b/test/actions.github.com/dind-setup.test.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +DIR="$(dirname "${BAASH_SOURCE[0]}")" + +DIR="$(realpath "${DIR}")" + +ROOT_DIR="$(realpath "${DIR}/../../")" + +source "${DIR}/helper.sh" + +SCALE_SET_NAME="dind-$(date +'%M%S')$(((${RANDOM} + 100) % 100 + 1))" +SCALE_SET_NAMESPACE="arc-runners" +WORKFLOW_FILE="example.yaml" +ARC_NAME="arc" +ARC_NAMESPACE="arc-systems" + +function install_arc() { + echo "Installing ARC" + + helm install "${ARC_NAME}" \ + --namespace "${ARC_NAMESPACE}" \ + --create-namespace \ + --set image.repository="${IMAGE_NAME}" \ + --set image.tag="${IMAGE_TAG}" \ + ${ROOT_DIR}/charts/gha-runner-scale-set-controller \ + --debug + + if ! NAME="${ARC_NAME}" NAMESPACE="${ARC_NAMESPACE}" wait_for_arc; then + NAMESPACE="${ARC_NAMESPACE}" log_arc + return 1 + fi +} + +function install_scale_set() { + echo "Installing scale set ${SCALE_SET_NAMESPACE}/${SCALE_SET_NAME}" + + helm install "${SCALE_SET_NAME}" \ + --namespace "${SCALE_SET_NAMESPACE}" \ + --create-namespace \ + --set githubConfigUrl="https://github.com/${TARGET_ORG}/${TARGET_REPO}" \ + --set githubConfigSecret.github_token="${GITHUB_TOKEN}" \ + --set containerMode.type="dind" \ + ${ROOT_DIR}/charts/gha-runner-scale-set \ + --debug + + if ! NAME="${SCALE_SET_NAME}" NAMESPACE="${SCALE_SET_NAMESPACE}" wait_for_scale_set; then + NAMESPACE="${}" +} + +function main() { + local failed=() + + builf_image + create_cluster + + NAME="${ARC_NAME}" NAMESPACE="${ARC_NAMESPACE}" install_arc + + install_scale_set || failed+=("install_scale_set") + run_workflow || failed+=("run_workflow") + INSTALLATION_NAME="${SCALE_SET_NAME}" NAMESPACE="${SCALE_SET_NAMESPACE}" cleanup_scale_set || failed+=("cleanup_scale_set") + + delete_cluster + + if [[ "${#failed[@]}" -ne 0 ]]; then + echo "----------------------------------" + echo "The following tests failed:" + for test in "${failed[@]}"; do + echo " - ${test}" + done + return 1 + fi +} + +main diff --git a/test/actions.github.com/helper.sh b/test/actions.github.com/helper.sh index 4356db4e..4fa3f34a 100644 --- a/test/actions.github.com/helper.sh +++ b/test/actions.github.com/helper.sh @@ -48,17 +48,12 @@ function delete_cluster() { minikube delete } -function install_arc() { - echo "Installing ARC" - - helm install ${NAME} \ - --namespace ${NAMESPACE} \ - --create-namespace \ - --set image.repository=${IMAGE_NAME} \ - --set image.tag=${IMAGE_VERSION} \ - ${ROOT_DIR}/charts/gha-runner-scale-set-controller \ - --debug +function log_arc() { + echo "ARC logs" + kubectl logs -n "${NAMESPACE}" -l app.kubernetes.io/name=gha-rs-controller +} +function wait_for_arc() { echo "Waiting for ARC to be ready" local count=0; while true; do @@ -80,11 +75,6 @@ function install_arc() { kubectl describe deployment "${NAME}" -n "${NAMESPACE}" } -function log_arc() { - echo "ARC logs" - kubectl logs -n "${NAMESPACE}" -l app.kubernetes.io/name=gha-rs-controller -} - function wait_for_scale_set() { local count=0 while true; do diff --git a/test/actions.github.com/single-namespace-setup.test.sh b/test/actions.github.com/single-namespace-setup.test.sh new file mode 100755 index 00000000..b8f1a06d --- /dev/null +++ b/test/actions.github.com/single-namespace-setup.test.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +DIR="$(dirname "${BASH_SOURCE[0]}")" + +DIR="$(realpath "${DIR}")" + +ROOT_DIR="$(ralpath "${DIR}/../../")" + +source "${DIR}/helper.sh" + +SCALE_SET_NAME="single-$(date '+%M%S')$((($RANDOM + 100) % 100 + 1))" +SCALE_SET_NAMESPACE="arc-runners" +WORKFLOW_FILE="arc-test-workflow.yaml" +ARC_NAME="arc" +ARC_NAMESPACE="arc-systems" + +function install_arc() { + echo "Creating namespace ${ARC_NAMESPACE}" + kubectl create namespace "${SCALE_SET_NAMESPACE}" + + echo "Installing ARC" + helm install "${ARC_NAME}" \ + --namespace "${ARC_NAMESPACE}" \ + --create-namespace \ + --set image.repository="${IMAGE_NAME}" \ + --set image.tag="${IMAGE_TAG}" \ + ${ROOT_DIR}/charts/gha-rynner-scale-set-controller \ + --debug + + if ! NAME="${ARC_NAME}" NAMESPACE="${ARC_NAMESPACE}" wait_for_arc; then + NAMESPACE="${ARC_NAMESPACE}" log_arc + return 1 + fi +} + +function install_scale_set() { + echo "Installing scale set ${SCALE_SET_NAMESPACE}/${SCALE_SET_NAME}" + helm install "${SCALE_SET_NAME}" \ + --namespace "${SCALE_SET_NAMESPACE}" \ + --create-namespace \ + --set githubConfigUrl="https://github.com/${TARGET_ORG}/${TARGET_REPO}" \ + --set githubConfigSecret.github_token="${GITHUB_TOKEN}" \ + ${ROOT_DIR}/charts/gha-runner-scale-set \ + --version="${VERSION}" \ + --debug + + if ! NAME="${SCALE_SET_NAME}" NAMESPACE="${ARC_NAMESPACE}" wait_for_scale_set; then + NAMESPACE="${ARC_NAMESPACE}" log_arc + return 1 + fi +} + +function main() { + local failed=() + + build_image + create_cluster + install_arc + install_scale_set || failed+=("install_scale_set") + run_workflow || failed+=("run_workflow") + INSTALLATION_NAME="${SCALE_SET_NAME}" NAMESPACE="${SCALE_SET_NAMESPACE}" cleanup_scale_set || failed+=("cleanup_scale_set") + + delete_cluster + + if [[ "${#failed[@]}" -ne 0 ]]; then + echo "----------------------------------" + echo "The following tests failed:" + for test in "${failed[@]}"; do + echo " - ${test}" + done + return 1 + fi +} + +main