Skip to content

Adding GH Actions config #46

Adding GH Actions config

Adding GH Actions config #46

Workflow file for this run

name: Mautic Build and Test
on:
push:
branches:
- staging # Main branch
- '[0-9]+\.[0-9]+'
- development
- beta
pull_request:
branches:
- '*'
env:
PLUGIN_DIR: plugins/CustomObjectsBundle # Same as extra.install-directory-name in composer.json
jobs:
phpunit:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.4'] # The supported PHP versions
db-types: ['mysql'] # can be: ['mysql', 'mariadb'] but not necessary for this plugin that does not add any DB schema
mautic-versions: ['4.4'] # The supported Mautic versions
name: Tests on PHP ${{ matrix.php-versions }}, ${{ matrix.db-types }}, Mautic ${{ matrix.mautic-versions }}
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:
- name: Checkout Mautic 4
uses: actions/checkout@v3
with:
repository: mautic/mautic
ref: ${{ matrix.mautic-versions }}
- name: Checkout this plugin
uses: actions/checkout@v3
with:
path: ${{ env.PLUGIN_DIR }}
- name: Get Commit ID
run: |
echo "COMMIT_ID=${{ github.sha }}" >> $GITHUB_ENV
echo "Commit ID: $COMMIT_ID"
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
ini-values: -dpcov.enabled=0, pcov.directory=."
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql
coverage: pcov
- 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: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install && composer require --dev theofidry/alice-data-fixtures
- name: Install Mautic
env:
DB_PORT: ${{ job.services.database.ports[3306] }}
run: |
cp ./.github/ci-files/local.php ./app/config/local.php
php bin/console mautic:install --force http://localhost
- name: Install Plugins
env:
DB_PORT: ${{ job.services.database.ports[3306] }}
run: php bin/console mautic:plugins:install --env=dev
- name: Run Code Style check
run: bin/php-cs-fixer fix ${{ env.PLUGIN_DIR }} --config=.php-cs-fixer.php -v --dry-run --show-progress=dots --diff
# - name: PHPSTAN - baseline (debug)
# run: bin/phpstan --configuration=plugins/CustomObjectsBundle/phpstan.neon --generate-baseline=var/logs/phpstan-baseline-${{ matrix.php-versions }}.neon --allow-empty-baseline
- name: PHPSTAN - baseline (debug)
run: |
if [ -f "plugins/CustomObjectsBundle/phpstan.neon" ]; then
bin/phpstan --configuration=plugins/CustomObjectsBundle/phpstan.neon --generate-baseline=var/logs/phpstan-baseline-7.4.neon --allow-empty-baseline
else
echo "PHPStan configuration file not found. Skipping baseline generation."
fi
# - name: PHPSTAN
# run: bin/phpstan --configuration=${{ env.PLUGIN_DIR }}/phpstan.neon
- name: Rector
run: composer rector -- --dry-run --no-progress-bar ${{ env.PLUGIN_DIR }}
- name: Twig Lint
run: bin/console lint:twig ${{ env.PLUGIN_DIR }}
# - name: Run PHPUNIT tests
# env:
# DB_PORT: ${{ job.services.database.ports[3306] }}
# # run: XDEBUG_MODE=coverage APP_DEBUG=0 php -dpcov.enabled=1 -dpcov.directory=. -dpcov.exclude="~tests|themes|vendor~" bin/phpunit -d memory_limit=1G --bootstrap vendor/autoload.php --configuration ${{ env.PLUGIN_DIR }}/phpunit.xml --coverage-clover=${{ env.PLUGIN_DIR }}/coverage.xml --coverage-text
# run: XDEBUG_MODE=coverage APP_DEBUG=0 php -dpcov.enabled=1 -dpcov.directory=. -dpcov.exclude="~tests|themes|vendor|app~" bin/phpunit -d memory_limit=1G --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist --filter=CustomObjectsBundle --coverage-clover=${{ env.PLUGIN_DIR }}/coverage.xml --coverage-text
# - name: Coverage report (debug)
# run: cat ${{ env.PLUGIN_DIR }}/coverage.xml
# - name: Upload coverage report
# if: ${{ matrix.php-versions == '8.0' && matrix.db-types == 'mysql' && matrix.mautic-versions == '4.4' }} # upload just once, change for your matrix
# uses: codecov/codecov-action@v3
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# fail_ci_if_error: true
# working-directory: ${{ env.PLUGIN_DIR }}
# verbose: true
- name: Upload logs as artifacts
uses: actions/upload-artifact@v3
with:
name: mautic-logs
path: var/logs/
# - name: Setup SSH key
# run: |
# eval `ssh-agent -s`
# echo $ACSFBOT_SSHKEY | base64 -d | ssh-add -
# git config -l
# git config --global --add safe.directory '*'
# mkdir -p -m 0600 $HOME/.ssh && ssh-keyscan github.com >> $HOME/.ssh/known_hosts
# echo $ACQUIA_VCS_KNOWN_HOSTS_ENTRY >> $HOME/.ssh/known_hosts
- name: Push commit to mc-cs
run: |
git clone https://github.com/acquia/mc-cs.git mc-cs-plugin-test
cd mc-cs-plugin-test
ls -al
# git config --global user.email "acsfbot@acquia.com"
# git config --global user.name "Jenkins"
# git config --global advice.detachedHead false
# git config --global url."git@github.com:".insteadOf "https://github.com/"
# git checkout origin/mc-cs-plugin-test
# git pull origin $DEV_BRANCH
# git push origin HEAD:mc-cs-plugin-test