[ci] split tests and code quality tests #3
Workflow file for this run
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: Code Analysis | |
on: | |
push: | |
branches: | |
- '[0-9].*' | |
pull_request: | |
merge_group: | |
schedule: | |
# Run every day at 10:45 AM UTC to discover potential issues with dependencies like PHP updates etc. | |
- cron: '45 10 * * *' | |
jobs: | |
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', 'Twig Lint', 'scaffolded files mismatch', 'PHPStan baseline changes', 'composer install', 'composer lock check'] | |
php-versions: ['8.1'] | |
name: ${{ matrix.commands }} - ${{ matrix.php-versions }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: PHPStan Cache | |
if: ${{matrix.commands == 'PHPSTAN'}} | |
uses: actions/cache@v3 | |
with: | |
path: ./var/cache/phpstan | |
key: ${{ runner.os }}-phpstan-${{ hashFiles('**/composer.lock') }}-${{ github.run_id }} | |
restore-keys: | | |
${{ runner.os }}-phpstan-${{ hashFiles('**/composer.lock') }} | |
${{ runner.os }}-phpstan- | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/changed-files@v35 | |
- 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 | |
# composer install https://github.com/ramsey/composer-install | |
- name: Install dependencies | |
uses: "ramsey/composer-install@v2" | |
- name: Run ${{ matrix.commands }} | |
run: | | |
if [[ "${{ matrix.commands }}" == "PHPSTAN" ]]; then | |
export SYMFONY_ENV=dev | |
export APP_ENV=dev | |
export APP_DEBUG=1 | |
composer phpstan -- --no-progress | |
elif [[ "${{ matrix.commands }}" == "Rector" ]]; then | |
export SYMFONY_ENV=test | |
bin/console cache:warmup | |
bin/rector --dry-run --ansi | |
elif [[ "${{ matrix.commands }}" == "Twig Lint" ]]; then | |
bin/console lint:twig app plugins | |
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 | |
/tmp/jq -r '.extra["mautic-scaffold"]["file-mapping"] | to_entries[] | "diff -rui \(.key | sub("\\[(project|web)-root\\]";".")) app/\(.value)"' app/composer.json > diff_commands_verbose.sh | |
bash diff_commands.sh 2>&1 | 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 or deleted" | |
echo "Please apply the same changes in the files mentioned above" | |
echo "verbose diff:" | |
bash diff_commands_verbose.sh | |
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 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))" | |
# test if console is executable | |
./bin/console cache:clear | |
elif [[ "${{ matrix.commands }}" == "composer lock check" ]]; then | |
composer validate --ansi | |
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.' |