From b48c4bde0859782e7892e6861e698d81ce15c0cc Mon Sep 17 00:00:00 2001 From: DerekCrannaford <43056286+DerekCrannaford@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:15:44 +1000 Subject: [PATCH] Actioning quick pair review --- .github/workflows/playwright.yml | 13 +++++--- test/docker_run_tests.sh | 52 ++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 54f4b51..79712a2 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -117,9 +117,12 @@ jobs: done # Pre-requisites Prepare Cmfive Environment - - name: Setup cmfive Test Environment - run: | - docker exec -t cmfive sh -c "chmod -R ugo=rwX /var/www/html*" + + # Tests will assume playwright code is executable + # we should rely on deployment methods already to have provisioned: + # - name: Setup cmfive Test Environment + # run: | + # docker exec -t cmfive sh -c "chmod -R ugo=rwX /var/www/html*" - name: Inject configs into cmfive Test Environment run: | @@ -145,7 +148,7 @@ jobs: - name: Run Unit and Playwright tests run: | - test/docker_run_tests.sh + sh test/docker_run_tests.sh --cosine_container cmfive - name: Get container logs if: ${{ failure() }} || ${{ success() }} @@ -166,7 +169,7 @@ jobs: if: ${{ failure() }} || ${{ success() }} uses: actions/upload-artifact@v4 with: - name: test-output-${{matrix.node_version}} + name: test-output path: | boilerplate/storage/log/ boilerplate/test/playwright/test-results/ diff --git a/test/docker_run_tests.sh b/test/docker_run_tests.sh index 6e069c4..e262734 100644 --- a/test/docker_run_tests.sh +++ b/test/docker_run_tests.sh @@ -9,9 +9,11 @@ set +e # Node version can be specified, WARNING Playwright&Cosine will not be expected to support all node versions! # usage: ./docker_run.sh --fresh # usage: ./docker_run.sh --node_ver 18 +# usage: ./docker_run.sh --cosine_container [default is 'cmfive'] freshen_all="" test_node_version="" +cosine_container="cmfive" while test $# != 0 do @@ -20,21 +22,16 @@ do --node_ver) shift; test_node_version=$1 ;; --) shift; break;; + --cosine_container) + shift; cosine_container=$1 ;; + --) shift; break;; esac shift done # Bootstrap this script in the Playwright container if [ -z "$IS_PLAYWRIGHT_CONTAINER" ]; then - # Explicitly prep DB for testing: - echo "Backup and snaphsot DB with migrations" - docker exec -t cmfive bash -c "DB_HOST=mysql-8 DB_USERNAME=$DB_USERNAME DB_PASSWORD=$DB_PASSWORD DB_DATABASE=$DB_DATABASE DB_PORT=3306 php cmfive.php testDB setup" - DB_SETUP_EXIT_CODE=$? - if [ $DB_SETUP_EXIT_CODE -ne 0 ]; then - echo "Warning: Failed to setup test DB" - exit $DB_SETUP_EXIT_CODE - fi - echo "Success: Setup test DB" + # Get the directory of the script TESTDIR=$(dirname -- "$( readlink -f -- "$0"; )";) @@ -45,7 +42,7 @@ if [ -z "$IS_PLAYWRIGHT_CONTAINER" ]; then PROJECTDIR="$(dirname "$PROJECTDIR")" echo "PROJECTDIR: $PROJECTDIR" echo "TESTDIR: $TESTDIR" - if [ "$PROJECTDIR" == "/" ]; then + if [ "$PROJECTDIR" = "/" ]; then echo "Panic: docker-compose.yml not found, be sure to run this script from the test directory" exit 2 fi @@ -58,8 +55,36 @@ if [ -z "$IS_PLAYWRIGHT_CONTAINER" ]; then docker compose up -d --wait fi + system_is_at=$(readlink -f $PROJECTDIR/system) + echo ">> CONTAINER LABELS (BOILERPLATE) <<" + echo "====================================" + docker inspect --format='{{range $key, $value := .Config.Labels}}{{$key}}={{$value}}{{println}}{{end}}' cmfive + echo ">> CONTAINER LABELS (CORE COMMIT) <<" + echo "====================================" + echo "VENDOR DIRECTORY:" + docker exec -u root $cosine_container sh -c "cd composer/vendor/2pisoftware/cmfive-core && git log -1 --pretty=format:"CORE_HASH=\"%H\"%nCORE_COMMIT_MSG=\"%s\"%nCORE_REF=\"%D\""" + echo "" + if cd $system_is_at/.. ; then + echo "" + echo ">> TESTS ON BRANCH (CORE COMMIT) <<" + echo "====================================" + echo "MOUNTED CORE from $system_is_at: (this is mounted to /system)" + git log -1 --pretty=format:"CORE_HASH=\"%H\"%nCORE_COMMIT_MSG=\"%s\"%nCORE_REF=\"%D\"" + echo "" + fi + + # Explicitly prep DB for testing: + echo "Backup and snaphsot DB with migrations" + docker exec -u cmfive $cosine_container sh -c "DB_HOST=mysql-8 DB_USERNAME=$DB_USERNAME DB_PASSWORD=$DB_PASSWORD DB_DATABASE=$DB_DATABASE DB_PORT=3306 php cmfive.php testDB setup" + DB_SETUP_EXIT_CODE=$? + if [ $DB_SETUP_EXIT_CODE -ne 0 ]; then + echo "Warning: Failed to setup test DB" + exit $DB_SETUP_EXIT_CODE + fi + echo "Success: Setup test DB" + # First, Run Unit Tests - docker exec -u cmfive cmfive sh -c "DB_HOST=mysql-8 DB_USERNAME=$DB_USERNAME DB_PASSWORD=$DB_PASSWORD DB_DATABASE=$DB_DATABASE DB_PORT=3306 php cmfive.php tests unit all; exit \$?" + docker exec -u cmfive $cosine_container sh -c "DB_HOST=mysql-8 DB_USERNAME=$DB_USERNAME DB_PASSWORD=$DB_PASSWORD DB_DATABASE=$DB_DATABASE DB_PORT=3306 php cmfive.php tests unit all; exit \$?" UNIT_TESTS_EXIT_CODE=$? if [ $UNIT_TESTS_EXIT_CODE -ne 0 ]; then echo "Unit tests failed: $UNIT_TESTS_EXIT_CODE" @@ -126,12 +151,13 @@ wait_for_response() { wait_for_response "http://localhost:3000" 60 -chmod -R 755 . +# Tests will assume playwright code is executable +# we should rely on deployment methods already to have provisioned: +# chmod -R 755 . whoami locale date - # if TEST_NODE_VERSION is set, adopt version if [ ! -z $TEST_NODE_VERSION ]; then