Skip to content

Commit

Permalink
Update readme for wiki; add Grunt for building and deploying
Browse files Browse the repository at this point in the history
* Update phpunit coverage whitelist to include all files rather than limit to one
* Fix coverage warnings
* Remove tests directory from PHPCS exclusion.
* Add global doc and fix phpcs in WPCOM_AMP_Polldaddy_Embed
* Move contents of readme to wiki; sync readme.md with readme.txt
* Remove readme-assets which have been moved to the wiki repo
* Remove readme sections now in wiki; add Grunt for building and deploying
* Add verify_matching_versions command from better-code-editing feature plugin
* Add verify_matching_versions and phpunit as dependencies of deploy command.
* Fix paths for jshint.
* Add version to composer.json.
* Update contributors
* Add create-release-zip task as part of grunt build
* Updated all version instances to 0.6
* Completed 0.6 changelog
* Build 0.6-beta release
  • Loading branch information
westonruter authored and Thierry Muller committed Dec 19, 2017
1 parent 78c60fa commit d5362a7
Show file tree
Hide file tree
Showing 33 changed files with 2,568 additions and 754 deletions.
2 changes: 1 addition & 1 deletion .dev-lib
@@ -1,6 +1,6 @@
SYNC_README_MD=0
PATH_EXCLUDES_PATTERN=includes/lib/
DEFAULT_BASE_BRANCH=develop
ASSETS_DIR=wp-assets

function after_wp_install {
echo "Installing REST API..."
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
@@ -1,2 +1,6 @@
.DS_Store
vendor
build
node_modules
wiki
amp.zip
121 changes: 121 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,121 @@
/* eslint-env node */
/* jshint node:true */

module.exports = function( grunt ) {
'use strict';

grunt.initConfig( {

pkg: grunt.file.readJSON( 'package.json' ),

// JavaScript linting with JSHint.
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'assets/**/*.js'
]
},

// Clean up the build.
clean: {
build: {
src: [ 'build' ]
}
},

// Shell actions.
shell: {
options: {
stdout: true,
stderr: true
},
readme: {
command: './dev-lib/generate-markdown-readme' // Generate the readme.md.
},
phpunit: {
command: 'phpunit'
},
verify_matching_versions: {
command: 'php bin/verify-version-consistency.php'
},
create_release_zip: {
command: 'if [ ! -e build ]; then echo "Run grunt build first."; exit 1; fi; if [ -e amp.zip ]; then rm amp.zip; fi; cd build; zip -r ../amp.zip .; cd ..; echo; echo "ZIP of build: $(pwd)/amp.zip"'
}
},

// Deploys a git Repo to the WordPress SVN repo.
wp_deploy: {
deploy: {
options: {
plugin_slug: 'amp',
build_dir: 'build',
assets_dir: 'wp-assets'
}
}
}

} );

// Load tasks.
grunt.loadNpmTasks( 'grunt-contrib-clean' );
grunt.loadNpmTasks( 'grunt-contrib-copy' );
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-shell' );
grunt.loadNpmTasks( 'grunt-wp-deploy' );

// Register tasks.
grunt.registerTask( 'default', [
'build'
] );

grunt.registerTask( 'readme', [
'shell:readme'
] );

grunt.registerTask( 'build', function() {
var done = this.async();

grunt.util.spawn(
{
cmd: 'git',
args: [ 'ls-files' ]
},
function( err, res ) {
if ( err ) {
throw new Error( err.message );
}

grunt.config.set( 'copy', {
build: {
src: res.stdout.trim().split( /\n/ ).filter( function( file ) {
return ! /^(\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|tests|wp-assets|dev-lib|readme\.md)/.test( file );
} ),
dest: 'build',
expand: true
}
} );
grunt.task.run( 'readme' );
grunt.task.run( 'copy' );
grunt.task.run( 'shell:create_release_zip' );
done();
}
);
} );

grunt.registerTask( 'create-release-zip', [
'build',
'shell:create_release_zip'
] );

grunt.registerTask( 'deploy', [
'build',
'jshint',
'shell:phpunit',
'shell:verify_matching_versions',
'wp_deploy',
'clean'
] );
};
6 changes: 3 additions & 3 deletions amp.php
Expand Up @@ -5,7 +5,7 @@
* Plugin URI: https://github.com/automattic/amp-wp
* Author: Automattic
* Author URI: https://automattic.com
* Version: 0.6.0-alpha
* Version: 0.6-alpha
* Text Domain: amp
* Domain Path: /languages/
* License: GPLv2 or later
Expand All @@ -15,7 +15,7 @@

