Skip to content

Commit

Permalink
added - workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveJonesDev committed Feb 1, 2024
1 parent ee43d3d commit e71969c
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CS

on:
# Run on all pushes (except to main) and on all pull requests.
push:
branches:
- '*'
pull_request:
branches:
- '*'
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
checkcs:
name: 'Check code style'
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run custom composer script
run: ./run-composer.sh

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: cs2pr

# Validate the composer.json file.
# @link https://getcomposer.org/doc/03-cli.md#validate
- name: Validate Composer installation
run: composer validate --no-check-all

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
# Bust the cache at least once a month - output format: YYYY-MM-DD.
custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")

# Check the codestyle of the files.
# The results of the CS check will be shown inline in the PR via the CS2PR tool.
# @link https://github.com/staabm/annotate-pull-request-from-checkstyle/
- name: Check PHP code style
id: phpcs
run: composer check-cs -- --report-full --report-checkstyle=./phpcs-report.xml --ignore=vendor

- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml
37 changes: 37 additions & 0 deletions .github/workflows/lint-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Lint JS

on:
# Run on pushes to select branches and on all pull requests.
push:
branches:
- main
- develop
- trunk
- 'feature/**'
- 'release/**'
- 'hotfix/[0-9]+.[0-9]+*'
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest

name: "Lint: JS"

steps:
- name: Checkout code
uses: actions/checkout@v3

# The lint stage doesn't run the unit tests or use code style, so no need for PHPUnit, WPCS or phpcompatibility.
- name: 'Install NPM packages'
run: npm install
- name: 'Run ESLint'
run: npm run lint:js
72 changes: 72 additions & 0 deletions .github/workflows/lint-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Lint PHP

on:
# Run on pushes to select branches and on all pull requests.
push:
branches:
- master
- develop
- trunk
- 'feature/**'
- 'release/**'
- 'hotfix/[0-9]+.[0-9]+*'
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest

strategy:
matrix:
# Lint against the highest/lowest supported versions of each PHP major.
# And also do a run against "nightly" (the current dev version of PHP).
php_version: ['7.4', '8.0', '8.1', '8.2']

name: "Lint: PHP ${{ matrix.php_version }}"

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install PHP for the composer install
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none

# The lint stage doesn't run the unit tests or use code style, so no need for PHPUnit, WPCS or phpcompatibility.
- name: 'Composer: adjust dependencies - remove PHPUnit'
run: composer remove --no-update --dev phpunit/phpunit --no-scripts --no-interaction
- name: 'Composer: adjust dependencies - remove Yoast test urils'
run: composer remove --no-update --dev yoast/wp-test-utils --no-scripts --no-interaction
- name: 'Composer: adjust dependencies - remove PHPCompatibility'
run: composer remove --no-update --dev phpcompatibility/phpcompatibility-wp --no-scripts --no-interaction
- name: 'Composer: adjust dependencies - remove WPCS'
run: composer remove --no-update --dev wp-coding-standards/wpcs --no-scripts --no-interaction

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
# Bust the cache at least once a month - output format: YYYY-MM-DD.
custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")

- name: Install PHP for the actual test
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: none
tools: cs2pr

- name: Lint against parse errors
run: composer lint -- --checkstyle | cs2pr
90 changes: 90 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Test

on:
# Run on pushes to select branches and on all pull requests.
push:
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
integration:
runs-on: ubuntu-latest

strategy:
matrix:
include:
- php_version: '8.1'
wp_version: '6.2'
multisite: false

- php_version: '8.1'
wp_version: 'latest'
multisite: false

- php_version: '8.1'
wp_version: 'latest'
multisite: true

- php_version: '8.2'
wp_version: 'latest'
multisite: true

name: "Integration Test: PHP ${{ matrix.php_version }} | WP ${{ matrix.wp_version }}${{ matrix.multisite == true && ' (+ ms)' || '' }}"

# Allow builds to fail on as-of-yet unreleased WordPress versions.
continue-on-error: ${{ matrix.wp_version == 'trunk' }}

services:
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: none

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: "Composer: remove the PHP platform requirement"
run: composer config --unset platform.php

- name: "Install Composer dependencies"
uses: ramsey/composer-install@v2
with:
# Force a `composer update` run.
dependency-versions: "highest"
# But make it selective.
composer-options: "yoast/wp-test-utils --with-dependencies"
# Bust the cache at least once a month - output format: YYYY-MM-DD.
custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")

- name: Install WP
shell: bash
run: tests/bin/install-wp-tests.sh wordpress_tests root '' 127.0.0.1:3306 ${{ matrix.wp_version }}

- name: Run unit tests - single site
run: composer test

- name: Run unit tests - multisite
if: ${{ matrix.multisite == true }}
run: composer test
env:
WP_MULTISITE: 1
34 changes: 34 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Security

on:
# Run on all pushes and on all pull requests.
push:
pull_request:
# Also run this workflow every Monday at 6:00.
schedule:
- cron: '0 6 * * 1'
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
security:
name: 'Security check'
runs-on: ubuntu-latest

# Don't run the cronjob in this workflow on forks.
if: github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'Yoast')

steps:
- name: Checkout code
uses: actions/checkout@v3

# This action checks the `composer.lock` file against known security vulnerabilities in the dependencies.
# https://github.com/marketplace/actions/the-php-security-checker
- name: Run Security Check
uses: symfonycorp/security-checker-action@v5

0 comments on commit e71969c

Please sign in to comment.