Skip to content

Commit

Permalink
Merge pull request #41 from rokka-io/chore/migrate-to-wp-env
Browse files Browse the repository at this point in the history
feat(): WordPress 6.0 / Use wp-env to run tests
  • Loading branch information
tschortsch authored May 17, 2022
2 parents 9309590 + c753863 commit 5f44972
Show file tree
Hide file tree
Showing 45 changed files with 8,439 additions and 14,410 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
parser: '@babel/eslint-parser',
env: {
browser: true
},
rules: {
quotes: ['error', 'single']
}
}
9 changes: 0 additions & 9 deletions .eslintrc.json

This file was deleted.

125 changes: 54 additions & 71 deletions .github/workflows/lint-test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Use Node.js 16.x
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16.x

Expand All @@ -23,105 +23,93 @@ jobs:
- name: Run linter
run: |
npm run wp-env start
npm run lint
composer lint
tests:
name: Tests

runs-on: ubuntu-latest

env:
WP_VERSION: ${{ matrix.wp-versions }}

services:
mysql:
image: mysql:5.7
ports:
- 3306
env:
MYSQL_DATABASE: wordpress_test
MYSQL_ROOT_PASSWORD: root
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
matrix:
php-versions: [
'5.6',
'7.0',
'7.1',
'7.2',
'7.3'
]
wp-versions: [
'4.0', # Minimum required version
'4.4', # Introduction of Responsive Images
'4.7', # Introduction of REST API
'4.9.18', # Last 4.x version
'5.0', # Introduction of Gutenberg
#'4.7', # Introduction of REST API
#'4.9.20', # Last 4.x version
#'5.0', # Introduction of Gutenberg
'5.3', # Changes in generating srcset
'latest'
'5.9.3' # Latest
]
exclude: # exclude PHP >= 7 and WP 4.0 combinations because of PHP Fatal error: 'break' not in the 'loop' or 'switch' context
- php-versions: 7.0
wp-versions: 4.0
- php-versions: 7.1
wp-versions: 4.0
- php-versions: 7.2
wp-versions: 4.0
- php-versions: 7.3
wp-versions: 4.0
- php-versions: 7.4
wp-versions: 4.0
- php-versions: 7.3
wp-versions: 4.4
- php-versions: 7.3
wp-versions: 4.7
- php-versions: 7.3
wp-versions: 4.9.18

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mysql
- uses: actions/checkout@v3

- name: Use Node.js 16.x
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Install dependencies
run: |
npm ci
composer install
- name: "Install WP specific wp-phpunit version (${{ matrix.wp-versions }})"
run: composer require --dev wp-phpunit/wp-phpunit:${{ matrix.wp-versions }}

- name: Setup WordPress
run: scripts/install-wp-tests.sh wordpress_test root root 127.0.0.1:${{ job.services.mysql.ports['3306'] }} $WP_VERSION
- name: "Configure environment with WP ${{ matrix.wp-versions }}"
run: |
echo -e '{\n\t"core": "WordPress/WordPress#${{ matrix.wp-versions }}"\n}' > ./.wp-env.override.json
- name: Running PHP tests
run: composer test
- name: Install WordPress
run: |
chmod -R 767 ./ # TODO: Possibly integrate in wp-env
npm run wp-env start --debug
- name: Running PHP unit tests
run: npm run test:unit:php:ci

tests-wp-60:
name: Tests WordPress 6.0

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install dependencies
run: |
npm ci
composer install
- name: "Configure environment with WP 6.0"
run: |
echo -e '{\n\t"core": "https://wordpress.org/wordpress-6.0-RC2.zip"\n}' > ./.wp-env.override.json
- name: Install WordPress
run: |
chmod -R 767 ./ # TODO: Possibly integrate in wp-env
npm run wp-env start
- name: Running PHP unit tests
run: npm run test:unit:php:ci

deploy-dry-run:
name: '[DRY RUN] Deploy'