define( 'AMP__FILE__', __FILE__ );
define( 'AMP__DIR__', dirname( __FILE__ ) );
define( 'AMP__VERSION', '0.6.0-alpha' );
define( 'AMP__VERSION', '0.6-alpha' );

require_once AMP__DIR__ . '/includes/class-amp-autoloader.php';
AMP_Autoloader::register();
Expand Down Expand Up @@ -146,7 +146,7 @@ function amp_maybe_add_actions() {
}

function amp_load_classes() {
_deprecated_function( __FUNCTION__, '0.6.0' );
_deprecated_function( __FUNCTION__, '0.6' );
}

function amp_add_frontend_actions() {
Expand Down
1 change: 1 addition & 0 deletions bin/create-embed-test-post.php
Expand Up @@ -2,6 +2,7 @@
/**
* Create embed test post.
*
* @codeCoverageIgnore
* @package AMP
*/

Expand Down
61 changes: 61 additions & 0 deletions bin/verify-version-consistency.php
@@ -0,0 +1,61 @@
#!/usr/bin/env
<?php
/**
* Verify versions referenced in plugin match.
*
* @codeCoverageIgnore
* @package AMP
*/

if ( 'cli' !== php_sapi_name() ) {
fwrite( STDERR, "Must run from CLI.\n" );
exit( 1 );
}

$versions = array();

$versions['package.json'] = json_decode( file_get_contents( dirname( __FILE__ ) . '/../package.json' ) )->version;
$versions['package-lock.json'] = json_decode( file_get_contents( dirname( __FILE__ ) . '/../package-lock.json' ) )->version;
$versions['composer.json'] = json_decode( file_get_contents( dirname( __FILE__ ) . '/../composer.json' ) )->version;

$readme_txt = file_get_contents( dirname( __FILE__ ) . '/../readme.txt' );
if ( ! preg_match( '/Stable tag:\s+(?P<version>\S+)/i', $readme_txt, $matches ) ) {
echo "Could not find stable tag in readme\n";
exit( 1 );
}
$versions['readme.txt#stable-tag'] = $matches['version'];

if ( ! preg_match( '/== Changelog ==\s+=\s+(?P<version>\d+\.\d+(?:.\d+)?)/', $readme_txt, $matches ) ) {
echo "Could not find version i n readme.txt changelog\n";
exit( 1 );
}
$versions['readme.txt#changelog'] = $matches['version'];

$readme_md = file_get_contents( dirname( __FILE__ ) . '/../readme.md' );
if ( ! preg_match( '/## Changelog ##\s+###\s+(?P<version>\d+\.\d+(?:.\d+)?)/', $readme_md, $matches ) ) {
echo "Could not find version in readme.md changelog\n";
exit( 1 );
}
$versions['readme.md#changelog'] = $matches['version'];

$plugin_file = file_get_contents( dirname( __FILE__ ) . '/../amp.php' );
if ( ! preg_match( '/\*\s*Version:\s*(?P<version>\d+\.\d+(?:.\d+)?)/', $plugin_file, $matches ) ) {
echo "Could not find version in readme metadata\n";
exit( 1 );
}
$versions['amp.php#metadata'] = $matches['version'];

if ( ! preg_match( '/define\( \'AMP__VERSION\', \'(?P<version>[^\\\']+)\'/', $plugin_file, $matches ) ) {
echo "Could not find version in AMP__VERSION constant\n";
exit( 1 );
}
$versions['AMP__VERSION'] = $matches['version'];

fwrite( STDERR, "Version references:\n" );

echo json_encode( $versions, JSON_PRETTY_PRINT ) . "\n";

if ( 1 !== count( array_unique( $versions ) ) ) {
fwrite( STDERR, "Error: Not all version references have been updated.\n" );
exit( 1 );
}
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -3,5 +3,6 @@
"description": "WordPress plugin for adding AMP support.",
"homepage": "https://github.com/Automattic/amp-wp",
"type": "wordpress-plugin",
"license": "GPL-2.0"
"license": "GPL-2.0",
"version": "0.6.0"
}
16 changes: 13 additions & 3 deletions contributing.md
Expand Up @@ -7,15 +7,15 @@ To clone this repository
$ git clone --recursive git@github.com:Automattic/amp-wp.git
```

### Updating Allowed Tags And Attributes
## Updating Allowed Tags And Attributes

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:
1. `cd` to the root of this plugin
2. run `bash bin/amphtml-update.sh`
That script is intended for a Linux environment like [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV).

### Testing Media And Embed Support
## Testing Media And Embed Support

The following script creates a post in order to test support for WordPress media and embeds.
To run it:
Expand All @@ -24,7 +24,7 @@ To run it:
3. run `wp eval-file bin/create-embed-test-post.php`
4. go to the URL that is output in the command line

### PHPUnit Testing
## PHPUnit Testing

Please run these tests in an environment with WordPress unit tests installed, like [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV).

Expand All @@ -41,3 +41,13 @@ $ phpunit --coverage-html /tmp/report
```

