Skip to content

Abilities API

Abilities API #3307

name: Coding Standards
# When to run tests.
on:
pull_request:
types:
- opened
- synchronize
push:
branches:
- main
jobs:
dependabot-metadata:
uses: ./.github/workflows/_dependabot-metadata.yml
secrets: inherit
tests:
# Name.
name: Coding Standards / WordPress ${{ matrix.wp-versions }} / PHP ${{ matrix.php-versions }}
# Virtual Environment to use.
# @see: https://github.com/actions/virtual-environments
runs-on: ubuntu-latest
# Requires the dependabot-metadata job to have run successfully.
needs: [dependabot-metadata]
# Always allow non-Dependabot PRs and pushes.
# For Dependabot PRs, only run when the update is for composer (skip github-actions updates).
if: |
always() &&
(
github.actor != 'dependabot[bot]' ||
needs.dependabot-metadata.outputs.package-ecosystem == 'composer'
)
# Environment Variables.
# Accessible by using ${{ env.NAME }}
# Use ${{ secrets.NAME }} to include any GitHub Secrets in ${{ env.NAME }}
# The base folder will always be /home/runner/work/github-repo-name/github-repo-name
env:
ROOT_DIR: /home/runner/work/convertkit-wordpress/convertkit-wordpress/wordpress
PLUGIN_DIR: /home/runner/work/convertkit-wordpress/convertkit-wordpress/wordpress/wp-content/plugins/convertkit
DB_NAME: test
DB_USER: root
DB_PASS: root
DB_HOST: localhost
INSTALL_PLUGINS: "classic-editor contact-form-7 elementor forminator woocommerce wordpress-seo litespeed-cache w3-total-cache" # Don't include this repository's Plugin here.
# Defines the WordPress and PHP Versions matrix to run tests on.
strategy:
matrix:
wp-versions: [ 'latest' ] #[ '6.1.1', 'latest' ]
php-versions: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ] #[ '7.3', '7.4', '8.0', '8.1' ]
# Steps to install, configure and run tests
steps:
# Checkout Plugin to /home/runner/work/convertkit-wordpress/convertkit-wordpress/convertkit
# We cannot checkout to ${{ env.PLUGIN_DIR }} as GitHub Actions require it be first placed in /home/runner/work/repo/repo
- name: Checkout Plugin
uses: actions/checkout@v7
with:
path: /home/runner/work/convertkit-wordpress/convertkit-wordpress/convertkit
- name: Set up MySQL
uses: ./convertkit/.github/actions/setup-mysql
with:
db-name: ${{ env.DB_NAME }}
db-user: ${{ env.DB_USER }}
db-pass: ${{ env.DB_PASS }}
db-host: ${{ env.DB_HOST }}
- name: Download and Extract WordPress
uses: ./convertkit/.github/actions/download-wordpress
with:
wp-version: ${{ matrix.wp-versions }}
target-dir: ${{ env.ROOT_DIR }}
# This step is deliberate, to force PHP 7.4 for WP-CLI to work.
# PHP 8.x results in the workflow failing due to incompatibilities between WP-CLI and PHP 8.x.
#- name: Install PHP 7.4.26
# uses: shivammathur/setup-php@v2
# with:
# php-version: 7.4.26
# coverage: xdebug
- name: Install WordPress via WP-CLI
uses: ./convertkit/.github/actions/install-wordpress
with:
root-dir: ${{ env.ROOT_DIR }}
db-name: ${{ env.DB_NAME }}
db-user: ${{ env.DB_USER }}
db-pass: ${{ env.DB_PASS }}
db-host: ${{ env.DB_HOST }}
# env.INSTALL_PLUGINS is a list of Plugin slugs, space separated e.g. contact-form-7 woocommerce.
- name: Install Free Third Party WordPress Plugins
working-directory: ${{ env.ROOT_DIR }}
run: wp-cli plugin install ${{ env.INSTALL_PLUGINS }}
# These should be stored as a separated list of URLs in the repository Settings > Secrets > Repository Secret > CONVERTKIT_PAID_PLUGIN_URLS.
# We cannot include the URLs in this file, as they're not Plugins we are permitted to distribute.
- name: Install and Activate Paid Third Party WordPress Plugins
working-directory: ${{ env.ROOT_DIR }}
run: wp-cli plugin install ${{ secrets.CONVERTKIT_PAID_PLUGIN_URLS }} --activate
# Move Plugin to PLUGIN_DIR.
- name: Move Plugin
run: mv /home/runner/work/convertkit-wordpress/convertkit-wordpress/convertkit ${{ env.PLUGIN_DIR }}
# Install PHP version to run coding standards / static analysis against.
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug
tools: cs2pr
# Installs wp-browser, Codeception, PHP CodeSniffer and anything else needed to run tests.
# jq is used to remove the wordpress/mcp-adapter package from composer.json, as it requires PHP 7.4+.
- name: Run Composer
working-directory: ${{ env.PLUGIN_DIR }}
run: |
jq 'del(.require."wordpress/mcp-adapter")' composer.json > composer.json.tmp && mv composer.json.tmp composer.json
composer update
# Installs WordPress scripts for CSS and JS Coding Standards.
- name: Run npm install
working-directory: ${{ env.PLUGIN_DIR }}
run: npm install
# Run PHP Coding Standards on Tests.
- name: Run WordPress PHP Coding Standards on Tests
working-directory: ${{ env.PLUGIN_DIR }}
if: ${{ contains('8.1 8.2 8.3 8.4', matrix.php-versions) }}
run: php vendor/bin/phpcs -q --standard=phpcs.tests.xml --report=checkstyle ./tests | cs2pr
# Run PHP Coding Standards on Plugin.
- name: Run WordPress PHP Coding Standards
working-directory: ${{ env.PLUGIN_DIR }}
run: php vendor/bin/phpcs -q --standard=phpcs.xml --report=checkstyle ./ | cs2pr
# Run CSS Coding Standards on Plugin.
- name: Run WordPress CSS Coding Standards
working-directory: ${{ env.PLUGIN_DIR }}
run: npm run lint:css
# Run JS Coding Standards on Plugin.
- name: Run WordPress JS Coding Standards
working-directory: ${{ env.PLUGIN_DIR }}
run: npm run lint:js
# Run PHPStan for static analysis.
- name: Run PHPStan Static Analysis
working-directory: ${{ env.PLUGIN_DIR }}
run: php vendor/bin/phpstan analyse --memory-limit=1250M