Skip to content

Port CI/CD, testing, and robustness features from CHIP for Gravity Forms #33

Port CI/CD, testing, and robustness features from CHIP for Gravity Forms

Port CI/CD, testing, and robustness features from CHIP for Gravity Forms #33

Workflow file for this run

name: WordPress Plugin Check
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Tier 1: Build + PHP compatibility (run in parallel)
build:
name: Build Plugin
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Prepare plugin folder for CI
run: |
mkdir -p ci-build/chip-for-givewp
git archive HEAD | tar -x -C ci-build/chip-for-givewp
echo "✅ Plugin folder prepared"
ls -la ci-build/chip-for-givewp/
- name: Upload build artifact
uses: actions/upload-artifact@v7
with:
name: chip-for-givewp-build
path: ci-build/
retention-days: 5
php-compatibility:
name: PHP ${{ matrix.php-version }} Compatibility
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.2', '8.4', '8.5']
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
- name: Install PHPCompatibility
run: |
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --dev squizlabs/php_codesniffer dealerdirect/phpcodesniffer-composer-installer phpcompatibility/phpcompatibility-wp:"*"
echo "$(composer global config bin-dir --absolute)" >> $GITHUB_PATH
- name: Verify PHPCS Standards
run: phpcs -i
- name: Check PHP ${{ matrix.php-version }} Compatibility
run: |
phpcs --standard=PHPCompatibilityWP --runtime-set testVersion ${{ matrix.php-version }} --extensions=php --ignore=vendor,node_modules,assets .
phpunit:
name: PHPUnit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
tools: phpunit
- name: Install Composer dependencies
run: composer install --no-interaction --prefer-dist
- name: Run PHPUnit
run: phpunit
# Tier 2: PHPCS (depends on nothing, runs in parallel)
phpcs:
name: PHP CodeSniffer (WordPress Standards)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
- name: Install WordPress Coding Standards
run: |
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --dev squizlabs/php_codesniffer dealerdirect/phpcodesniffer-composer-installer wp-coding-standards/wpcs:"^3.0"
echo "$(composer global config bin-dir --absolute)" >> $GITHUB_PATH
- name: Verify PHPCS Standards
run: phpcs -i
- name: Run PHPCS
run: phpcs --standard=phpcs.xml .
continue-on-error: false
# Tier 3: Plugin Check (needs build artifact)
# Manual wp-env approach — upstream plugin-check-action is broken (#579).
plugin-check:
name: Plugin Check
runs-on: ubuntu-latest
needs: [build, php-compatibility, phpcs, phpunit]
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Download build artifact
uses: actions/download-artifact@v8
with:
name: chip-for-givewp-build
path: ./build
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
- name: Install @wordpress/env
run: npm install -g @wordpress/env
- name: Create wp-env override for CI
run: |
cat > .wp-env.override.json <<'JSONEOF'
{
"core": null,
"plugins": [
"https://downloads.wordpress.org/plugin/give.zip",
"https://downloads.wordpress.org/plugin/plugin-check.zip"
],
"mappings": {
"wp-content/plugins/chip-for-givewp": "./build/chip-for-givewp"
}
}
JSONEOF
cat .wp-env.override.json
- name: Start WordPress environment
run: |
npx wp-env start --update
# Give containers time to stabilize
sleep 10
- name: Activate Plugin Check
run: |
npx wp-env run cli wp plugin activate plugin-check
- name: Run Plugin Check
run: |
# Run plugin check and output JSON for parsing.
# Ignore trademarked_term: the plugin name "CHIP for GiveWP" and slug "chip-for-givewp"
# contain "wp" which is already published on WordPress.org and cannot be changed.
# wp-env run cli prepends status text to stdout; filter only JSON lines.
npx wp-env run cli wp plugin check chip-for-givewp \
--format=json \
--ignore-codes=trademarked_term \
| grep -E '^\[|^\{' > /tmp/plugin-check-results.json
# Display results in a readable table format.
npx wp-env run cli wp plugin check chip-for-givewp \
--ignore-codes=trademarked_term
# Parse JSON to count errors and warnings.
ERRORS=$(jq '[.[] | select(.type == "ERROR")] | length' /tmp/plugin-check-results.json)
WARNINGS=$(jq '[.[] | select(.type == "WARNING")] | length' /tmp/plugin-check-results.json)
echo ""
echo "═══════════════════════════════════════"
echo " Plugin Check Summary"
echo "═══════════════════════════════════════"
echo " Errors: ${ERRORS}"
echo " Warnings: ${WARNINGS}"
if [ "${ERRORS}" -gt 0 ] || [ "${WARNINGS}" -gt 0 ]; then
echo ""
echo "❌ Plugin Check failed with ${ERRORS} error(s) and ${WARNINGS} warning(s)"
exit 1
fi
echo ""
echo "✅ Plugin Check passed (no errors or warnings)"
- name: Stop WordPress environment
if: always()
run: npx wp-env stop