Skip to content

Commit

Permalink
test: split build and test (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrfritsch authored Mar 12, 2020
1 parent f28b1ae commit 88a7776
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 35 deletions.
85 changes: 81 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ on:
schedule:
- cron: '0 6 * * *'

env:
DRUPAL_TESTING_TEST_CODING_STYLES: false
DRUPAL_TESTING_PROJECT_BASEDIR: ${{ github.workspace }}/tests/module

jobs:
build:
test-projects:

runs-on: ubuntu-latest

Expand Down Expand Up @@ -57,7 +61,80 @@ jobs:
- name: Run tests
run: test-drupal-project
env:
DRUPAL_TESTING_TEST_CODING_STYLES: false
DRUPAL_TESTING_PROJECT_BASEDIR: ${{ github.workspace }}/tests/module
DRUPAL_TESTING_COMPOSER_PROJECT: ${{ matrix.DRUPAL_TESTING_COMPOSER_PROJECT }}
DRUPAL_TESTING_DRUPAL_VERSION: ${{ matrix.DRUPAL_TESTING_DRUPAL_VERSION }}
DRUPAL_TESTING_DRUPAL_VERSION: ${{ matrix.DRUPAL_TESTING_DRUPAL_VERSION }}

test-split-upload:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- uses: shivammathur/setup-php@master
with:
coverage: none
php-version: '7.3'

- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-cache-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-cache-

- name: Cache NPM dependencies
id: npm-cache
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-npm-cache
restore-keys: ${{ runner.os }}-npm-cache

- name: Setup environment variables
run: |
echo "::add-path::$HOME/.composer/vendor/bin"
echo "::add-path::$GITHUB_WORKSPACE/vendor/bin"
echo "::add-path::$GITHUB_WORKSPACE/bin"
- name: Install project
run: test-drupal-project install

- name: Zip build
run: cd /tmp; tar cfz build.tgz test; mv build.tgz ${GITHUB_WORKSPACE}

- name: Upload build
uses: actions/upload-artifact@v1
with:
name: build
path: build.tgz

test-split-download:
needs: test-split-upload

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- uses: shivammathur/setup-php@master
with:
coverage: none
php-version: '7.3'
extensions: Imagick

- name: Setup environment variables
run: |
echo "::add-path::$HOME/.composer/vendor/bin"
echo "::add-path::$GITHUB_WORKSPACE/vendor/bin"
echo "::add-path::$GITHUB_WORKSPACE/bin"
- name: Download build
uses: actions/download-artifact@v1
with:
name: build

- name: Unzip build artifact
run: tar xCfz /tmp build/build.tgz test; rm -rf build

- name: Run the tests
run: test-drupal-project run_tests
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ The simplest way to run the tests is to just call <code>test_drupal_project</cod
This will do everything, but it is actually divided into several steps which can be called separately by providing the
step as a parameter: <code>test_drupal_project build</code> would call the build step and any steps that the build step
depends on. Steps, that have already been executed will not be called again on subsequent call. So, if you call
<code>test_drupal_project start_web_server</code> next, all steps up to the build step will not be executed.
<code>test_drupal_project start_services</code> next, all steps up to the build step will not be executed.

The steps are the following:

### setup
Setup the testing environment. Starts selenium and mysql if necessary and tweaks php on travis
### requirements
Check if testing requirements are met.

### coding_style
Tests php and javascript coding styles
Expand All @@ -103,8 +103,8 @@ Builds the drupal installation with drupal project, adds all dependencies from t
### install
Installs drupal with the minimal profile or the one that has been configured.

### start_web_server
Starts a webserver pointing to the installed drupal.
### start_services
Starts services required for testing. Starts web server and selenium.

### run_tests
Runs the tests
Expand Down
4 changes: 2 additions & 2 deletions bin/test-drupal-project
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ run would start from scratch.
Parameter:
STAGE The test stage to execute, defaults to run_test (all stages are executed).
If a stage depends on other stages, they will be automatically called.
Possible values: setup, coding_style, prepare_build, build,
install, start_web_server, run_tests
Possible values: requirements, coding_style, prepare_build, build,
install, start_services, run_tests
Options:
-h, --help Display this help.
-nc, --no-cleanup Do not cleanup after successful tests. Set this option to keep the installation.
Expand Down
8 changes: 4 additions & 4 deletions lib/stage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ stage_dependency() {

case ${1} in
run_tests)
dep="start_web_server"
dep="start_services"
;;
start_web_server)
start_services)
dep="install"
;;
install)
Expand All @@ -52,9 +52,9 @@ stage_dependency() {
dep="prepare_build"
;;
prepare_build)
dep="setup"
dep="requirements"
;;
setup)
requirements)
dep="coding_style"
;;
esac
Expand Down
12 changes: 12 additions & 0 deletions lib/stages/requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# Check requirements.
_stage_requirements() {
printf "Check requirements\n\n"

if [[ ${DRUPAL_TESTING_DATABASE_ENGINE} != 'sqlite' ]] && ! port_is_open "${DRUPAL_TESTING_DATABASE_HOST}" "${DRUPAL_TESTING_DATABASE_PORT}"; then
printf "Error: Database is not running, or configured incorrectly.\n"
exit 1
fi

}
16 changes: 9 additions & 7 deletions lib/stages/setup.sh → lib/stages/start_services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ download_chromedriver() {
rm "${DRUPAL_TESTING_TEST_BASE_DIRECTORY}"/"${filename}"
}

# Setup the environment, and start services
_stage_setup() {
printf "Setup environment\n\n"
_stage_start_services() {
printf "Starting services\n\n"

if [[ ${DRUPAL_TESTING_DATABASE_ENGINE} != 'sqlite' ]] && ! port_is_open "${DRUPAL_TESTING_DATABASE_HOST}" "${DRUPAL_TESTING_DATABASE_PORT}"; then
printf "Error: Database is not running, or configured incorrectly.\n"
exit 1
fi
local docroot
docroot=$(get_distribution_docroot)

if ! port_is_open "${DRUPAL_TESTING_SELENIUM_HOST}" "${DRUPAL_TESTING_SELENIUM_PORT}"; then
printf "Starting web driver\n"
Expand All @@ -38,4 +35,9 @@ _stage_setup() {

wait_for_port "${DRUPAL_TESTING_SELENIUM_HOST}" "${DRUPAL_TESTING_SELENIUM_PORT}"
fi

if ! port_is_open "${DRUPAL_TESTING_HTTP_HOST}" "${DRUPAL_TESTING_HTTP_PORT}"; then
php -S "${DRUPAL_TESTING_HTTP_HOST}":"${DRUPAL_TESTING_HTTP_PORT}" -t "${docroot}" >/dev/null 2>&1 &
wait_for_port "${DRUPAL_TESTING_HTTP_HOST}" "${DRUPAL_TESTING_HTTP_PORT}" 30
fi
}
13 changes: 0 additions & 13 deletions lib/stages/start_web_server.sh

This file was deleted.

0 comments on commit 88a7776

Please sign in to comment.