-
Notifications
You must be signed in to change notification settings - Fork 382
Engineering Guidelines
To contribute to this plugin, you need the following tools installed on your computer:
- Composer - to install PHP dependencies.
- Node.js - to install JavaScript dependencies.
- WordPress - to run the actual plugin.
You should be running a Node version matching the current active LTS release or newer for this plugin to work correctly. You can check your Node.js version by typing node -v in the Terminal prompt.
If you have an incompatible version of Node in your development environment, you can use nvm to change node versions on the command line:
nvm installSince you need a WordPress environment to run the plugin in, the quickest way to get up and running is to use the provided Docker setup. Install Docker and Docker Compose by following the instructions on their website.
You can then clone this project somewhere on your computer:
git clone [email protected]:ampproject/amp-wp.git amp
cd ampIf you'd like to checkout the most recent stable release tag instead of develop, you can do this:
git fetch --tags
git checkout $(git tag --sort=-v:refname | grep -v '-' | head -n 1)After that, run a script to set up the local environment. It will automatically verify whether Docker, Composer and Node.js are configured properly and start the local WordPress instance. You may need to run this script multiple times if prompted.
./bin/local-env/start.shIf everything was successful, you'll see this on your screen:
Welcome to...
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMWNXK0OOkkkkOO0KXNWMMMMMMMMMMMMMMMM
MMMMMMMMMMMMWX0kdlc:::::::::::ccodk0NWMMMMMMMMMMMM
MMMMMMMMMWXOdl::::::::::::::::::::::lx0NMMMMMMMMMM
MMMMMMMWKxl::::::::::::::::::::::::::::oOXWMMMMMMM
MMMMMMXkl:::::::::::::::::col::::::::::::oONMMMMMM
MMMMW0o:::::::::::::::::ox0Xk:::::::::::::cxXWMMMM
MMMW0l:::::::::::::::::dKWWXd:::::::::::::::dXMMMM
MMW0l::::::::::::::::cxXWMM0l::::::::::::::::dXMMM
MMXd::::::::::::::::ckNMMMWkc::::::::::::::::ckWMM
MWOc:::::::::::::::lONMMMMNkooool:::::::::::::oXMM
MWk:::::::::::::::l0WMMMMMMWNWNNOc::::::::::::l0MM
MNx::::::::::::::oKWMMMMMMMMMMW0l:::::::::::::cOWM
MNx:::::::::::::oKWWWMMMMMMMMNOl::::::::::::::c0MM
MWOc::::::::::::cddddxKWMMMMNkc:::::::::::::::oKMM
MMXd:::::::::::::::::l0MMMMXdc:::::::::::::::ckWMM
MMW0l::::::::::::::::dXMWWKd:::::::::::::::::oXMMM
MMMWOl:::::::::::::::kWW0xo:::::::::::::::::oKWMMM
MMMMW0l:::::::::::::l0NOl::::::::::::::::::dKWMMMM
MMMMMWKdc:::::::::::cooc:::::::::::::::::lkNMMMMMM
MMMMMMMN0dc::::::::::::::::::::::::::::lxKWMMMMMMM
MMMMMMMMMWKxoc::::::::::::::::::::::coOXWMMMMMMMMM
MMMMMMMMMMMWNKkdoc:::::::::::::cloxOKWMMMMMMMMMMMM
MMMMMMMMMMMMMMMWNX0OkkxxxxxxkO0KXWWMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
The WordPress installation should be available at http://localhost:8890 (Username: admin, Password: password).
To later turn off the local environment, you can run:
npm run env:stopTo bring it back later, run:
npm run env:startAlso, if you need to reset the local environment's database, you can run:
npm run env:reset-siteAlternatively, you can use your own local WordPress environment and clone this repository right into your wp-content/plugins directory.
cd wp-content/plugins && git clone [email protected]:ampproject/amp-wp.git ampThen install the packages:
composer install
npm installAnd lastly, do a build of the JavaScript:
npm run build:jsLastly, to get the plugin running in your WordPress install, run composer install and then activate the plugin via the WordPress dashboard or wp plugin activate amp.
Whether you use the pre-existing local environment or a custom one, any PHP code changes will be directly visible during development.
However, for JavaScript this involves a build process. To watch for any JavaScript file changes and re-build it when needed, you can run the following command:
npm run devThis way you will get a development build of the JavaScript, which makes debugging easier.
To get a production build, run:
npm run build:jsThe branching strategy follows the GitFlow schema; make sure to familiarize yourself with it.
All branches are named with with the following pattern: {type}/{issue_id}-{short_description}
-
{type}= issue Type label -
{issue_id}= issue ID -
{short_description}= short description of the PR
To include your changes in the next patch release (e.g. 1.0.x), please base your branch off of the current release branch (e.g. 1.0) and open your pull request back to that branch. If you open your pull request with the develop branch then it will be by default included in the next minor version (e.g. 1.x).
All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult GitHub Help for more information on using pull requests.
All contributions to this project will be checked against WordPress-Coding-Standards with PHPCS, and for JavaScript linting is done with ESLint.
To verify your code meets the requirements, you can run npm run lint.
You can also install a pre-commit hook via:
echo -n "set -e; composer run-script pre-commit" > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commitOr if running inside Lando:
echo -n "set -e; lando composer run-script pre-commit" > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commitThis way, your code will be checked automatically before committing any changes.
The AMP plugin uses the PHPUnit testing framework to write unit and integration tests for the PHP part.
To run the full test suite, you can use the following command:
npm run test:phpYou can also just run test for a specific function or class by using something like this:
npm run test:php -- --filter=AMP_Theme_SupportSee npm run test:php:help to see all the possible options.
Jest is used as the JavaScript unit testing framework.
To run the full test suite, you can use the following command:
npm run test:jsYou can also watch for any file changes and only run tests that failed or have been modified:
npm run test:js:watchSee npm run test:js:help to get a list of additional options that can be passed to the test runner.
This project leverages the local Docker-based environment to facilitate end-to-end (e2e) testing using Puppeteer.
To run the full test suite, you can use the following command:
npm run test:e2eYou can also watch for any file changes and only run tests that failed or have been modified:
npm run test:e2e:watchNot using the built-in local environment? You can also pass any other URL to run the tests against. Example:
npm run test:e2e -- --wordpress-base-url=https://my-amp-dev-site.localFor debugging purposes, you can also run the E2E tests in non-headless mode:
npm run test:e2e:interactiveNote that this will also slow down all interactions during tests by 80ms. You can control these values individually too:
PUPPETEER_HEADLESS=false npm run test:e2e # Interactive mode, normal speed.
PUPPETEER_SLOWMO=200 npm run test:e2e # Headless mode, slowed down by 200ms.Sometimes one might want to test additional scenarios that aren't possible in a WordPress installation out of the box. That's why the test setup allows for for adding some utility plugins that can be activated during E2E tests.
For example, such a plugin could create a custom post type and the accompanying E2E test would verify that block validation errors are shown for this custom post type too.
These plugins can be added to tests/e2e/plugins and then activated via the WordPress admin.
The following script creates a post in order to test support for WordPress media and embeds. To run it:
-
sshinto an environment like VVV -
cdto the root of this plugin - run
wp eval-file bin/create-embed-test-post.php - go to the URL that is output in the command line
The following script adds an instance of every default WordPress widget to the first registered sidebar. To run it:
-
sshinto an environment like VVV -
cdto the root of this plugin - run
wp eval-file bin/add-test-widgets-to-sidebar.php - There will be a message indicating which sidebar has the widgets. Please visit a page with that sidebar.
The following script creates a post with comments in order to test support for WordPress comments. To run it:
-
sshinto an environment like VVV -
cdto the root of this plugin - run
wp eval-file bin/create-comments-on-test-post.php - go to the URL that is output in the command line
The following script creates a post with all core Gutenberg blocks. To run it:
-
sshinto an environment like VVV -
cdto the root of this plugin - run
bash bin/create-gutenberge-test-post.sh - go to the URL that is output in the command line
The file class-amp-allowed-tags-generated.php has the AMP specification's allowed tags and attributes. It's used in sanitization.
To update that file, perform the following steps:
-
cdto the root of this plugin - Run
./bin/amphtml-update.sh(orlando ssh -c './bin/amphtml-update.sh'if using Lando). - Review the diff.
- Update tests based on changes to the spec.
- Commit changes.
This script is intended for a Linux environment like VVV or Lando wordpressdev.
To create a build of the plugin for installing in WordPress as a ZIP package, run:
npm run build:prodThis will create an amp.zip in the plugin directory which you can install. The contents of this ZIP are also located in the build directory which you can rsync somewhere as well if needed.
You can also build the plugin in development mode (for unminified scripts and styles):
npm run build:devUse these icons to categorize changelog line items, as done by AMP core:
- ✨ New feature
- 🐛 Bug fix
- 🔥 P0 fix
- ✅ Tests
- ❄️ Flaky tests
- 🚀 Performance improvements
- 🖍 CSS / Styling
- ♿ Accessibility
- 🌐 Internationalization
- 📖 Documentation
- 🏗 Infrastructure / Tooling / Builds / CI
- ⏪ Reverting a previous change
- ♻️ Refactoring
- 🚮 Deleting code
- Create changelog draft on Wiki page.
- Check out the branch intended for release (
developfor major,x.yfor minor) and pull latest commits. - Bump plugin versions in
amp.php(2×: the metadata block in the header and also theAMP__VERSIONconstant). Commit and push. - Wait for the GitHub actions to create new build ZIPs for the branch. Alternatively, you may create the build ZIP yourself:
- Do
npm install && composer selfupdate && composer install -o. - Do
npm run build:prod.
- Do
- Install the
amp.ziponto a normal WordPress install running a stable release build; do smoke test to ensure it works. -
Draft new release on GitHub targeting the required branch (
developfor major,x.yfor minor).- Use the new plugin version as the tag (e.g.
1.2-beta3or1.2.1-RC1) - Use new version as the title, followed by some highlight tagline of the release.
- Attach the
amp.zipbuild to the release. - Add changelog entry to the release, link to compare view comparing previous release, and link to milestone.
- Make sure “Pre-release” is checked.
- Use the new plugin version as the tag (e.g.
- Verify the release branch has the pushed commit! Double check Travis.
- Publish GitHub release.
- (Deprecated?) Create built release tag (from the just-created
builddirectory):- Do
git fetch origin --tags && ./bin/tag-built.sh - Add link from release notes.
- Do
- Make announcements on Twitter and the #amp-wp channel on AMP Slack, linking to release post or GitHub release.
- Bump version in release branch, e.g.
…-alphato…-beta1and…-beta2to…-RC1
Contributors who want to make a new release, follow these steps:
- Copy these instructions into a Google Doc and share with those doing the release.
- Create changelog draft on Wiki page.
- Gather props list of the entire release, including contributors of code, design, testing, project management, etc.
- Update readme including the description, contributors, and screenshots (as needed).
- For major release, draft blog post about the new release.
- For minor releases, make sure all merged commits in
develophave been also merged onto release branch.- To open all PRs that have been merged into the
1.5branch since the1.5.3release:for num in $(git log 1.5.3...origin/1.5 --oneline | ack '(?<=#)\d+' -o | sort | uniq); do open "https://github.com/ampproject/amp-wp/issues/$num"; done - Make sure all milestoned issues and PRs match this set:
git log 1.5.3...origin/1.5 --oneline | ack '(?<=#)\d+' -o | sort | uniq > prs-from-branch.txt diff prs-from-gh.txt prs-from-branch.txt
- Make sure there are no duplicate entries by selecting the changelog contents and doing:
pbpaste | ack '(?<=/)\d+' -o | sort | uniq -c. - Make sure the issues in the changelog match the issues in the milestone.
- To open all PRs that have been merged into the
- Check out the branch intended for release (
developfor major,x.yfor minor) and pull latest commits. - (Obsolete?) Delete the
assetsdirectory and re-checkout from Git to ensure that orphaned build files are removed. - (Maybe) Do
npm install && composer selfupdate && composer install --no-interaction && npm run build:prod. - Update metadata:
- Bump plugin versions in
amp.php(×2: the metadata block in the header and also theAMP__VERSIONconstant). Verify vianpx grunt shell:verify_matching_versions. Ensure patch version number is supplied for major releases, so1.2-RC1should bump to1.2.0. Commit and push. - Ensure "Tested Up To" is updated to current WordPress version.
- Re-run
wp amp docs generate --format=markdown . docs && wp amp docs generate --format=json . docsand commit any docs updates. - Commit.
- Bump plugin versions in
- Do
npm install && composer selfupdate && composer install --no-interaction && npm run build:prod. - Install the
amp.ziponto a normal WordPress install running a stable release build; do smoke test to ensure it works. - Optionally do sanity check by comparing the
builddirectory with the previously-deployed plugin on WordPress.org for example:svn export https://plugins.svn.wordpress.org/amp/trunk /tmp/amp-trunk; diff /tmp/amp-trunk/ ./build/(instead of straightdiff, it's best to use a GUI likeidea diff,phpstorm diff, oropendiff). -
Draft new release on GitHub targeting the required branch (
developfor major,x.yfor minor):- Use the new plugin version as the tag (e.g.
1.2.0or1.2.1) - Attach the
amp.zipbuild to the release. - Add changelog entry to the release and link to compare view comparing previous release.
- Use the new plugin version as the tag (e.g.
- Verify the release branch has the pushed commit! Double check Travis.
- Publish GitHub release.
- Run
npm run deployto commit the plugin to WordPress.org. - Open confirmation email.
- Click view changes and compare SVN diff with previous release.
- Confirm the release.
- Confirm the release is available on WordPress.org; try installing it on a WordPress install and confirm it works.
- Create built release tag (from the just-created
builddirectory):- Do
git fetch origin --tags && ./bin/tag-built.sh - Add link from release notes.
- Do
- For new major releases, create a release branch from the tag. Patch versions are made from the release branch.
- Bump version in release branch. After major release (e.g.
1.2.0), bump to1.3.0-alphaondevelop; after minor release (e.g.1.2.1) bump version to1.2.2-alphaon the release branch. - Update docs on
amp-wp.org, where$versionis the version that was just released:terminus remote:wp wordpress-amp.live -- docs generate --version=$version | cat - - Update
developbranch:- Re-run
npm install && composer install && npm run dev. - For minor releases, bump
Stable tagin thereadme.txt/readme.mdindevelop. - Re-run
wp amp docs generate --format=markdown . docs && wp amp docs generate --format=json . docsand commit any docs updates.
- Re-run
- Close the GitHub milestone.
- Archive cards in project in Passed QA column.
- Publish release blog post (if applicable), including link to GitHub release.
- Make announcements on Twitter and the #amp-wp channel on AMP Slack, linking to release post or GitHub release.
- Alert any community members who are awaiting for fixes either on the support forum or GitHub issues.
- Changelog messages are added in the PR-related issue, within its reserved section, which is pre-populated from the issue template.
- Changelog messages start with a verb in its imperative form (e.g. “Fix bug xyz”), preferably one of the following words:
- Add (for features)
- Introduce (for features)
- Enhance (for enhancements)
- Improve (for enhancements)
- Change (for misc changes)
- Update (for misc changes)
- Modify (for misc changes)
- Remove (for removal)
- Fix (for bug fixes)
- N/A (skip changelog message)
- The changelog messages are categorized as follows:
- Added
- Enhanced
- Changed
- Fixed
- Changelog messages are automatically assigned to one of the defined categories based on the first word the message starts with. Default: “Changed”.
- Changelogs with the message “N/A” are skipped.
Maintainers must ensure that changelog messages are clear and follow the formatting guidelines.
Notice: Please also see the plugin documentation on amp-wp.org