Skip to content

API library tests #1784

API library tests

API library tests #1784

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.1
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 apt-get update
sudo apt-get install apache2 libapache2-mod-php8.1
sudo a2enmod rewrite
sudo sed -i 's,^session.save_handler =.*$,session.save_handler = redis,' /etc/php/8.1/apache2/php.ini
sudo sed -i 's,^;session.save_path =.*$,session.save_path = "tcp://127.0.0.1:6379",' /etc/php/8.1/apache2/php.ini
sudo sed -i 's,^memory_limit =.*$,memory_limit = 256M,' /etc/php/8.1/apache2/php.ini
sudo service apache2 restart
cat /etc/php/8.1/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/
cp ./.github/ci-files/.env /var/www/html/
sed -i 's/DB_PORT=3306/DB_PORT=${{ job.services.mysql.ports[3306] }}/g' /var/www/html/.env
rm -f /var/www/html/.env.test
- name: Install Mautic
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
run: |
composer install --prefer-dist --no-progress
if [[ "$(jq -r '.version | .[0:1]' app/release_metadata.json)" == "4" ]]; then
cp $GITHUB_WORKSPACE/.github/ci-files/local_4.php ./app/config/local.php
php bin/console mautic:install http://localhost/ --force --env=test --mailer_from_name="GitHub Actions" --mailer_from_email="[email protected]"
sed -i "s/('prod',/('test',/g" ./index.php
echo "MAUTIC_VERSION=4" >> $GITHUB_ENV
else
cp $GITHUB_WORKSPACE/.github/ci-files/local_5.php ./config/local.php
php bin/console mautic:install http://localhost/ --force --env=test
echo "MAUTIC_VERSION=5" >> $GITHUB_ENV
fi
php bin/console cache:warmup --no-interaction --env=test
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=test
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: |
sed -i 's/env name="MAUTIC_VERSION" value="5"/env name="MAUTIC_VERSION" value="${{ env.MAUTIC_VERSION }}"/g' ./phpunit.xml.dist
vendor/bin/phpunit --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@v4
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.'
tests:
runs-on: ubuntu-20.04
name: CS & PHPSTAN 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-fixer.php -v --dry-run --using-cache=no --show-progress=dots --diff $(git diff -- '*.php' --name-only --diff-filter=ACMRTUXB "HEAD~..HEAD")
- name: Run PHPSTAN tests
run: composer phpstan