Skip to content

Commit

Permalink
Integrate with wp-product-info for plugin updates (#179)
Browse files Browse the repository at this point in the history
* test: confirm update callbacks are attached

* chore: Add updater functions

* chore: Add updater callbacks

* chore: add convenience constants used by updater functionality

* chore: load updater files via require_once

* chore: exclude VIP rule for wp_remote_get calls

* chore: coding standards

* chore: add base CircleCI config.

Copied initial setup from the Atlas Headless Extension plugin.

* chore: Remove unused CircleCI config parts

* chore: fix test that checks for active plugin count.

Our integration with the plugin update mechanism outputs a "active" row
to display errors when communicating with wp-product-info. This class is
used by WP to style the update notices to match the table row.

* chore: Add blakewilson/wp-enforce-semver dependency

* chore: Instantiate EnforceSemVer class

* chore: Change support link to GitHub issues

* ci: download latest release zip

* ci: adjust unzip command

* ci: adjust unzip paths

* ci: adjust paths

* ci: mkdir build

* ci: update persist path. Add temp debug info.

* ci: move zip to build dir for later deployment

* ci: add build version to zip file name when moving to build directory

* chore: Customize semver notice text.

Removes link to semver.org.

* test: confirm callback to customize semver notice text is attached.

* chore: add changeset

* ci: update CircleCI config to run deploy jobs on tags
  • Loading branch information
mindctrl authored Feb 21, 2024
1 parent 077f48c commit 9fab724
Show file tree
Hide file tree
Showing 11 changed files with 640 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-geese-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/wp-graphql-content-blocks": minor
---

Added support for automatic updates hosted from WP Engine infrastructure. Includes warnings when major versions with potential breaking changes are released.
163 changes: 163 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Notes:
# - Jobs initially start from /home/circleci/project
# - Plugin located at /home/circleci/project/wp-graphql-content-blocks

version: 2.1

orbs:
php: circleci/[email protected]
wp-product-orb: wpengine/[email protected]
node: circleci/[email protected]

jobs:
plugin-unzip:
executor: wp-product-orb/default
environment:
WPE_SESSION_DIR: ./.wpe
parameters:
slug:
type: string
filename:
type: string
steps:
- attach_workspace:
at: .
- wp-product-orb/variable_load
- run:
name: "Unzip plugin files"
command: |
cd ~/project
mkdir build
curl -sL https://github.com/wpengine/wp-graphql-content-blocks/releases/latest/download/wp-graphql-content-blocks.zip > <<parameters.slug>>.zip
unzip -o -d <<parameters.slug>> <<parameters.slug>>.zip
ls -laR
- wp-product-orb/get_version_from_php:
filename: <<parameters.slug>>/<<parameters.filename>>
return_var: BUILD_VERSION
- wp-product-orb/variable:
var: BUILD_VERSION
value: $BUILD_VERSION
- run:
name: "Move zip file to build directory"
command: |
mv <<parameters.slug>>.zip build/<<parameters.slug>>.$BUILD_VERSION.zip
- run:
name: "DEBUG"
command: |
ls -laR
- persist_to_workspace:
root: .
paths:
- .

plugin-build-json:
executor: wp-product-orb/parser
environment:
WPE_SESSION_DIR: ./.wpe
parameters:
slug:
type: string
steps:
- attach_workspace:
at: .
- run:
command: |
cd ~/project
- wp-product-orb/variable_load
- wp-product-orb/parse_wp_readme:
infile: <<parameters.slug>>/readme.txt
outfile: build/<<parameters.slug>>.$BUILD_VERSION.json
- store_artifacts:
path: build
- run:
name: "DEBUG"
command: |
pwd
ls -laR
- persist_to_workspace:
root: .
paths:
- build

plugin-deploy:
executor: wp-product-orb/authenticate
environment:
WPE_SESSION_DIR: ./.wpe
parameters:
auth_url:
type: string
upload_url:
type: string
slug:
type: string
steps:
- attach_workspace:
at: .
- wp-product-orb/variable_load
- wp-product-orb/authenticate:
user: WPE_LDAP_USER
pass: WPE_LDAP_PASS
url: <<parameters.auth_url>>
- run:
name: "DEBUG"
command: |
pwd
ls -laR
- wp-product-orb/post_zip:
url: <<parameters.upload_url>>/<<parameters.slug>>
zip: build/<<parameters.slug>>.$BUILD_VERSION.zip
json: build/<<parameters.slug>>.$BUILD_VERSION.json
version: $BUILD_VERSION

workflows:
deploy:
jobs:
- plugin-unzip:
slug: wpgraphql-content-blocks
filename: wp-graphql-content-blocks.php
# Run this job when a tag is published.
filters:
branches:
ignore: /.*/
tags:
only: /^v.*/
- plugin-build-json:
slug: wpgraphql-content-blocks
requires:
- plugin-unzip
# Run this job when a tag is published.
filters:
branches:
ignore: /.*/
tags:
only: /^v.*/
- plugin-deploy:
name: "plugin-deploy-staging"
slug: wpgraphql-content-blocks
requires:
- plugin-unzip
- plugin-build-json
filters:
branches:
only:
- main
- canary
tags:
only: /^v.*/
context: wpe-ldap-creds
auth_url: https://auth-staging.wpengine.io/v1/tokens
upload_url: https://wp-product-info-staging.wpesvc.net/v1/plugins
- plugin-deploy:
name: "plugin-deploy-production"
slug: wp-graphql-content-blocks
requires:
- "plugin-deploy-staging"
filters:
branches:
ignore: /.*/
tags:
# Run this job when a tag is published.
only: /^v.*/
context: wpe-ldap-creds
auth_url: https://auth.wpengine.io/v1/tokens
upload_url: https://wp-product-info.wpesvc.net/v1/plugins
1 change: 1 addition & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint" />
<exclude name="WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get" />
</rule>

<!-- Individual rule configuration -->
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"minimum-stability": "dev",
"require": {
"php": ">=7.4",
"imangazaliev/didom": "^2.0"
"imangazaliev/didom": "^2.0",
"blakewilson/wp-enforce-semver": "^2.0"
},
"require-dev": {
"brain/monkey": "^2.6",
Expand Down
108 changes: 106 additions & 2 deletions composer.lock

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

6 changes: 6 additions & 0 deletions includes/WPGraphQLContentBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ static function () {
}//end if
}//end if

require_once WPGRAPHQL_CONTENT_BLOCKS_PLUGIN_DIR . 'includes/updates/update-functions.php';
require_once WPGRAPHQL_CONTENT_BLOCKS_PLUGIN_DIR . 'includes/updates/update-callbacks.php';

// phpcs:ignore SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable -- Library bootstraps itself, hence variable is unused.
$semver = new \EnforceSemVer\EnforceSemVer( WPGRAPHQL_CONTENT_BLOCKS_PATH );

return true;
}

Expand Down
Loading

0 comments on commit 9fab724

Please sign in to comment.