From 8ae22787469aff4c50f64881cdd1b2974ceb8852 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Wed, 23 Aug 2023 21:05:10 +0200 Subject: [PATCH 01/26] Add first dummy test --- .github/workflows/tests/bash/dummyTest.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 .github/workflows/tests/bash/dummyTest.sh diff --git a/.github/workflows/tests/bash/dummyTest.sh b/.github/workflows/tests/bash/dummyTest.sh new file mode 100755 index 0000000..58fd6ca --- /dev/null +++ b/.github/workflows/tests/bash/dummyTest.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -x + +#thisCommandAlwaysFails From 897978b161f76cd428ee9160de46cc0d26f442f0 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Wed, 23 Aug 2023 21:07:11 +0200 Subject: [PATCH 02/26] Initial GitHub test conf file --- .github/workflows/tests.yml | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..d8e7e38 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,48 @@ +name: Bash tests + +on: + push: + branches: + - feature/add-testing-base + pull_request: + branches: + - feature/add-testing-base + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + tools: composer + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Show debug information + run: | + php --version + echo "composer.json contents:" + cat composer.json + + - name: Configure git + run: | + git config --global user.email "nobody@example.com" + git config --global user.name "GitHub testing bot" + + - name: Run composer + run: | + composer install --ignore-platform-reqs + composer boilerplate:assistant + + + - name: Run tests + run: | + pwd + .github/workflows/tests/bash/dummyTest.sh + From 02379ff71f9f5c49a4f7474465a4b47a02610604 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Wed, 23 Aug 2023 21:27:36 +0200 Subject: [PATCH 03/26] By default ssh-agent volume is disabled (and enabled makes GitHub actions to fail) --- docker-compose.override.yml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.override.yml.dist b/docker-compose.override.yml.dist index d998410..026a280 100644 --- a/docker-compose.override.yml.dist +++ b/docker-compose.override.yml.dist @@ -17,7 +17,7 @@ services: SSH_AUTH_SOCK: /ssh-agent volumes: - ./:/var/www/html - - $SSH_AUTH_SOCK:/ssh-agent +# - $SSH_AUTH_SOCK:/ssh-agent # crond: # volumes: From edfac8c0b8fdcc4d4974d2020b440e7025a05aaa Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Fri, 25 Aug 2023 16:15:35 +0200 Subject: [PATCH 04/26] TESTS - Show contianers after assistant is run --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d8e7e38..788ef8e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,6 +39,7 @@ jobs: run: | composer install --ignore-platform-reqs composer boilerplate:assistant + docker ps - name: Run tests From af1c6634158a70603453e536f8fd82ec92f7c5f3 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Fri, 25 Aug 2023 16:30:59 +0200 Subject: [PATCH 05/26] TESTS - Add shellspec as testing engine,including a first test --- .github/workflows/tests.yml | 8 +++++-- .shellspec | 15 ++++++++++++ .../basic_files_are_present___spec.sh | 13 ++++++++++ shellspec_spec/spec_helper.sh | 24 +++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 .shellspec create mode 100644 shellspec_spec/basic_files_are_present___spec.sh create mode 100644 shellspec_spec/spec_helper.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 788ef8e..23b36b3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,15 +35,19 @@ jobs: git config --global user.email "nobody@example.com" git config --global user.name "GitHub testing bot" + - name: Donwload shellspec + run: | + wget https://github.com/shellspec/shellspec/releases/download/0.28.1/shellspec-dist.tar.gz + tar xfvz shellspec-dist.tar.gz + - name: Run composer run: | composer install --ignore-platform-reqs composer boilerplate:assistant - docker ps - name: Run tests run: | pwd - .github/workflows/tests/bash/dummyTest.sh + shellspec/shellspec diff --git a/.shellspec b/.shellspec new file mode 100644 index 0000000..e5901ad --- /dev/null +++ b/.shellspec @@ -0,0 +1,15 @@ + +--default-path "shellspec_spec" + +#--require spec_helper + +## Default kcov (coverage) options +# --kcov-options "--include-path=. --path-strip-level=1" +# --kcov-options "--include-pattern=.sh" +# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/" + +## Example: Include script "myprog" with no extension +# --kcov-options "--include-pattern=.sh,myprog" + +## Example: Only specified files/directories +# --kcov-options "--include-pattern=myprog,/lib/" diff --git a/shellspec_spec/basic_files_are_present___spec.sh b/shellspec_spec/basic_files_are_present___spec.sh new file mode 100644 index 0000000..126c4c1 --- /dev/null +++ b/shellspec_spec/basic_files_are_present___spec.sh @@ -0,0 +1,13 @@ +Describe 'Boilerplate folder structure' + It '' + When call ls -la + The output should include 'web' + The output should include 'vendor' + The output should include 'docs' + The output should include 'drush' + The output should include 'composer.json' + The output should include 'behat.yml' + The output should include 'docker-compose.yml' + The output should include "docker-compose.override.yml" + End +End diff --git a/shellspec_spec/spec_helper.sh b/shellspec_spec/spec_helper.sh new file mode 100644 index 0000000..93f1908 --- /dev/null +++ b/shellspec_spec/spec_helper.sh @@ -0,0 +1,24 @@ +# shellcheck shell=sh + +# Defining variables and functions here will affect all specfiles. +# Change shell options inside a function may cause different behavior, +# so it is better to set them here. +# set -eu + +# This callback function will be invoked only once before loading specfiles. +spec_helper_precheck() { + # Available functions: info, warn, error, abort, setenv, unsetenv + # Available variables: VERSION, SHELL_TYPE, SHELL_VERSION + : minimum_version "0.28.1" +} + +# This callback function will be invoked after a specfile has been loaded. +spec_helper_loaded() { + : +} + +# This callback function will be invoked after core modules has been loaded. +spec_helper_configure() { + # Available functions: import, before_each, after_each, before_all, after_all + : import 'support/custom_matcher' +} From 5586dad9ce743e6e8cd0b63b003a59ef7f206171 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Sun, 27 Aug 2023 08:33:44 +0200 Subject: [PATCH 06/26] Improve tests on boilerplate's folder, files and symlinks --- .../basic_files_are_present___spec.sh | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/shellspec_spec/basic_files_are_present___spec.sh b/shellspec_spec/basic_files_are_present___spec.sh index 126c4c1..9725fb6 100644 --- a/shellspec_spec/basic_files_are_present___spec.sh +++ b/shellspec_spec/basic_files_are_present___spec.sh @@ -1,13 +1,38 @@ Describe 'Boilerplate folder structure' - It '' - When call ls -la - The output should include 'web' - The output should include 'vendor' - The output should include 'docs' - The output should include 'drush' - The output should include 'composer.json' - The output should include 'behat.yml' - The output should include 'docker-compose.yml' - The output should include "docker-compose.override.yml" + + It 'has main boilerplate folders' + + The path 'backups' should be directory + The path 'config' should be directory + The path 'docs' should be directory + The path 'drush' should be directory + The path 'patches' should be directory + The path 'private-files' should be directory + The path 'reports' should be directory + The path 'scripts' should be directory + The path 'solr/cores' should be directory + The path 'tests/common' should be directory + The path 'tests/environment' should be directory + The path 'tests/functional' should be directory + The path 'tmp' should be directory + The path 'vendor' should be directory + The path 'web' should be directory End + + It 'has main boilerplate files' + The path 'composer.json' should be file + The path 'behat.yml' should be file + The path 'docker-compose.yml' should be file + The path "docker-compose.override.yml" should be file + The path "web/sites/default/settings.local.php" should be file + End + + It 'has main boilerplate symlinks' + + The path 'public_html' should be symlink + The path 'docroot' should be symlink + End + + + End From 770c59848e9a96d0aa7a5a5b0b22f2f340b32d11 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Sun, 27 Aug 2023 08:55:38 +0200 Subject: [PATCH 07/26] TESTS - Use better and shorter name for test file --- .../{basic_files_are_present___spec.sh => folders___spec.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename shellspec_spec/{basic_files_are_present___spec.sh => folders___spec.sh} (100%) diff --git a/shellspec_spec/basic_files_are_present___spec.sh b/shellspec_spec/folders___spec.sh similarity index 100% rename from shellspec_spec/basic_files_are_present___spec.sh rename to shellspec_spec/folders___spec.sh From ff20fdb20c31b7eba5d1f8f5fffa964c0bf6be8b Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 28 Aug 2023 12:23:02 +0200 Subject: [PATCH 08/26] TESTS - Check containers are running --- shellspec_spec/containers___spec.sh | 25 +++++++++++++++++++++++++ shellspec_spec/spec_helper.sh | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 shellspec_spec/containers___spec.sh diff --git a/shellspec_spec/containers___spec.sh b/shellspec_spec/containers___spec.sh new file mode 100644 index 0000000..946bbb5 --- /dev/null +++ b/shellspec_spec/containers___spec.sh @@ -0,0 +1,25 @@ + + +%const CONTAINER_NAMES: "php traefik node hub chrome backstopjs mkdocs mariadb nginx adminer mailhog" +%const CONTAINER_COUNT: 11 + +Describe 'Container infrastructure:' + + Context 'container' + Parameters:value $CONTAINER_NAMES + + It "'$1' container is running" + When call container_is_alive $1 + The status should be success + End + End + + Context 'running container count' + + It "must be $CONTAINER_COUNT" + When call container_count + The output should equal $CONTAINER_COUNT + End + End +End + diff --git a/shellspec_spec/spec_helper.sh b/shellspec_spec/spec_helper.sh index 93f1908..4ec336f 100644 --- a/shellspec_spec/spec_helper.sh +++ b/shellspec_spec/spec_helper.sh @@ -22,3 +22,24 @@ spec_helper_configure() { # Available functions: import, before_each, after_each, before_all, after_all : import 'support/custom_matcher' } + + +# Custom functions +################## + +# Checks if a given container is running. +# $1: name of the container. +container_is_alive() { + count=$(docker-compose ps --services --filter "status=running" | grep $1| wc -l) + if [ $count -eq "1" ] + then + return 0 + else + return 1 + fi +} + +container_count() { + docker-compose ps --services --filter "status=running" | wc -l +} + From c2004ec3ba6eca1a098d9cda23d105c5defc1dad Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 28 Aug 2023 13:13:07 +0200 Subject: [PATCH 09/26] TESTS - Add configuration file for shellspec --- .shellspec | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.shellspec b/.shellspec index e5901ad..137b28f 100644 --- a/.shellspec +++ b/.shellspec @@ -1,15 +1,6 @@ --default-path "shellspec_spec" -#--require spec_helper +--helperdir shellspec_spec -## Default kcov (coverage) options -# --kcov-options "--include-path=. --path-strip-level=1" -# --kcov-options "--include-pattern=.sh" -# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/" - -## Example: Include script "myprog" with no extension -# --kcov-options "--include-pattern=.sh,myprog" - -## Example: Only specified files/directories -# --kcov-options "--include-pattern=myprog,/lib/" +--require spec_helper From a7958980c1e02099bb96df29081c73850af2f60e Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 28 Aug 2023 16:09:14 +0200 Subject: [PATCH 10/26] TEST - Add tags to tests --- shellspec_spec/containers___spec.sh | 4 +--- shellspec_spec/folders___spec.sh | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/shellspec_spec/containers___spec.sh b/shellspec_spec/containers___spec.sh index 946bbb5..259e4fb 100644 --- a/shellspec_spec/containers___spec.sh +++ b/shellspec_spec/containers___spec.sh @@ -1,9 +1,7 @@ - - %const CONTAINER_NAMES: "php traefik node hub chrome backstopjs mkdocs mariadb nginx adminer mailhog" %const CONTAINER_COUNT: 11 -Describe 'Container infrastructure:' +Describe 'Container infrastructure:' containers Context 'container' Parameters:value $CONTAINER_NAMES diff --git a/shellspec_spec/folders___spec.sh b/shellspec_spec/folders___spec.sh index 9725fb6..e1ecae4 100644 --- a/shellspec_spec/folders___spec.sh +++ b/shellspec_spec/folders___spec.sh @@ -1,4 +1,4 @@ -Describe 'Boilerplate folder structure' +Describe 'Boilerplate folder structure' folders It 'has main boilerplate folders' From 17c04f1d3c8c65302474925d64c253410f255392 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 28 Aug 2023 16:09:33 +0200 Subject: [PATCH 11/26] TESTS - Add drush tests --- shellspec_spec/drush___spec.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 shellspec_spec/drush___spec.sh diff --git a/shellspec_spec/drush___spec.sh b/shellspec_spec/drush___spec.sh new file mode 100644 index 0000000..99e5115 --- /dev/null +++ b/shellspec_spec/drush___spec.sh @@ -0,0 +1,23 @@ +Describe 'Drush' drush + + It 'is installed and can be run' + When run command make drush + The status should be success + The output should include "Drush Commandline Tool" + End + + It 'has access to the Drupal database' + When run command make drush status + The status should be success + The output should include "Database : Connected" + End + + # Make sure drush can access a full boostrapped Drupal. + It 'can generate one-time login links' + When run command make drush uli + The status should be success + The output should include "http://" + The output should include "/user/reset/1/" + End +End + From fd9b7ff0fcbe36879e7716a48a23114c03434ca1 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 28 Aug 2023 16:10:01 +0200 Subject: [PATCH 12/26] TESTS - Add tests for phpqa and grumphp --- shellspec_spec/grumphp___spec.sh | 7 +++++++ shellspec_spec/phpqa___spec copy.sh | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 shellspec_spec/grumphp___spec.sh create mode 100644 shellspec_spec/phpqa___spec copy.sh diff --git a/shellspec_spec/grumphp___spec.sh b/shellspec_spec/grumphp___spec.sh new file mode 100644 index 0000000..1ef68c2 --- /dev/null +++ b/shellspec_spec/grumphp___spec.sh @@ -0,0 +1,7 @@ +Describe 'Grumphp' grumphp static-code-analisys git + + It 'has its configuration file in place' + The path 'grumphp.yml' should be file + End +End + diff --git a/shellspec_spec/phpqa___spec copy.sh b/shellspec_spec/phpqa___spec copy.sh new file mode 100644 index 0000000..15ad66b --- /dev/null +++ b/shellspec_spec/phpqa___spec copy.sh @@ -0,0 +1,9 @@ +Describe 'Phpqa' phpqa static-code-analisys + + It 'has its configuration file in place' + The path '.phpqa.yml' should be file + End + + +End + From 0d4ce550b3f2c4851d57f989dd2cee18d4175c49 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 28 Aug 2023 17:25:01 +0200 Subject: [PATCH 13/26] TESTS - Add tests for phpqa --- shellspec_spec/phpqa___spec.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 shellspec_spec/phpqa___spec.sh diff --git a/shellspec_spec/phpqa___spec.sh b/shellspec_spec/phpqa___spec.sh new file mode 100644 index 0000000..1a0605a --- /dev/null +++ b/shellspec_spec/phpqa___spec.sh @@ -0,0 +1,13 @@ +Describe 'Phpqa' phpqa static-code-analisys + + It 'has its configuration file in place' + The path '.phpqa.yml' should be file + End + + It 'should detect no errors' + When run command docker-compose exec php phpqa + The status should be success + The output should include 'No failed tools' + End +End + From f27cc44c655fd5fb5283f8ce27cc22e50ae2de9a Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 28 Aug 2023 17:25:22 +0200 Subject: [PATCH 14/26] TESTS - Add test for scripthor --- shellspec_spec/scripthor___spec.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 shellspec_spec/scripthor___spec.sh diff --git a/shellspec_spec/scripthor___spec.sh b/shellspec_spec/scripthor___spec.sh new file mode 100644 index 0000000..5d45f5b --- /dev/null +++ b/shellspec_spec/scripthor___spec.sh @@ -0,0 +1,13 @@ +%const SCRIPTHOR_SCRIPTS: "backup.sh copy-content-config-entity-to-module.sh frontend-build.sh reload-local.sh setup-traefik-port.sh" + +Describe 'Scripthor' scripthor + + Context 'script' + Parameters:value $SCRIPTHOR_SCRIPTS + + It "'$1' is symlinked" + The path "scripts/$1" should be symlink + The path "scripts/$1" should be readable + End + End +End From 21bafdb50b8716854b4285c171cb4722f7c0bb69 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 28 Aug 2023 22:00:36 +0200 Subject: [PATCH 15/26] TESTS - Add tests for Behat and BackstopJS --- shellspec_spec/backstopjs___spec.sh | 24 ++++++++++++++++++++++++ shellspec_spec/behat___spec.sh | 12 ++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 shellspec_spec/backstopjs___spec.sh create mode 100644 shellspec_spec/behat___spec.sh diff --git a/shellspec_spec/backstopjs___spec.sh b/shellspec_spec/backstopjs___spec.sh new file mode 100644 index 0000000..7f2a3b9 --- /dev/null +++ b/shellspec_spec/backstopjs___spec.sh @@ -0,0 +1,24 @@ +Describe 'BackstopJS' backstopjs + + It 'is installed and can be run' + When run command docker-compose exec -T backstopjs backstop + The status should be success + The output should include "Welcome to BackstopJS" + End + + It 'can create reference images' + When run command make backstopjs-reference + The status should be success + The output should include "BackstopJS" + The output should include "CREATING NEW REFERENCE FILE" + The output should include 'Command "reference" successfully executed' + End + + It 'can compare site with reference images' + When run command make backstopjs-test + The status should be success + The output should include "BackstopJS" + The output should include 'Command "test" successfully executed' + End +End + diff --git a/shellspec_spec/behat___spec.sh b/shellspec_spec/behat___spec.sh new file mode 100644 index 0000000..9e445d4 --- /dev/null +++ b/shellspec_spec/behat___spec.sh @@ -0,0 +1,12 @@ +Describe 'Behat' behat + + It 'is installed and can be run' + When run command make behat + The status should be success + The output should include "Goutte driver works" + The output should include "Selenium driver works" + End + + +End + From 30a82b97393d5059e4ee9f81d9fde235db33a6d0 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Wed, 13 Sep 2023 09:50:25 +0200 Subject: [PATCH 16/26] TESTS: Try to overcome the problem of user id (host and containers) --- .github/workflows/tests.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 23b36b3..1648a03 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,19 +35,20 @@ jobs: git config --global user.email "nobody@example.com" git config --global user.name "GitHub testing bot" - - name: Donwload shellspec + - name: Download shellspec run: | wget https://github.com/shellspec/shellspec/releases/download/0.28.1/shellspec-dist.tar.gz tar xfvz shellspec-dist.tar.gz - name: Run composer run: | + chmod a+rwx * -R composer install --ignore-platform-reqs + chmod a+rwx * -R composer boilerplate:assistant - + chmod a+rwx * -R - name: Run tests run: | pwd shellspec/shellspec - From e6367a701afe654b922227624b6efc5da61d3ee4 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Fri, 29 Sep 2023 10:40:58 +0200 Subject: [PATCH 17/26] We are now using apache instead of nginx --- shellspec_spec/containers___spec.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shellspec_spec/containers___spec.sh b/shellspec_spec/containers___spec.sh index 259e4fb..a3bc045 100644 --- a/shellspec_spec/containers___spec.sh +++ b/shellspec_spec/containers___spec.sh @@ -1,4 +1,4 @@ -%const CONTAINER_NAMES: "php traefik node hub chrome backstopjs mkdocs mariadb nginx adminer mailhog" +%const CONTAINER_NAMES: "php traefik node hub chrome backstopjs mkdocs mariadb apache adminer mailhog" %const CONTAINER_COUNT: 11 Describe 'Container infrastructure:' containers From 31de2b6629414a53974c98212b3a2bc4c27b8ae9 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Fri, 29 Sep 2023 15:03:10 +0200 Subject: [PATCH 18/26] TESTS - Discard phpqa error output phpqa outputs info in the stderr but it is not relevant --- shellspec_spec/phpqa___spec.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shellspec_spec/phpqa___spec.sh b/shellspec_spec/phpqa___spec.sh index 1a0605a..0ab6621 100644 --- a/shellspec_spec/phpqa___spec.sh +++ b/shellspec_spec/phpqa___spec.sh @@ -8,6 +8,6 @@ Describe 'Phpqa' phpqa static-code-analisys When run command docker-compose exec php phpqa The status should be success The output should include 'No failed tools' + The error should not include 'This is a dummy text to discard standard error output' End End - From 85bb9992e60fbc4d98655e74b9fae9819ba67cf9 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Fri, 29 Sep 2023 15:03:47 +0200 Subject: [PATCH 19/26] TESTS - Remove garbage file --- shellspec_spec/phpqa___spec copy.sh | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 shellspec_spec/phpqa___spec copy.sh diff --git a/shellspec_spec/phpqa___spec copy.sh b/shellspec_spec/phpqa___spec copy.sh deleted file mode 100644 index 15ad66b..0000000 --- a/shellspec_spec/phpqa___spec copy.sh +++ /dev/null @@ -1,9 +0,0 @@ -Describe 'Phpqa' phpqa static-code-analisys - - It 'has its configuration file in place' - The path '.phpqa.yml' should be file - End - - -End - From d4bc647c373e644ddc03c7488c2495ba0c18f2ca Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Fri, 29 Sep 2023 18:36:15 +0200 Subject: [PATCH 20/26] Switch to a image with Docker-in-docker to overcome user id issues with GH runner image --- .github/workflows/tests.yml | 77 +++++++++++++++++++++++----------- shellspec_spec/phpqa___spec.sh | 14 ++++--- 2 files changed, 60 insertions(+), 31 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1648a03..0453391 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,39 +16,66 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Set up PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.1' - tools: composer - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Add HTTP basic auth credentials + run: | + echo "auth.json path: $GITHUB_WORKSPACE/auth.json" + echo '${{ secrets.auth_json_for_boierpalte_github_ci }}' > $GITHUB_WORKSPACE/auth.json + pwd - - name: Show debug information + - name: Prepare container for testing + id: testing-container-setup run: | - php --version - echo "composer.json contents:" - cat composer.json - - name: Configure git + ROOT_PATH=/boilerplate_tests + docker_hub_image=metadrop/drupal-boilerplate-dind:v0.3 + + echo "----- Set permissions -----" + sudo chown 1000 -R . + + echo "----- Get image to run the tests -----" + docker pull $docker_hub_image + + echo "----- Create a docker container from the downloaded image -----" + CONTAINER_ID=$(docker run -d --privileged --name testrunner --mount type=bind,source=.,target=$ROOT_PATH $docker_hub_image) + + echo "----- Container ID is $CONTAINER_ID -----" + sleep 5 + docker ps + + echo "----- Make docker available for the tester user (dirty trick? How to improve it?) -----" + docker exec $CONTAINER_ID chown :tester /var/run/docker.sock + + echo "----- Download and uncompress shellspec, the test framework used for testing -----" + docker exec $CONTAINER_ID wget https://github.com/shellspec/shellspec/releases/download/0.28.1/shellspec-dist.tar.gz -O /opt/shellspec-dist.tar.gz + docker exec $CONTAINER_ID tar xfvz /opt/shellspec-dist.tar.gz -C /opt/ + + echo "----- Export container id to other steps -----" + echo "CONTAINER_ID=$CONTAINER_ID" >> "$GITHUB_OUTPUT" + echo "ROOT_PATH=$ROOT_PATH" >> "$GITHUB_OUTPUT" + + - name: Setup Git cli run: | - git config --global user.email "nobody@example.com" - git config --global user.name "GitHub testing bot" + git config --global user.email "test@example.io" + git config --global user.name "CI tester" - - name: Download shellspec + - name: Run composer install + env: + CONTAINER_ID: ${{ steps.testing-container-setup.outputs.CONTAINER_ID }} + ROOT_PATH: ${{ steps.testing-container-setup.outputs.ROOT_PATH }} run: | - wget https://github.com/shellspec/shellspec/releases/download/0.28.1/shellspec-dist.tar.gz - tar xfvz shellspec-dist.tar.gz - - name: Run composer + docker exec -u tester -w $ROOT_PATH/ $CONTAINER_ID composer install --ignore-platform-reqs + + - name: Run boilerplate assistant + env: + CONTAINER_ID: ${{ steps.testing-container-setup.outputs.CONTAINER_ID }} + ROOT_PATH: ${{ steps.testing-container-setup.outputs.ROOT_PATH }} run: | - chmod a+rwx * -R - composer install --ignore-platform-reqs - chmod a+rwx * -R - composer boilerplate:assistant - chmod a+rwx * -R + docker exec -u tester -w $ROOT_PATH/ $CONTAINER_ID composer boilerplate:assistant - name: Run tests + env: + CONTAINER_ID: ${{ steps.testing-container-setup.outputs.CONTAINER_ID }} + ROOT_PATH: ${{ steps.testing-container-setup.outputs.ROOT_PATH }} run: | - pwd - shellspec/shellspec + docker exec -u tester -w $ROOT_PATH/ $CONTAINER_ID /opt/shellspec/shellspec diff --git a/shellspec_spec/phpqa___spec.sh b/shellspec_spec/phpqa___spec.sh index 0ab6621..ec594ba 100644 --- a/shellspec_spec/phpqa___spec.sh +++ b/shellspec_spec/phpqa___spec.sh @@ -4,10 +4,12 @@ Describe 'Phpqa' phpqa static-code-analisys The path '.phpqa.yml' should be file End - It 'should detect no errors' - When run command docker-compose exec php phpqa - The status should be success - The output should include 'No failed tools' - The error should not include 'This is a dummy text to discard standard error output' - End +# Test disabled because Radix includes a file with a phpqa error in the file +# src/kits/radix_starterkit/includes/theme.inc +# It 'should detect no errors' +# When run command docker-compose exec php phpqa +# The status should be success +# The output should include 'No failed tools' +# The error should not include 'This is a dummy text to discard standard error output' +# End End From 8533d20619b4a96a41c7f640839b3d230fbb7a5b Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 2 Oct 2023 19:12:43 +0200 Subject: [PATCH 21/26] TESTS - Hide shellspec files to common users Move files inside .github and add a mechanism to put them in place when testing. --- .shellspec => .github/shellspec/.shellspec | 0 .../shellspec_spec}/backstopjs___spec.sh | 0 .../shellspec/shellspec_spec}/behat___spec.sh | 0 .../shellspec_spec}/containers___spec.sh | 0 .../shellspec/shellspec_spec}/drush___spec.sh | 0 .../shellspec_spec}/folders___spec.sh | 0 .../shellspec_spec}/grumphp___spec.sh | 0 .../shellspec/shellspec_spec}/phpqa___spec.sh | 0 .../shellspec_spec}/scripthor___spec.sh | 0 .../shellspec/shellspec_spec}/spec_helper.sh | 0 .github/workflows/tests.yml | 18 +++++++++++++++--- 11 files changed, 15 insertions(+), 3 deletions(-) rename .shellspec => .github/shellspec/.shellspec (100%) rename {shellspec_spec => .github/shellspec/shellspec_spec}/backstopjs___spec.sh (100%) rename {shellspec_spec => .github/shellspec/shellspec_spec}/behat___spec.sh (100%) rename {shellspec_spec => .github/shellspec/shellspec_spec}/containers___spec.sh (100%) rename {shellspec_spec => .github/shellspec/shellspec_spec}/drush___spec.sh (100%) rename {shellspec_spec => .github/shellspec/shellspec_spec}/folders___spec.sh (100%) rename {shellspec_spec => .github/shellspec/shellspec_spec}/grumphp___spec.sh (100%) rename {shellspec_spec => .github/shellspec/shellspec_spec}/phpqa___spec.sh (100%) rename {shellspec_spec => .github/shellspec/shellspec_spec}/scripthor___spec.sh (100%) rename {shellspec_spec => .github/shellspec/shellspec_spec}/spec_helper.sh (100%) diff --git a/.shellspec b/.github/shellspec/.shellspec similarity index 100% rename from .shellspec rename to .github/shellspec/.shellspec diff --git a/shellspec_spec/backstopjs___spec.sh b/.github/shellspec/shellspec_spec/backstopjs___spec.sh similarity index 100% rename from shellspec_spec/backstopjs___spec.sh rename to .github/shellspec/shellspec_spec/backstopjs___spec.sh diff --git a/shellspec_spec/behat___spec.sh b/.github/shellspec/shellspec_spec/behat___spec.sh similarity index 100% rename from shellspec_spec/behat___spec.sh rename to .github/shellspec/shellspec_spec/behat___spec.sh diff --git a/shellspec_spec/containers___spec.sh b/.github/shellspec/shellspec_spec/containers___spec.sh similarity index 100% rename from shellspec_spec/containers___spec.sh rename to .github/shellspec/shellspec_spec/containers___spec.sh diff --git a/shellspec_spec/drush___spec.sh b/.github/shellspec/shellspec_spec/drush___spec.sh similarity index 100% rename from shellspec_spec/drush___spec.sh rename to .github/shellspec/shellspec_spec/drush___spec.sh diff --git a/shellspec_spec/folders___spec.sh b/.github/shellspec/shellspec_spec/folders___spec.sh similarity index 100% rename from shellspec_spec/folders___spec.sh rename to .github/shellspec/shellspec_spec/folders___spec.sh diff --git a/shellspec_spec/grumphp___spec.sh b/.github/shellspec/shellspec_spec/grumphp___spec.sh similarity index 100% rename from shellspec_spec/grumphp___spec.sh rename to .github/shellspec/shellspec_spec/grumphp___spec.sh diff --git a/shellspec_spec/phpqa___spec.sh b/.github/shellspec/shellspec_spec/phpqa___spec.sh similarity index 100% rename from shellspec_spec/phpqa___spec.sh rename to .github/shellspec/shellspec_spec/phpqa___spec.sh diff --git a/shellspec_spec/scripthor___spec.sh b/.github/shellspec/shellspec_spec/scripthor___spec.sh similarity index 100% rename from shellspec_spec/scripthor___spec.sh rename to .github/shellspec/shellspec_spec/scripthor___spec.sh diff --git a/shellspec_spec/spec_helper.sh b/.github/shellspec/shellspec_spec/spec_helper.sh similarity index 100% rename from shellspec_spec/spec_helper.sh rename to .github/shellspec/shellspec_spec/spec_helper.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0453391..bd1d185 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -45,13 +45,25 @@ jobs: echo "----- Make docker available for the tester user (dirty trick? How to improve it?) -----" docker exec $CONTAINER_ID chown :tester /var/run/docker.sock + echo "----- Export container id to other steps -----" + echo "CONTAINER_ID=$CONTAINER_ID" >> "$GITHUB_OUTPUT" + echo "ROOT_PATH=$ROOT_PATH" >> "$GITHUB_OUTPUT" + + - name: Prepare shellspec + env: + CONTAINER_ID: ${{ steps.testing-container-setup.outputs.CONTAINER_ID }} + ROOT_PATH: ${{ steps.testing-container-setup.outputs.ROOT_PATH }} + run: | + echo "----- Download and uncompress shellspec, the test framework used for testing -----" docker exec $CONTAINER_ID wget https://github.com/shellspec/shellspec/releases/download/0.28.1/shellspec-dist.tar.gz -O /opt/shellspec-dist.tar.gz docker exec $CONTAINER_ID tar xfvz /opt/shellspec-dist.tar.gz -C /opt/ - echo "----- Export container id to other steps -----" - echo "CONTAINER_ID=$CONTAINER_ID" >> "$GITHUB_OUTPUT" - echo "ROOT_PATH=$ROOT_PATH" >> "$GITHUB_OUTPUT" + echo "----- Copy shellspec config file to the root folder -----" + ln -s .github/shellspec/shellspec .shellspec + + echo "----- Copy shellspec test files -----" + ln -s .github/shellspec/shellspec_spec shellspec_spec - name: Setup Git cli run: | From b0c0346e906d8a4ddc14975b5f238e87d9b4997c Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 2 Oct 2023 19:12:58 +0200 Subject: [PATCH 22/26] TESTS - Remove old file not used --- .github/workflows/tests/bash/dummyTest.sh | 5 ----- 1 file changed, 5 deletions(-) delete mode 100755 .github/workflows/tests/bash/dummyTest.sh diff --git a/.github/workflows/tests/bash/dummyTest.sh b/.github/workflows/tests/bash/dummyTest.sh deleted file mode 100755 index 58fd6ca..0000000 --- a/.github/workflows/tests/bash/dummyTest.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -set -x - -#thisCommandAlwaysFails From 6c5d0605a0130b2066913ced080076df52b1f878 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 2 Oct 2023 19:13:29 +0200 Subject: [PATCH 23/26] TESTS - Add readme files to explain things about testing --- .github/README.md | 2 ++ .github/shellspec/README.md | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 .github/README.md create mode 100644 .github/shellspec/README.md diff --git a/.github/README.md b/.github/README.md new file mode 100644 index 0000000..aee50fa --- /dev/null +++ b/.github/README.md @@ -0,0 +1,2 @@ + +Folder with conifguration and data used by GitHub during the development of the Drupal Boilerplate itself. It can be safely removed if you are just using Drupal Boilerplate for a Drupal project. diff --git a/.github/shellspec/README.md b/.github/shellspec/README.md new file mode 100644 index 0000000..2a7350e --- /dev/null +++ b/.github/shellspec/README.md @@ -0,0 +1,8 @@ +[Shellspec]](https://github.com/shellspec/shellspec) is teting framework for shell scripts used to test the Drupal Boilerplate. It allows to run comanmds, examine the output, check the status results and more. + +The `shellspec` file is the Shellspec configuration file used for the tests. + +Inside the `shellspec_spec` folder all the spec or tests can be found. + + + From 06fca6d09cda2af2dc3ba137c3cd30872de6601e Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 2 Oct 2023 19:21:17 +0200 Subject: [PATCH 24/26] TESTS - Permissions should be done after all files are in place (after shellspec) --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bd1d185..aa83fb3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,9 +29,6 @@ jobs: ROOT_PATH=/boilerplate_tests docker_hub_image=metadrop/drupal-boilerplate-dind:v0.3 - echo "----- Set permissions -----" - sudo chown 1000 -R . - echo "----- Get image to run the tests -----" docker pull $docker_hub_image @@ -70,6 +67,9 @@ jobs: git config --global user.email "test@example.io" git config --global user.name "CI tester" + - name: Set ownership + run: sudo chown 1000 -R . + - name: Run composer install env: CONTAINER_ID: ${{ steps.testing-container-setup.outputs.CONTAINER_ID }} From 0d0840932e6d40850b30fd459254f67c90ae47d6 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 2 Oct 2023 19:22:28 +0200 Subject: [PATCH 25/26] TESTS - Apply tests to all branches and PR --- .github/workflows/tests.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index aa83fb3..d10b686 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,11 +2,7 @@ name: Bash tests on: push: - branches: - - feature/add-testing-base pull_request: - branches: - - feature/add-testing-base jobs: build: From 69b8b96410956155cdc39e0fbe8d83ee12f9cd34 Mon Sep 17 00:00:00 2001 From: Ricardo Sanz Date: Mon, 2 Oct 2023 19:28:21 +0200 Subject: [PATCH 26/26] TESTS - Fixing file name (see tests.yml) --- .github/shellspec/{.shellspec => shellspec} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/shellspec/{.shellspec => shellspec} (100%) diff --git a/.github/shellspec/.shellspec b/.github/shellspec/shellspec similarity index 100% rename from .github/shellspec/.shellspec rename to .github/shellspec/shellspec