When you push a commit to your PR, Travis CI will run the PHPUnit tests and sniffs against the WordPress Coding Standards.

## Creating a Release

Contributors who want to make a new release, follow these steps:

1. Bump plugin versions in `package.json` (×1), `package-lock.json` (×1, just do `npm install` first), `composer.json` (×1), and in `amp.php` (×2: the metadata block in the header and also the `AMP__VERSION` constant).
2. Add changelog entry to readme.
3. Merge release branch into `master`.
4. Run `grunt deploy` to to commit the plugin to WordPress.org.
5. [Create new release](https://github.com/Automattic/amp-wp/releases/new) on GitHub targeting `master`, with the new plugin version as the tag and release title. Attaching the `amp.zip` build to the release. Publish.
4 changes: 2 additions & 2 deletions includes/admin/class-amp-customizer.php
Expand Up @@ -281,11 +281,11 @@ public function print_controls_templates() {
/**
* Whether the Customizer is AMP. This is always true since the AMP Customizer has been merged with the main Customizer.
*
* @deprecated 0.6.0
* @deprecated 0.6
* @return bool
*/
public static function is_amp_customizer() {
_deprecated_function( __METHOD__, '0.6.0' );
_deprecated_function( __METHOD__, '0.6' );
return true;
}
}
6 changes: 3 additions & 3 deletions includes/class-amp-autoloader.php
Expand Up @@ -97,7 +97,7 @@ class AMP_Autoloader {
*
* Design Goal: Execute as few lines of code as possible each call.
*
* @since 0.6.0
* @since 0.6
*
* @param string $class_name Class name.
*/
Expand All @@ -112,7 +112,7 @@ protected static function autoload( $class_name ) {
/**
* Registers this autoloader to PHP.
*
* @since 0.6.0
* @since 0.6
*
* Called at the end of this file; calling a second time has no effect.
*/
Expand All @@ -126,7 +126,7 @@ public static function register() {
/**
* Allows an extensions plugin to register a class and its file for autoloading
*
* @since 0.6.0
* @since 0.6
*
* @param string $class_name Full classname (include namespace if applicable).
* @param string $filepath Absolute filepath to class file, including .php extension.
Expand Down
2 changes: 1 addition & 1 deletion includes/embeds/class-amp-soundcloud-embed.php
Expand Up @@ -74,7 +74,7 @@ public function get_scripts() {
* @return string Rendered oEmbed.
*/
public function oembed( $matches, $attr, $url ) {
_deprecated_function( __METHOD__, '0.6.0' );
_deprecated_function( __METHOD__, '0.6' );
unset( $matches, $attr );
$track_id = $this->get_track_id_from_url( $url );
return $this->render( compact( 'track_id' ) );
Expand Down
2 changes: 1 addition & 1 deletion includes/lib/fasterimage/amp-fasterimage.php
Expand Up @@ -13,7 +13,7 @@
* @deprecated
*/
function amp_load_fasterimage_classes() {
_deprecated_function( __FUNCTION__, '0.6.0' );
_deprecated_function( __FUNCTION__, '0.6' );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/options/class-amp-options-manager.php
Expand Up @@ -238,7 +238,7 @@ public static function handle_analytics_submit() {
* @return bool Whether options were updated.
*/
public static function update_analytics_options( $data ) {
_deprecated_function( __METHOD__, '0.6.0', __CLASS__ . '::update_option' );
_deprecated_function( __METHOD__, '0.6', __CLASS__ . '::update_option' );
return self::update_option( 'analytics', wp_unslash( $data ) );
}
}
4 changes: 2 additions & 2 deletions includes/utils/class-amp-dom-utils.php
Expand Up @@ -87,7 +87,7 @@ public static function get_content_from_dom( $dom ) {
*
* @see Called by function get_content_from_dom()
*
* @since 0.6.0
* @since 0.6
*
* @param DOMDocument $dom Represents an HTML document.
* @param DOMNode $node Represents an HTML element of the $dom from which to extract HTML content.
Expand Down Expand Up @@ -263,7 +263,7 @@ private static function is_self_closing_tag( $tag ) {
/**
* Returns array of self closing tags
*
* @since 0.6.0
* @since 0.6
*
* @return string[]
*/
Expand Down

0 comments on commit d5362a7

Please sign in to comment.