Build, Validate and Test #191
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
build: | |
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: | |
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: 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 | |
- name: Check Application Status | |
run: drush status |