Skip to content

πŸš€ A collection of professional reusable GitHub Actions workflows for WordPress and PHP projects. Streamline builds, automated testing (PHPUnit/WPCS), and secure SSH folder synchronization.

Notifications You must be signed in to change notification settings

WritePoetry/reusable-workflows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

74 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Reusable GitHub Actions Workflows

This repository contains multiple reusable GitHub Actions workflows with distinct purposes. Each workflow can be called independently or chained together, depending on the project needs.

Table of Contents


Features

  • Centralized build and release process.
  • Multi-version PHP testing.
  • Safe folder synchronization with configurable mappings.
  • Reusable across multiple projects.

1. Build & Release Workflow

Packages the project into a zip and publishes a GitHub release. Specifically designed for WordPress projects using @wordpress/scripts.

Inputs

Name Description Required Default
output_dir Directory where build artifacts and the zip file are placed No build

Outputs

Name Description
package_file Name of the zip file generated by the build job, used in the release job

Requirements in the Consuming Project

  • npm Scripts: Must include "plugin-zip": "wp-scripts plugin-zip".
  • Dependencies: Requires @wordpress/scripts in devDependencies.
  • Engines: Must specify node and npm versions in package.json.
  • File Selection: The zip contains files declared in the files field of package.json.

Plugin File Naming

The final zip file name is formed as: <package-name>-<version>.zip

  • <package-name>: from name in package.json.
  • <version>: from Git tag (GITHUB_REF_NAME without v).

Usage Example

jobs:
  call_shared_release:
    uses: WritePoetry/reusable-workflows/.github/workflows/release.yml@v1
    with:
      output_dir: 'custom-build-folder'
    permissions:
      contents: write
      packages: read
      actions: read
    secrets: inherit

2. PHP Unit Tests Workflow

Runs PHPUnit tests across multiple PHP versions, with optional WordPress integration testing and coding-standards checks.

Inputs

Name Description Required Default
php_versions JSON array of PHP versions used for matrix testing No ['7.4', '8.0', '8.1', '8.2']
phpunit9_config PHPUnit 9-specific configuration file, used only when detected No phpunit-9.xml

Requirements in the Consuming Project

  • A valid composer.json including PHPUnit (and optionally WPCS).
  • The script bin/install-wp-tests.sh for WordPress integration tests.

Behavior

  • Matrix Testing: Each PHP version runs independently.
  • Database: Spins up MySQL 5.7 and prepares wordpress_test automatically if needed.
  • Multisite: Executes tests in both standard and Multisite (WP_MULTISITE=1) environments.

Usage Example

jobs:
  tests:
    uses: WritePoetry/reusable-workflows/.github/workflows/php-tests.yml@v1
    with:
      php_versions: "['8.1','8.2']"
    secrets: inherit

3. Sync Folders Workflow

Synchronizes selected local directories to a remote server using SSH and rsync. Supports multiple folder mappings through matrix execution.

Inputs

Name Description Required Default
host Remote server host Yes β€”
username SSH username for the remote server Yes β€”
folder Base folder on the remote server where synchronization occurs Yes β€”
paths JSON array of {from, to, exclude} mappings No Default WordPress structure

Secrets

Name Description Required
ssh-key Private SSH key for rsync authentication Yes

Usage Example

jobs:
  deploy_files:
    uses: WritePoetry/reusable-workflows/.github/workflows/sync-folders.yml@v1
    with:
      host: example.com
      username: deploy
      folder: /var/www/html/wp-content
      paths: |
        [
          {"from": "themes", "to": "/themes/"},
          {"from": "plugins", "to": "/plugins/", "exclude": ".git* node_modules"}
        ]
    secrets:
      ssh-key: ${{ secrets.SERVER_SSH_DEPLOY_KEY }}

General Usage Note

You can chain these workflows to create a complete CI/CD pipeline:

jobs:
  run_tests_first:
    uses: WritePoetry/reusable-workflows/.github/workflows/php-tests.yml@v1
    secrets: inherit

  call_shared_release:
    needs: run_tests_first
    uses: WritePoetry/reusable-workflows/.github/workflows/release.yml@v1
    permissions:
      contents: write
      packages: read
      actions: read
    secrets: inherit

Note: Artifacts are transferred between jobs using upload-artifact and download-artifact. Output variables are used only to reference filenames, not to transfer files.

About

πŸš€ A collection of professional reusable GitHub Actions workflows for WordPress and PHP projects. Streamline builds, automated testing (PHPUnit/WPCS), and secure SSH folder synchronization.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published