From 04f1e9cbf72f82f40a4d0bb23f7b800e92092449 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Tue, 17 Apr 2018 18:10:21 +0200 Subject: [PATCH 1/5] remove amp_last_check_time query var --- includes/class-amp-theme-support.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 8f4de26c36c..1b75a9717c1 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -288,6 +288,7 @@ public static function purge_amp_query_vars() { '__amp_source_origin', '_wp_amp_action_xhr_converted', 'amp_latest_update_time', + 'amp_last_check_time', ); // Scrub input vars. From f0842aa127fb639335e80fa05a84bca7164a0636 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Tue, 17 Apr 2018 18:12:37 +0200 Subject: [PATCH 2/5] add unit test for removal of amp_last_check_time --- tests/test-class-amp-theme-support.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index 1858a266635..68d668040bb 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -296,6 +296,7 @@ public function test_purge_amp_query_vars() { // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification $bad_query_vars = array( 'amp_latest_update_time' => '1517199956', + 'amp_last_check_time' => '1517599126', '__amp_source_origin' => home_url(), ); $ok_query_vars = array( From 3f241287477bcd1f99562a4808600752ddffe5ef Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Apr 2018 22:37:39 -0700 Subject: [PATCH 3/5] Switch to using build stages for deploys --- .travis.yml | 74 ++++++++++++++++++++++++++--------------------------- dev-lib | 2 +- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index cc42f030de3..c7e4d9968e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,33 +20,10 @@ cache: - $HOME/phpunit-bin - $HOME/deployment-targets -matrix: - include: - - php: "5.3" - env: WP_VERSION=latest DEV_LIB_SKIP=composer,phpcs - - php: "5.4" - env: WP_VERSION=4.7 DEV_LIB_SKIP=composer,phpcs - - php: "5.5" - env: WP_VERSION=latest DEV_LIB_SKIP=phpcs - - php: "5.6" - env: WP_VERSION=4.8 DEV_LIB_SKIP=phpcs - - php: "5.6" - env: WP_VERSION=latest DEV_LIB_SKIP=phpcs - - php: "7.0" - env: WP_VERSION=latest DEV_LIB_SKIP=phpcs - - php: "7.1" - env: WP_VERSION=latest DEV_LIB_SKIP=phpcs - - php: "7.2" - env: WP_VERSION=trunk DEPLOY_TEST_SITE=true - install: - nvm install 6 && nvm use 6 - export DEV_LIB_PATH=dev-lib - source $DEV_LIB_PATH/travis.install.sh - - echo "TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST" - - echo "TRAVIS_BRANCH=$TRAVIS_BRANCH" - - echo "TRAVIS_EVENT_TYPE=$TRAVIS_EVENT_TYPE" - - echo "TRAVIS_PULL_REQUEST_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH" script: - source $DEV_LIB_PATH/travis.script.sh @@ -54,18 +31,39 @@ script: after_script: - source $DEV_LIB_PATH/travis.after_script.sh -after_success: - - | - if [[ $DEPLOY_TEST_SITE == true ]] && - [[ $TRAVIS_PULL_REQUEST == false ]] && - [[ $TRAVIS_SECURE_ENV_VARS == true ]] && - ( [[ $TRAVIS_BRANCH =~ ^[a-z][a-z0-9-]{0,10}$ ]] || [[ $TRAVIS_BRANCH =~ [0-9]+\.[0-9]+ ]] ) && - ! [[ $TRAVIS_BRANCH =~ ^(live|test|dev|settings|team|support|debug|multidev|files|tags|billing)$ ]]; - then - pantheon_branch=$( echo $TRAVIS_BRANCH | sed 's/^\([0-9]\)/v\1/' | sed 's/[^a-z0-9-]/-/' ) - echo "Initializing deployment to Pantheon branch: $pantheon_branch" - - eval "$(ssh-agent -s)" - openssl aes-256-cbc -K $encrypted_7eb11f40d4e9_key -iv $encrypted_7eb11f40d4e9_iv -in bin/keys/id_rsa_ampconfdemo.enc -out bin/keys/id_rsa_ampconfdemo -d && chmod 600 bin/keys/id_rsa_ampconfdemo - ./bin/deploy-travis-pantheon.sh ampconfdemo db7f3307-9808-4753-aaa4-acb387c94472 $(pwd)/bin/keys/id_rsa_ampconfdemo $pantheon_branch - fi +jobs: + include: + - stage: test + php: "7.2" + env: WP_VERSION=trunk + - php: "5.3" + env: WP_VERSION=latest DEV_LIB_SKIP=composer,phpcs + - php: "5.4" + env: WP_VERSION=4.7 DEV_LIB_SKIP=composer,phpcs + - php: "5.5" + env: WP_VERSION=latest DEV_LIB_SKIP=phpcs + - php: "5.6" + env: WP_VERSION=4.8 DEV_LIB_SKIP=phpcs + - php: "5.6" + env: WP_VERSION=latest DEV_LIB_SKIP=phpcs + - php: "7.0" + env: WP_VERSION=latest DEV_LIB_SKIP=phpcs + - php: "7.1" + env: WP_VERSION=latest DEV_LIB_SKIP=phpcs + - stage: deploy + if: type = push AND fork = false AND ( branch =~ ^[a-z][a-z0-9-]{0,10}$ OR branch =~ ^[0-9]+\.[0-9]+$ ) AND NOT branch IN ( live, test, dev, settings, team, support, debug, multidev, files, tags, billing ) + php: "7.1" + env: WP_VERSION=latest DEV_LIB_ONLY=composer,grunt + script: + - | + eval "$(ssh-agent -s)" + pantheon_branch=$( echo $TRAVIS_BRANCH | sed 's/^\([0-9]\)/v\1/' | sed 's/[^a-z0-9-]/-/' ) + echo "Initializing deployment to Pantheon branch: $pantheon_branch" + openssl aes-256-cbc -K $encrypted_7eb11f40d4e9_key -iv $encrypted_7eb11f40d4e9_iv -in bin/keys/id_rsa_ampconfdemo.enc -out bin/keys/id_rsa_ampconfdemo -d + chmod 600 bin/keys/id_rsa_ampconfdemo + ./bin/deploy-travis-pantheon.sh \ + ampconfdemo \ + db7f3307-9808-4753-aaa4-acb387c94472 \ + $(pwd)/bin/keys/id_rsa_ampconfdemo \ + $pantheon_branch + after_script: skip diff --git a/dev-lib b/dev-lib index e18d8807923..453ebf28d26 160000 --- a/dev-lib +++ b/dev-lib @@ -1 +1 @@ -Subproject commit e18d880792321937b9d028251f7877c206730b95 +Subproject commit 453ebf28d26c16fc0152d8631df05ebb27411a48 From 1454f9956fd3f14ddbd882ebad213ffef055848a Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 18 Apr 2018 10:26:28 -0700 Subject: [PATCH 4/5] Make sure clean task is run before build --- Gruntfile.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Gruntfile.js b/Gruntfile.js index 24f1475ee3b..dc9408cd04b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -88,6 +88,7 @@ module.exports = function( grunt ) { throw new Error( err.message ); } + grunt.task.run( 'clean' ); grunt.config.set( 'copy', { build: { src: res.stdout.trim().split( /\n/ ).filter( function( file ) { From acf672bc4ca3387e1aaf0752813b5ec35042aaf2 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 18 Apr 2018 11:31:11 -0700 Subject: [PATCH 5/5] Automatically append commit-timestamp when doing grunt build --- Gruntfile.js | 91 ++++++++++++++++++++++++++--------- bin/deploy-travis-pantheon.sh | 4 -- dev-lib | 2 +- 3 files changed, 70 insertions(+), 27 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index dc9408cd04b..fc2bd647957 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,5 +1,6 @@ /* eslint-env node */ /* jshint node:true */ +/* eslint-disable no-param-reassign */ module.exports = function( grunt ) { 'use strict'; @@ -76,34 +77,81 @@ module.exports = function( grunt ) { ] ); grunt.registerTask( 'build', function() { - var done = this.async(); + var done = this.async(), spawnQueue = [], stdout = []; - grunt.util.spawn( + spawnQueue.push( { cmd: 'git', - args: [ 'ls-files' ] + args: [ '--no-pager', 'log', '-1', '--format=%h', '--date=short' ] }, - function( err, res ) { - if ( err ) { - throw new Error( err.message ); + { + cmd: 'git', + args: [ 'ls-files' ] + } + ); + + function finalize() { + var commitHash, lsOutput, versionAppend; + commitHash = stdout.shift(); + lsOutput = stdout.shift(); + versionAppend = commitHash + '-' + new Date().toISOString().replace( /\.\d+/, '' ).replace( /-|:/g, '' ); + + grunt.task.run( 'clean' ); + grunt.config.set( 'copy', { + build: { + src: lsOutput.trim().split( /\n/ ).filter( function( file ) { + return ! /^(\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|tests|wp-assets|dev-lib|readme\.md|composer\..*)/.test( file ); + } ), + dest: 'build', + expand: true, + options: { + noProcess: [ '*/**', 'LICENSE', 'jetpack-helper.php', 'wpcom-helper.php' ], // That is, only process amp.php and readme.txt. + process: function( content, srcpath ) { + var matches, version, versionRegex; + if ( /amp\.php$/.test( srcpath ) ) { + versionRegex = /(\*\s+Version:\s+)(\d+(\.\d+)+-\w+)/; + + // If not a stable build (e.g. 0.7.0-beta), amend the version with the git commit and current timestamp. + matches = content.match( versionRegex ); + if ( matches ) { + version = matches[2] + '-' + versionAppend; + console.log( 'Updating version in amp.php to ' + version ); + content = content.replace( versionRegex, '$1' + version ); + content = content.replace( /(define\(\s*'AMP__VERSION',\s*')(.+?)(?=')/, '$1' + version ); + } + } + return content; + } + } } + } ); + grunt.task.run( 'readme' ); + grunt.task.run( 'copy' ); + + grunt.task.run( 'shell:create_release_zip' ); + + done(); + } - grunt.task.run( 'clean' ); - 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|composer\..*)/.test( file ); - } ), - dest: 'build', - expand: true + function doNext() { + var nextSpawnArgs = spawnQueue.shift(); + if ( ! nextSpawnArgs ) { + finalize(); + } else { + grunt.util.spawn( + nextSpawnArgs, + function( err, res ) { + if ( err ) { + throw new Error( err.message ); + } + stdout.push( res.stdout ); + doNext(); } - } ); - grunt.task.run( 'readme' ); - grunt.task.run( 'copy' ); - grunt.task.run( 'shell:create_release_zip' ); - done(); + ); } - ); + } + + doNext(); } ); grunt.registerTask( 'create-release-zip', [ @@ -116,7 +164,6 @@ module.exports = function( grunt ) { 'jshint', 'shell:phpunit', 'shell:verify_matching_versions', - 'wp_deploy', - 'clean' + 'wp_deploy' ] ); }; diff --git a/bin/deploy-travis-pantheon.sh b/bin/deploy-travis-pantheon.sh index 9c01a4dec83..3d84d8e6e45 100755 --- a/bin/deploy-travis-pantheon.sh +++ b/bin/deploy-travis-pantheon.sh @@ -86,11 +86,7 @@ if [ ! -e node_modules/.bin ]; then fi PATH="node_modules/.bin/:$PATH" grunt build -version_append=$(git --no-pager log -1 --format="%h" --date=short)-$(date "+%Y%m%dT%H%M%S") rsync -avz --delete ./build/ "$repo_dir/wp-content/plugins/amp/" -cat ./build/amp.php | - sed "/^ \* Version:/ s/$/-$version_append/" | - sed "/^define( 'AMP__VERSION/ s/' );/-$version_append' );/" > "$repo_dir/wp-content/plugins/amp/amp.php" git --no-pager log -1 --format="Build AMP plugin at %h: %s" > /tmp/commit-message.txt # Commit and deploy. diff --git a/dev-lib b/dev-lib index 453ebf28d26..c80f10dad3c 160000 --- a/dev-lib +++ b/dev-lib @@ -1 +1 @@ -Subproject commit 453ebf28d26c16fc0152d8631df05ebb27411a48 +Subproject commit c80f10dad3cb402213914438d8ae1cdeccce9e4a