Skip to content

Build, Validate and Test #1062

Build, Validate and Test

Build, Validate and Test #1062

Workflow file for this run

name: Build, Validate and Test
on:
schedule:
# Weekdays at 22:00 UTC (Monday to Friday 8 am AEST).
- cron: '0 22 * * 1-5'
workflow_dispatch:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
jobs:
full:
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' || !github.event.pull_request.draft }}
name: Full (Build, Validate, and Test)
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.3']
services:
database:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
env:
SKIP_CHECKS: ${{ vars.SKIP_CHECKS }}
CI: GITHUB_ACTIONS
GH_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
# github.head_ref is only defined on pull_request events.
# When not a PR, github.ref_name has the branch name.
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
# the commit ID for the last commit to the head branch of the pull request
# (the default is the last *merge* commit of the pull request merge branch)
- name: Setup PHP and tools
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:2.7.7
# See https://www.drupal.org/docs/getting-started/system-requirements/php-requirements#extensions
extensions: curl, date, dom, filter, gd, hash, json, mbstring, mysql, pcre, pdo, pdo_mysql, session, SimpleXML, SPL, tokenizer, xml, xmlwriter
# See https://docs.pantheon.io/guides/account-mgmt/plans/resources#current-plan-resources
ini-values: memory_limit=256M, max_execution_time=120
coverage: none
- name: Install php-spx extension
run: |
cd /tmp
git clone https://github.com/NoiseByNorthwest/php-spx.git
cd php-spx
git checkout release/latest
phpize
./configure
make
mkdir -p $HOME/php-exts
make INSTALL_ROOT=$HOME/php-exts install
EXTENSION_DIR=$(find $HOME/php-exts -name 'spx.so' | sed 's|/spx.so||')
echo "extension=${EXTENSION_DIR}/spx.so" >> "$(php -r 'echo php_ini_loaded_file();')"
shell: bash
- name: Prepare environment variables
run: |
echo "GITHUB_REF_NAME=$(echo ${GITHUB_REF##*/})" >> $GITHUB_ENV
echo "COMPOSER_BIN=$(echo ${GITHUB_WORKSPACE}/vendor/bin)" >> $GITHUB_ENV
echo "drush=$(echo ${GITHUB_WORKSPACE}/bin/drush)" >> $GITHUB_ENV
echo "SCRIPT_DIR=$(echo ${GITHUB_WORKSPACE}/.github/scripts)" >> $GITHUB_ENV
# Caching based on https://github.com/marketplace/actions/composer-php-actions#caching-dependencies-for-faster-builds
- name: Determine Composer cache directory
shell: bash
run: "echo \"COMPOSER_CACHE_DIR=$(composer config cache-dir)\" >> $GITHUB_ENV"
- name: Cache dependencies installed with Composer
uses: actions/cache@v4
with:
path: |
"${{ env.COMPOSER_CACHE_DIR }}"
$GITHUB_WORKSPACE/vendor
$GITHUB_WORKSPACE/web/core
$GITHUB_WORKSPACE/web/libraries
$GITHUB_WORKSPACE/web/modules/contrib
$GITHUB_WORKSPACE/web/themes/contrib
$GITHUB_WORKSPACE/web/profiles/contrib
key: os-${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
~/.npm
~/.nvm
key: ${{ runner.os }}-build-${{ github.ref }}
# Caching END
- name: Composer install
run: |
composer validate
composer --no-interaction --no-progress --prefer-dist --optimize-autoloader install
- name: Setup environment variables
run: |
echo "$GITHUB_WORKSPACE/vendor/bin" >> $GITHUB_PATH
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
- name: Validate composer
run: composer validate --no-check-all --ansi
- name: Download JavaScript Cookie Library
run: curl --create-dirs -o libraries/js-cookie/dist/js.cookie.min.js https://cdn.jsdelivr.net/npm/[email protected]/dist/js.cookie.min.js
- name: PHP Compatibility Check
run: |
phpcs -p modules/custom --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --extensions=php,module,inc --runtime-set testVersion ${{ matrix.php }}
phpcs -p themes/custom --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --extensions=php,theme,inc --runtime-set testVersion ${{ matrix.php }}
- name: Run code quality checks
run: grumphp run --testsuite=code_quality
- name: Run code security checks
if: ${{ !env.SKIP_CHECKS || env.SKIP_CHECKS != '1' }}
run: grumphp run --testsuite=code_security
- name: Execute Drupal-check
run: php ./bin/drupal-check modules/custom
- name: Show environment variables
run: ls -alk ./bin
- name: Setup MySQL
run: |
sudo service mysql start
mysql -uroot -proot < $(echo ${SCRIPT_DIR})/install.sql
- name: Setup Application
run: |
SPX_ENABLED=1 drush si convivial --locale=en --db-url=mysql://drupal:[email protected]:${{ job.services.mysql.ports[3306] }}/drupal --account-name=superadmin --account-pass=superadmin --site-name='Convivial Demo' --yes
drush ucrt admin --password=admin [email protected] --yes
drush urol site_administrator admin --yes
drush status
- name: Start Application in background
run: |
drush runserver localhost:8080 &
until netstat -an 2>/dev/null | grep '8080.*LISTEN'; do true; done
- name: Run Drupal Test Traits
run: phpunit
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Prepare environment variables for cypress tests
run: |
which node
node --version
npm --version
cp cypress.ci.default.json cypress.env.json
- name: Install cypress dependencies
run: |
npm install
npm list
- name: Run Cypress Tests
run: npx cypress run