# only run on master but not tags
if: ${{ github.ref == 'refs/heads/master' && !startsWith(github.ref, 'refs/tags/') }}

needs: [ lint, tests ]
needs: [ lint, tests, 'tests-wp-60' ]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.3
- uses: actions/checkout@v3

- shell: bash
env:
Expand All @@ -135,18 +123,13 @@ jobs:
# only run on tags
if: startsWith(github.ref, 'refs/tags/')

needs: [ lint, tests ]
needs: [ lint, tests, 'tests-wp-60' ]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4

- shell: bash
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
.idea/
vendor/
node_modules/
/bin/
/composer.phar
/.cache
/assets/dist/*.map
/release

.parcel-cache/
.wp-env.override.json
5 changes: 0 additions & 5 deletions .postcssrc

This file was deleted.

8 changes: 8 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"core": "https://wordpress.org/wordpress-6.0-RC2.zip",
"phpVersion": "7.1",
"plugins": [ "." ],
"themes": [
"./test-themes/rokka-integration"
]
}
63 changes: 38 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,66 +23,79 @@ Free account plans are available. Just install the plugin, register and use it.

* Node.js >= 16 (https://nodejs.org/)
* gettext (https://www.gnu.org/software/gettext/)
* WordPress >= 4.0
* PHP >= 5.6
* WordPress >= 4.7
* PHP >= 7.1

### Installation

1. Clone this repo

1. Install composer dependencies

```
$ curl -s https://getcomposer.org/installer | php
$ php composer.phar install
```bash
curl -s https://getcomposer.org/installer | php
php composer.phar install
```

1. Install Node dependencies

```
$ npm install
```bash
npm install
```

### Compile assets

$ npm run build
* `npm run dev`: Builds assets in development mode and watches for any changes and reports back any errors in your code.
* `npm run lint`: Lints JavaScript & PHP files.
* `npm run build`: Build production code into `assets/dist` folder.

### Extract messages / Compile translation files

Run the following script to extract messages from PHP-files and generate a new rokka-wordpress-plugin.pot file:
1. To extract the labels and generate the `languages/rokka-integration.pot` file run the following command:

$ scripts/translations/extract_messages.sh
```bash
./scripts/translations/extract-messages.sh
```

Update all .po files with newly extracted messages from .pot file:
2. To update the translation files (`*.po`) run the following command:

$ scripts/translations/update_translation_files.sh
```bash
./scripts/translations/update-translation-files.sh
```

To compile all .po files to .mo files use the following script:
1. To generate the `*.mo` translation files run the following command:

$ scripts/translations/compile_translation_files.sh
```bash
./scripts/translations/compile-translation-files.sh
```

### Unit tests
### Setup local dev environment

To run the unit tests you need to setup your local WordPress testing environment (PHP / MySQL required). Use the following script for this:
The following commands can be used to set up a local dev environment. See the official [documentation of `@wordpress/env`](https://developer.wordpress.org/block-editor/packages/packages-env/#command-reference) for a complete list of commands.

$ scripts/init-unit-test-environment.sh
* `npm run wp-env start`: Starts the Docker containers.
* `npm run wp-env stop`: Stops the Docker containers.

To run the tests use the following script:

$ php composer.phar test
### Unit tests

### Code Sniffer
To run the tests use the following command:

Execute the code sniffer by executing the following command from the plugin root:
```bash
npm run test:unit:php
```

$ php composer.phar lint
or the following command to run a specific test:

Fix the errors in prior to commit. Commit when fixed, so the build will pass on [Travis CI](https://travis-ci.org/rokka-io/rokka-wordpress-plugin).
```bash
npm run test:unit:php -- --filter 'my_test'
```

## Release new plugin version

To release a new version to the WordPress plugin repository use the following script:

$ scripts/deploy-wp-plugin.sh
```bash
./scripts/deploy-wp-plugin.sh
```

This command will automatically release the latest git tag as a version in the plugin repository.
2 changes: 1 addition & 1 deletion assets/dist/admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5f44972

Please sign in to comment.