Skip to content
This repository was archived by the owner on May 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# GitHub Action: whenever creating a new release of the source code,
# also create a release of the installable plugin.
####################################################################################
# GitHub Action:
# Whenever creating a new release of the source code,
# also create a release of the installable plugin,
# and downgrading it from PHP 7.4 to 7.2 to support more users.
####################################################################################
# Steps to execute:
# - Checkout the source code
# - Run "composer install" to download all dependencies under vendor/
# - Run "composer install" for development, to install dependencies for Rector
# - Run Rector to downgrade code from PHP 7.4 to 7.2
# - Run "composer install" for production (required dependencies are already under vendor/)
# - Create a .zip file, excluding:
# - All hidden files (.git, .gitignore, etc)
# - Rector file
# - All development files, ending in .dist
# - All composer files <= after installing dependencies, no need for them anymore
# - Markdown files concerning development
# - Folder build/ <= created only to store the .zip file
# - Folder dev-helpers/ <= not needed for the plugin
# - Upload the .zip file as an artifact to the action (this step is possibly optional)
# - Upload the .zip file as a release, for download
name: Generate Installable Plugin, and Upload as Release Asset
####################################################################################
name: Generate Installable Plugin and Upload as Release Asset
on:
release:
types: [published]
Expand All @@ -23,14 +31,18 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build project
- name: Downgrade code for production (PHP 7.4 to 7.2)
run: |
composer install
vendor/bin/rector process
- name: Build project for production
run: |
composer install --no-dev --optimize-autoloader
mkdir build
- name: Create artifact
uses: montudor/action-zip@v0.1.0
with:
args: zip -X -r build/graphql-api.zip . -x *.git* node_modules/\* .* "*/\.*" CODE_OF_CONDUCT.md CONTRIBUTING.md ISSUE_TEMPLATE.md PULL_REQUEST_TEMPLATE.md *.dist composer.* dev-helpers** build**
args: zip -X -r build/graphql-api.zip . -x *.git* node_modules/\* .* "*/\.*" CODE_OF_CONDUCT.md CONTRIBUTING.md ISSUE_TEMPLATE.md PULL_REQUEST_TEMPLATE.md rector.php *.dist composer.* dev-helpers** build**
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
Expand Down
54 changes: 39 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,56 @@
dist: trusty
########################################################################
# This pipeline is executed on PHP 7.4:
# - required for development
# - required to run Rector, to generate the PHP 7.2-compatible code for production
#
# It uses the Build Environment "Xenial", because it has PHP 7.2 preinstalled,
# so we can switch from the global PHP 7.4 to local PHP 7.2 through `phpenv`
#
# There are 2 parallel executions, with env variable:
# 1. DOWNGRADE_CODE="true"
# 2. DOWNGRADE_CODE="false"
#
# When DOWNGRADE_CODE is "false", it is the standard testing pipeline:
# Execute PHPCS, PHPUnit and PHPStan to check there are no issues, and generate report.
#
# When DOWNGRADE_CODE is "true", it tests the conversion of the PHP code version 7.4 to 7.2:
# - Run Rector to downgrade the code
# - Run PHPStan. If it exits with no errors, then downgrading the code works well.
########################################################################
dist: xenial
language: php

php:
- 7.2
- 7.3
- 7.4
jobs:
include:
- php: 7.4
env: DOWNGRADE_CODE=false
- php: 7.4
env: DOWNGRADE_CODE=true

## Cache composer
cache:
directories:
- $HOME/.composer/cache

## Commented out until version 1.0 (version 0.1.. doesn't follow semver)
# matrix:
# include:
# - php: 7.2
# env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'

before_script:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
# Downgrade the code to PHP 7.2 via Rector
- if [[ "$DOWNGRADE_CODE" == "true" ]]; then vendor/bin/rector process; fi

script:
- vendor/bin/phpcs -n --standard=psr2 src/
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
# Tests only on PHP 7.4
- if [[ "$DOWNGRADE_CODE" != "true" ]]; then vendor/bin/phpcs -n --standard=psr2 src/; fi
- if [[ "$DOWNGRADE_CODE" != "true" ]]; then vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover; fi
# Switch to PHP 7.2 to test if downgraded code works, then up again to 7.4
- if [[ "$DOWNGRADE_CODE" == "true" ]]; then phpenv local 7.2; fi
- if [[ "$DOWNGRADE_CODE" == "true" ]]; then php --version; fi
- vendor/bin/phpstan analyse -c phpstan.neon.dist src
- if [[ "$DOWNGRADE_CODE" == "true" ]]; then phpenv local 7.4; fi
- if [[ "$DOWNGRADE_CODE" == "true" ]]; then php --version; fi

after_script:
- wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover
# Tests only on PHP 7.4
- if [[ "$DOWNGRADE_CODE" != "true" ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi

notifications:
email:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to `graphql-api` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## 0.5.0 - 2020-09-01

### Added

- Code now supports typed properties from PHP 7.4, and it uses Rector to convert it to PHP 7.2 when generating the plugin for production

## 0.4.2 - 2020-08-31

### Fixed
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ GraphQL API is extensible, and ships with the following modules (organized by ca
</tbody>
</table>


## Development

Clone repo, and then install Composer dependencies, by running:
Expand Down Expand Up @@ -207,6 +206,27 @@ This method requires the code for the component to be divided into 2 separate pa
- A CMS-agnostic package, containing the business code and generic contracts, but without using any WordPress code (eg: [posts](https://github.com/PoPSchema/posts))
- A CMS-specific package, containing the implementation of the contracts for WordPress (eg: [posts-wp](https://github.com/PoPSchema/posts-wp))

## PHP versions

Allowed PHP code:

- PHP 7.2
- Typed properties from PHP 7.4

The code can be downgraded from PHP 7.4 to PHP 7.2 to run in production:

| | Development | Production |
| --- | --- | --- |
| **Min PHP version** | 7.4 | 7.2 (After removing typed properties) |

### Downgrading PHP code

Dry run to downgrade the code, via [Rector](https://github.com/rectorphp/rector):

```bash
composer downgrade-code
```

## Resources

The following videos show several features:
Expand Down
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "~7.2",
"php": "~7.4",
"erusev/parsedown": "^1.7",
"pop-schema/generic-customposts": "dev-master",
"pop-schema/commentmeta-wp": "dev-master",
Expand All @@ -47,9 +47,12 @@
"wikimedia/composer-merge-plugin": "^1.4"
},
"require-dev": {
"phpunit/phpunit": ">=8.5",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": ">=9.3",
"rector/rector": "^0.7.65",
"squizlabs/php_codesniffer": "^3.0",
"szepeviktor/phpstan-wordpress": "^0.6.2"
"szepeviktor/phpstan-wordpress": "^0.6.2",
"johnpbloch/wordpress": ">=5.5"
},
"repositories": [
{
Expand All @@ -71,9 +74,11 @@
"test": "phpunit",
"check-style": "phpcs src tests",
"fix-style": "phpcbf src tests",
"analyse": "phpstan analyse -c phpstan.neon.dist"
"analyse": "phpstan analyse -c phpstan.neon.dist",
"downgrade-code": "rector process --dry-run"
},
"extra": {
"wordpress-install-dir": "vendor/wordpress/wordpress",
"branch-alias": {
"dev-master": "1.0-dev"
},
Expand Down
Loading