Skip to content

Commit

Permalink
Merge pull request #110 from thefrosty/develop
Browse files Browse the repository at this point in the history
v3.0
  • Loading branch information
thefrosty authored Feb 17, 2023
2 parents 07b14ed + 27f7900 commit 2680800
Show file tree
Hide file tree
Showing 15 changed files with 480 additions and 294 deletions.
70 changes: 70 additions & 0 deletions .github/actions/ci-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CI Setup
description: "Sets up the environment for jobs during CI workflow"
# https://alejandrocelaya.blog/2022/08/19/how-to-reduce-duplication-in-your-github-actions-workflows/

inputs:
extensions:
default: 'curl, mysql, zip'
description: 'shivammathur/setup-php extensions'
required: false
extensions-cache-key:
description: 'The key used to cache PHP extensions'
required: true
php-version:
description: 'The PHP version to be setup'
required: true
token:
description: 'A GitHub PAT'
required: true
tools:
default: 'composer'
description: 'shivammathur/setup-php tools'
required: false
outputs:
files:
description: 'All changed files'
value: ${{ steps.files.outputs.all }}

runs:
using: composite
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup cache extensions
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ inputs.php-version }}
extensions: ${{ inputs.extensions }}
key: ${{ inputs.extensions-cache-key }}

- name: Cache extensions
uses: actions/cache@v3
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
coverage: xdebug
extensions: ${{ inputs.extensions }}
tools: ${{ inputs.tools }}

- name: Composer config
run: |
composer config github-oauth.github.com "${{ env.GITHUB_TOKEN }}"
env:
GITHUB_TOKEN: ${{ inputs.token }}
shell: bash

- name: Composer update
run: composer update --no-interaction --optimize-autoloader
shell: bash

- name: Get Changed Files
id: files
uses: masesgroup/retrieve-changed-files@v2
137 changes: 107 additions & 30 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,140 @@
name: Workflow
name: CI Tests

on:
push:
branches:
- develop
pull_request:

env:
WP_VERSION: 6.1.1

# 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:
Build:
run-phpcs:
name: Run PHPCS
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
strategy:
matrix:
php-versions: [ 7.4, 8.0, 8.1 ]
coverage: [ true ]

php-version: [ "8.0", "8.1", "8.2" ]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # No shallow clone, we need all history!
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup
id: ci-setup
uses: ./.github/actions/ci-setup
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug
tools: composer, cs2pr, phpunit
extensions: 'curl'
extensions-cache-key: run-phpcs-${{ matrix.php-version }}
php-version: ${{ matrix.php-version }}
token: ${{ secrets.GITHUB_TOKEN }}
tools: 'composer, cs2pr, phpcs'

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Run PHPCS
continue-on-error: false
id: phpcs
run: composer phpcs
env:
CHANGED_FILES: ${{ steps.ci-setup.outputs.files }}
PHP_VERSION: ${{ matrix.php-version }}

- name: Cache dependencies
uses: actions/cache@v2
- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml

run-phpmd:
name: Run PHPMD
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
strategy:
matrix:
php-version: [ "8.0", "8.1", "8.2" ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
id: ci-setup
uses: ./.github/actions/ci-setup
with:
path: ${{ steps.composercache.outputs.dir }}
key: php-${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
extensions: 'curl'
extensions-cache-key: run-phpunit-${{ matrix.php-version }}
php-version: ${{ matrix.php-version }}
token: ${{ secrets.GITHUB_TOKEN }}
tools: 'composer, phpmd'

- name: Run PHPMD
continue-on-error: true
id: phpmd
run: composer phpmd
env:
CHANGED_FILES: ${{ steps.ci-setup.outputs.files }}

- name: Install dependencies
run: composer update --prefer-dist --no-interaction
run-phpunit:
name: Run PHPUnit
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
strategy:
matrix:
php-version: [ "8.0", "8.1", "8.2" ]
coverage: [ true ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Create all branches
run: source ./bin/create-all-branches.sh
- name: Setup
id: ci-setup
uses: ./.github/actions/ci-setup
with:
extensions: 'curl, mysql, mysqli, tar, zip'
extensions-cache-key: run-phpunit-${{ matrix.php-version }}
php-version: ${{ matrix.php-version }}
token: ${{ secrets.GITHUB_TOKEN }}
tools: 'composer, phpunit'

- name: Run composer tests
- name: Run PHPUnit
continue-on-error: false
run: composer tests

- name: Show PHPCS results in PR
run: cs2pr ./phpcs-report.xml
id: phpunit
run: composer phpunit
env:
CHANGED_FILES: ${{ steps.ci-setup.outputs.files }}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false

run-phpstan:
name: Run PHPStan
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
strategy:
matrix:
php-version: [ "8.0", "8.1", "8.2" ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
id: ci-setup
uses: ./.github/actions/ci-setup
with:
extensions: 'curl'
extensions-cache-key: run-phpunit-${{ matrix.php-version }}
php-version: ${{ matrix.php-version }}
token: ${{ secrets.GITHUB_TOKEN }}
tools: 'composer, phpstan'

- name: Run PHPStan
continue-on-error: true
id: phpstan
run: composer phpstan
env:
CHANGED_FILES: ${{ steps.ci-setup.outputs.files }}
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ A library containing my standard development resources to build high quality Wor
### Requirements

```
PHP >= 7.4 OR >= 8.0
WordPress >= 5.6
PHP >= 8.0
WordPress >= 6.0
```

| PHP version | WordPress Utilities |
| ----------- | ------------------- |
| < 7.1 | 1.3.x |
| \>= 7.1 && < 7.3 | 1.9.x |
| 7.3 | 2.0.0 |
| \>= 7.4 | 2.1.0 |
| PHP version | WP Utilities |
|------------------|--------------|
| < 7.1 | 1.3.x |
| \>= 7.1 && < 7.3 | 1.9.x |
| 7.3 | 2.0.0 |
| \>= 7.4 | 2.1.0 |
| \>= 8.0 | 3.0 |

The required WordPress version will always be the most recent point release of
the previous major release branch.
Expand All @@ -38,7 +39,7 @@ compatibility is entirely coincidental.
To install this library, use Composer:

```
composer require thefrosty/wp-utilities:^2.7
composer require thefrosty/wp-utilities:^3.0
```

Then follow examples in the [Plugin README](./src/Plugin/README.md)
40 changes: 22 additions & 18 deletions bin/create-all-branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@ set -e

# https://stackoverflow.com/a/44036486/558561
function create_all_branches() {
# Keep track of where Travis put us.
# We are on a detached head, and we need to be able to go back to it.
local build_head
build_head=$(git rev-parse HEAD)
# Keep track of where Travis put us.
# We are on a detached head, and we need to be able to go back to it.
local build_head
build_head=$(git rev-parse HEAD)

# Fetch all the remote branches. Travis clones with `--depth`, which
# implies `--single-branch`, so we need to overwrite remote.origin.fetch to
# do that.
git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
git fetch
# optionally, we can also fetch the tags
git fetch --tags
# Fetch all the remote branches. Travis clones with `--depth`, which
# implies `--single-branch`, so we need to overwrite remote.origin.fetch to
# do that.
git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
git fetch --prune
# optionally, we can also fetch the tags, pass `true` to the function call.
if [[ $# -eq 1 ]]; then
git fetch --tags
fi

# create the tacking branches
for branch in $(git branch -r | grep -v HEAD); do
git checkout -qf "${branch#origin/}"
done
# create the tacking branches
for branch in $(git branch -r | grep -v HEAD); do
git checkout -qf "${branch#origin/}"
done

# finally, go back to where we were at the beginning
git checkout "${build_head}"
# finally, go back to where we were at the beginning
git checkout "${build_head}"
}

create_all_branches
if [[ -n "$CI" ]]; then
create_all_branches "$@"
fi;
6 changes: 4 additions & 2 deletions bin/eslint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

echo 'Checking ESLint'
source "$(dirname "$0")/functions.sh"
echo 'Checking ESLint'

jsFiles=""
jsFilesCount=0
Expand All @@ -21,6 +21,8 @@ if [[ ${jsFilesCount} == 0 ]]; then
exit 0
fi

jsFiles=$(echo "${jsFiles}" | xargs)
echo "Checking files: $jsFiles"

npx standard "${jsFiles}"
# shellcheck disable=SC2086
npx standard ${jsFiles}
Loading

0 comments on commit 2680800

Please sign in to comment.