Skip to content

API library tests

API library tests #185

Workflow file for this run

name: API library tests
on:
push:
branches:
- main
- '[0-9]+\.[0-9]+'
pull_request:
workflow_dispatch:
inputs:
pr:
description: 'PR number in mautic/mautic to test against'
required: false
schedule:
# Run every day at 10 AM UTC to discover potential issues with recent changes to Mautic itself
- cron: '0 10 * * *'
jobs:
phpunit:
runs-on: ubuntu-20.04
name: PHPUnit tests
services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: mautictest
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
mailhog:
image: mailhog/mailhog:latest
ports:
- 1025:1025
redis:
image: redis:6
ports:
- 6379:6379
steps:
- uses: actions/checkout@v3
- name: Copy our API library config into the tests/ folder
run: cp -a ./.github/ci-files/local.config.php tests/local.config.php
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
ini-values: session.save_handler=redis, session.save_path="tcp://127.0.0.1:6379"
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql
coverage: pcov
- name: Set SYMFONY_ENV to test
run: echo "SYMFONY_ENV=test" >> $GITHUB_ENV
- name: Install Apache
# We need the sed command at the bottom to set the PHP session save path to a directory that's writable for PHP
# NOTE: update the PHP version below as well if you're updating PHP!
run: |
sudo add-apt-repository ppa:ondrej/php -y
sudo add-apt-repository ppa:ondrej/apache2 -y
sudo apt-get install apache2 libapache2-mod-php8.0
sudo a2enmod rewrite
sudo sed -i 's,^session.save_handler =.*$,session.save_handler = redis,' /etc/php/8.0/apache2/php.ini
sudo sed -i 's,^;session.save_path =.*$,session.save_path = "tcp://127.0.0.1:6379",' /etc/php/8.0/apache2/php.ini
sudo service apache2 restart
cat /etc/php/8.0/apache2/php.ini | grep session
- name: Install dependencies
run: |
composer validate --strict
composer install --prefer-dist --no-progress
- name: Clone Mautic main branch or specific PR from GitHub
run: |
gh repo clone mautic/mautic -- --single-branch --depth 1
if [[ "${{ github.event.inputs.pr }}" != "" ]]; then
pushd mautic
gh pr checkout ${{ github.event.inputs.pr }}
popd
fi
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Move files to web root
run: |
shopt -s dotglob
sudo chmod -R 777 /var/www/html
sudo chown -R www-data:www-data /var/www/html
rm -rf /var/www/html/*
mv $GITHUB_WORKSPACE/mautic/* /var/www/html/
- name: Install Mautic
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
run: |
composer install --prefer-dist --no-progress
cp $GITHUB_WORKSPACE/.github/ci-files/local.php ./app/config/local.php
php bin/console mautic:install http://localhost/ \
--force --mailer_from_name="GitHub Actions" --mailer_from_email="[email protected]" \
--mailer_transport="smtp" --mailer_host="localhost" --mailer_port="1025" --env=dev
php bin/console cache:warmup --no-interaction --env=dev
working-directory: /var/www/html/
# Enable Twilio plugin with random credentials (needed for MessagesTest to function, doesn't actually contact Twilio API).
- name: Enable Twilio plugin
run: |
mysql -uroot -P${{ job.services.mysql.ports[3306] }} -h127.0.0.1 -e "USE mautictest; INSERT INTO plugin_integration_settings (plugin_id, name, is_published, supported_features, api_keys, feature_settings) VALUES (NULL, 'Twilio', 1, 'a:0:{}', 'a:2:{s:8:\"username\";s:169:\"bzFmNlIydWRSZXlIN2lQVkdpanJ4aTQ2NUh6RVdDbHlLRVhsWGZ4b0kyZVNxLzYrQ1J6V1RvMnlhVEp0c245TEp6eStQekx5ZVhLWjB1YVdoR3RnR2dHQ3k1emVVdGt5NzZKUmtjUnJ3c1E9|L8tbZRIYhwatT7Mq+HAdYA==\";s:8:\"password\";s:169:\"T2d2cFpXQWE5YVZnNFFianJSYURRYUtGRHBNZGZjM1VETXg2Wm5Va3NheW43MjVWUlJhTVlCL2pYMDBpbElONStiVVBNbEM3M3BaeGJMNkFKNUFEN1pTNldSRjc4bUM4SDh1SE9OY1k5MTg9|TeuSvfx4XSUOvp0O7T49Cg==\";}', 'a:4:{s:20:\"sending_phone_number\";N;s:22:\"disable_trackable_urls\";i:0;s:16:\"frequency_number\";N;s:14:\"frequency_time\";N;}');"
php bin/console mautic:plugins:reload --env=dev
working-directory: /var/www/html
- name: Set correct ownership so Apache can access the files
run: sudo chown -R www-data:www-data /var/www/html
- name: Run tests
run: vendor/bin/paratest -p 3 --coverage-clover coverage.xml
- name: Upload code coverage
run: bash <(curl -s https://codecov.io/bash)
- name: Upload logs as artifacts
uses: actions/upload-artifact@v2
if: always()
with:
name: mautic-logs
path: /var/www/html/var/logs/
- name: Slack Notification if tests fail
uses: rtCamp/action-slack-notify@v2
if: ${{ failure() && github.event_name == 'schedule' }}
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: 'The daily API library tests against mautic/mautic have failed. Most likely a PR was merged recently which introduced a regression of some sort.'
cs:
runs-on: ubuntu-20.04
name: CS tests
steps:
- uses: actions/checkout@v3
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql
- name: Install dependencies
run: |
composer validate --strict
composer install --prefer-dist --no-progress
- name: Run CS tests
run: vendor/bin/php-cs-fixer fix --config=.php_cs -v --dry-run --using-cache=no --show-progress=dots --diff $(git diff -- '*.php' --name-only --diff-filter=ACMRTUXB "HEAD~..HEAD")