Skip to content

Merge branch 'mautic:4.4' into 4.4 #98

Merge branch 'mautic:4.4' into 4.4

Merge branch 'mautic:4.4' into 4.4 #98

Workflow file for this run

name: Mautic tests and validations
on:
push:
branches:
- '[0-9].*'
pull_request:
schedule:
# Run every day at 10:45 AM UTC to discover potential issues with dependencies like PHP updates etc.
- cron: '45 10 * * *'
jobs:
phpunit:
# We don't want the scheduled jobs to run on forks of Mautic
if: (github.event_name == 'schedule' && (github.repository == 'mautic/mautic' || github.repository == 'mautic/api-library') ) || (github.event_name != 'schedule')
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.4', '8.0']
db-types: ['mysql', 'mariadb']
name: PHPUnit ${{ matrix.php-versions }} ${{ matrix.db-types }}
services:
database:
image: ${{ matrix.db-types == 'mysql' && 'mysql:5.7' || 'mariadb:10.3' }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: mautictest
ports:
- 3306
options: >-
--shm-size=2gb
--name=${{ matrix.db-types }}
--tmpfs=/var/lib/mysql
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- uses: actions/checkout@v2
# Codecov needs access to previous commits, so we add fetch-depth: 0
with:
fetch-depth: 0
- name: PHPUnit cache
if: ${{matrix.php-versions == '8.0' && matrix.db-types == 'mariadb'}}
uses: actions/cache@v3
with:
path: ./var/cache/phpunit
key: ${{ runner.os }}-phpunit-${{ hashFiles('**/composer.lock') }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-phpunit-${{ hashFiles('**/composer.lock') }}
${{ runner.os }}-phpunit-
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql
coverage: pcov
ini-values: pcov.enabled=0, pcov.directory=., pcov.exclude="~tests|themes|vendor~"
- name: add MySQL config file
run: |
mysqldump --version
mysqldump --print-defaults
cp .github/ci-files/.my.cnf ~/.my.cnf
mysqldump --print-defaults
- name: Set SYMFONY_ENV to test
run: |
echo "SYMFONY_ENV=test" >> $GITHUB_ENV
echo "MAUTIC_ENV=test" >> $GITHUB_ENV
- name: Install dependencies
run: |
composer validate
composer install --prefer-dist --no-progress --no-suggest
- name: Run tests - database = ${{ matrix.db-types }}
run: |
export DB_PORT="${{ job.services.database.ports[3306] }}"
if [[ "${{ matrix.php-versions }}" == "8.0" ]] && [[ "${{ matrix.db-types }}" == "mariadb" ]]; then
php -d pcov.enabled=1 bin/phpunit -d memory_limit=1G --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist --coverage-clover=coverage.xml
else
composer test
fi
- name: Upload coverage report
if: ${{ matrix.php-versions == '8.0' && matrix.db-types == 'mariadb' && github.repository == 'mautic/mautic' }}
uses: codecov/codecov-action@v2
with:
files: ./coverage.xml
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
- 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 GitHub Actions tests in mautic/mautic have failed. Most likely something external has changed, like a PHP version update.'
- name: Store log artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: logs-${{ matrix.php-versions }}-${{ matrix.db-types }}
path: ./var/logs/*
misc:
# We don't want the scheduled jobs to run on forks of Mautic
if: (github.event_name == 'schedule' && (github.repository == 'mautic/mautic' || github.repository == 'mautic/api-library') ) || (github.event_name != 'schedule')
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
commands: ['PHPSTAN', 'CS Fixer', 'Rector', 'scaffolded files mismatch', 'PHPStan baseline changes', 'composer install']
php-versions: ['7.4', '8.0']
name: ${{ matrix.commands }} - ${{ matrix.php-versions }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Rector Cache
if: ${{matrix.commands == 'Rector'}}
uses: actions/cache@v3
with:
path: ./var/cache/rector
key: ${{ runner.os }}-rector-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-rector-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
${{ runner.os }}-rector-${{ matrix.php-versions }}-
- name: PHPStan Cache
if: ${{matrix.commands == 'PHPSTAN'}}
uses: actions/cache@v3
with:
path: ./var/cache/phpstan
key: ${{ runner.os }}-phpstan-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-phpstan-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
${{ runner.os }}-phpstan-${{ matrix.php-versions }}-
- name: Get changed files
id: changed-files
uses: tj-actions/[email protected]
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql
- name: Install dependencies
run: |
composer validate
composer install --prefer-dist --no-progress --no-suggest
- name: Run ${{ matrix.commands }}
run: |
if [[ "${{ matrix.commands }}" == "PHPSTAN" ]]; then
composer phpstan
elif [[ "${{ matrix.commands }}" == "Rector" ]]; then
composer rector -- --dry-run --no-progress-bar
elif [[ "${{ matrix.commands }}" == "CS Fixer" ]]; then
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ $file == *.php ]]; then
cs_fix_files="${cs_fix_files} $file"
fi
done
if [[ $cs_fix_files ]]; then
bin/php-cs-fixer fix --config=.php-cs-fixer.php -v --dry-run --using-cache=no --show-progress=dots --diff $cs_fix_files
fi
elif [[ "${{ matrix.commands }}" == "scaffolded files mismatch" ]]; then
wget -q -O /tmp/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && chmod 755 /tmp/jq
/tmp/jq -r '.extra["mautic-scaffold"]["file-mapping"] | to_entries[] | "diff -q \(.key | sub("\\[(project|web)-root\\]";".")) app/\(.value)"' app/composer.json > diff_commands.sh
bash diff_commands.sh | tee /tmp/diff_command_output.txt
rm diff_commands.sh
if [[ $(wc -l </tmp/diff_command_output.txt) -ge 1 ]]; then
echo "some scaffolded files were not updated"
echo "Please apply the same changes in the files mentioned above"
exit 1
fi
elif [[ "${{ matrix.commands }}" == "PHPStan baseline changes" ]]; then
if [[ "${{ steps.changed-files.outputs.modified_files }}" == *"phpstan-baseline.neon"* ]]; then
stat=$(git diff --shortstat "origin/${{ github.base_ref }}" ${{ github.sha }} -- phpstan-baseline.neon)
echo $stat
regex="[0-9]+[[:space:]]insertion"
if [[ $stat =~ $regex ]]; then
echo "There are modifications (added or changed lines) to the phpstan-baseline.neon"
echo "Please fix the PHPStan errors instead of altering the baseline file"
exit 1
fi
fi
elif [[ "${{ matrix.commands }}" == "composer install" ]]; then
# create a temp dir and mimic a composer install via mautic/recommended-project
mkdir test_composer
cd test_composer
cp ../.github/ci-files/composer.json ./
composer install
# test if console works by generating assets for next step
php ./bin/console mautic:assets:generate
# test if media/css and media/js folder contain the same files as the tarball releases
test -z "$(comm -23 <(ls ../media/js | sort) <(ls docroot/media/js | sort))"
test -z "$(comm -23 <(ls ../media/css | sort) <(ls docroot/media/css | sort))"
php ./bin/console cache:clear
else
echo "Invalid command"
exit 1
fi
- 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 GitHub Actions tests in mautic/mautic have failed. Most likely something external has changed, like a PHP version update.'