Merge pull request #1344 from buckaroo-it/BP-4667-Remove-unnecessary-… #4765
Workflow file for this run
This file contains hidden or 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: M2 Coding Standard | |
on: | |
push: | |
pull_request: | |
# Prevent duplicate runs: cancel in-progress runs for the same PR/branch | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
# Job to check if we should run based on the event type and PR status | |
check-conditions: | |
runs-on: ubuntu-latest | |
outputs: | |
should-run: ${{ steps.decide.outputs.should-run }} | |
reason: ${{ steps.decide.outputs.reason }} | |
steps: | |
- name: Decide if checks should run | |
id: decide | |
run: | | |
if [ "${{ github.event_name }}" == "pull_request" ]; then | |
echo "should-run=true" >> $GITHUB_OUTPUT | |
echo "reason=Running because this is a Pull Request event" >> $GITHUB_OUTPUT | |
elif [ "${{ github.event_name }}" == "push" ]; then | |
branch_name="${{ github.ref_name }}" | |
pr_response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:$branch_name&state=open") | |
pr_count=$(echo "$pr_response" | jq length) | |
if [ "$pr_count" -eq 0 ]; then | |
echo "should-run=true" >> $GITHUB_OUTPUT | |
echo "reason=Running because push to branch with no open PR" >> $GITHUB_OUTPUT | |
else | |
echo "should-run=false" >> $GITHUB_OUTPUT | |
echo "reason=Skipping because open PR exists (checks will run on PR)" >> $GITHUB_OUTPUT | |
fi | |
else | |
echo "should-run=true" >> $GITHUB_OUTPUT | |
echo "reason=Running for workflow_dispatch or other event" >> $GITHUB_OUTPUT | |
fi | |
phpcs: | |
name: M2 Code Analysis | |
runs-on: ubuntu-latest | |
needs: check-conditions | |
if: needs.check-conditions.outputs.should-run == 'true' | |
continue-on-error: true | |
steps: | |
- name: Show execution reason | |
run: | | |
echo "✅ Running PHPCS: ${{ needs.check-conditions.outputs.reason }}" | |
- uses: actions/checkout@v3 | |
- uses: extdn/github-actions-m2/magento-coding-standard/8.3@master | |
with: | |
phpcs_severity: 10 | |
phpcs_report: full | |
phpmd: | |
name: M2 Mess Detection | |
runs-on: ubuntu-latest | |
needs: check-conditions | |
if: needs.check-conditions.outputs.should-run == 'true' | |
continue-on-error: true | |
steps: | |
- name: Show execution reason | |
run: | | |
echo "✅ Running PHPMD: ${{ needs.check-conditions.outputs.reason }}" | |
- uses: actions/checkout@v3 | |
- uses: extdn/github-actions-m2/magento-mess-detector@master | |
phpstan: | |
name: M2 PHPStan | |
runs-on: ubuntu-latest | |
needs: check-conditions | |
if: needs.check-conditions.outputs.should-run == 'true' | |
continue-on-error: true | |
steps: | |
# ─────────────────────────────────────────────────────────────── | |
# PHP & Composer | |
# ─────────────────────────────────────────────────────────────── | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: 8.3 | |
tools: composer:v2 | |
- uses: actions/checkout@v3 | |
- name: Validate composer.json | |
run: composer validate | |
- name: Clear Composer cache | |
run: composer clear-cache | |
# ─────────────────────────────────────────────────────────────── | |
# Magento test installation | |
# ─────────────────────────────────────────────────────────────── | |
- name: Setup Magento | |
env: | |
COMPOSER_PROCESS_TIMEOUT: 0 | |
COMPOSER_NO_INTERACTION: 1 | |
COMPOSER_NO_AUDIT: 1 | |
run: | | |
# Handle pull request files properly | |
if [ "${{ github.event_name }}" == "pull_request" ]; then | |
pull_number="${{ github.event.number }}" | |
if [ "$pull_number" != "null" ] && [ -n "$pull_number" ]; then | |
url="https://api.github.com/repos/buckaroo-it/Magento2/pulls/${pull_number}/files" | |
echo "Fetching file list: $url" | |
# Save only files still present in the checkout | |
curl -s "$url" \ | |
| jq -r '.[] | select(.status != "removed") | .filename' \ | |
| tee files_changed | |
# Optionally show them (‑r = no run if list is empty) | |
cat files_changed | xargs -r ls -la || echo "Some files may have been moved or renamed" | |
else | |
echo "No valid pull request number, skipping file change detection" | |
touch files_changed | |
fi | |
else | |
echo "Not a pull request, skipping file change detection" | |
touch files_changed | |
fi | |
# Magento auth.json | |
echo '{"http-basic": {"repo.magento.com": {"username": "${{ secrets.REPO_USERNAME }}","password": "${{ secrets.REPO_PASS }}"}}}' > auth.json | |
# Create clean Magento 2.4.8 project with PHP 8.3 (compatible combination) | |
composer create-project --repository-url=https://repo.magento.com/ \ | |
magento/project-community-edition=2.4.8 ~/m248 | |
# Copy module under test into the fresh install | |
mkdir -p ~/m248/app/code/Buckaroo/Magento2/ | |
rsync -r --exclude='m248' ./ ~/m248/app/code/Buckaroo/Magento2/ | |
cd ~/m248 | |
bin/magento module:enable --all | |
bin/magento setup:di:compile | |
# ─────────────────────────────────────────────────────────────── | |
# Static‑analysis tooling | |
# ─────────────────────────────────────────────────────────────── | |
- name: Install PHPStan | |
run: | | |
cd ~/m248 | |
composer require --dev phpstan/phpstan:^1.10 | |
ls -la vendor/bin/ | |
- name: Install Buckaroo SDK | |
run: | | |
cd ~/m248 | |
composer require buckaroo/sdk | |
- name: Run PHPStan | |
run: | | |
cd ~/m248 | |
vendor/bin/phpstan analyse \ | |
--level 1 \ | |
app/code/Buckaroo/Magento2/ \ | |
-c dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon |