Making WordPress.org

Changeset 3373


Ignore:
Timestamp:
06/15/2016 04:47:04 AM (10 years ago)
Author:
dd32
Message:

Plugin Directory: Add a SVN watching script to process & import plugins to the plugin directory after each commit.

This doesn't act as a post-commit hook, but instead is designed to be run in an endless loop.

See #1720

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin.php

    r3164 r3373  
    99ob_start();
    1010
    11 $opts = getopt( '', array( 'url:', 'abspath:', 'plugin:' ) );
     11$opts = getopt( '', array( 'url:', 'abspath:', 'plugin:', 'changed-tags:' ) );
    1212
    1313// Guess the default parameters:
    … …  
    2121if ( empty( $opts['abspath'] ) && false !== strpos( __DIR__, 'wp-content' ) ) {
    2222        $opts['abspath'] = substr( __DIR__, 0, strpos( __DIR__, 'wp-content' ) );
     23}
     24
     25if ( empty( $opts['changed-tags'] ) ) {
     26        $opts['changed-tags'] = array( 'trunk' );
     27} else {
     28        $opts['changed-tags'] = explode( ',', $opts['changed-tags'] );
    2329}
    2430
    … …  
    4753}
    4854
    49 $plugin_slug = $opts['plugin'];
     55$plugin_slug  = $opts['plugin'];
     56$changed_tags = $opts['changed-tags'];
     57$start_time   = microtime(1);
    5058
    5159echo "Processing Import for $plugin_slug... ";
    5260try {
    5361        $importer = new CLI\Import;
    54         $importer->import_from_svn( $plugin_slug );
    55         echo "OK\n";
     62        $importer->import_from_svn( $plugin_slug, $changed_tags );
     63        echo "OK. Took " . round( microtime(1) - $start_time, 2 )  . "s\n";
    5664} catch( \Exception $e ) {
    57         echo "Failed.\n";
     65        echo "Failed. Took " . round( microtime(1) - $start_time, 2 )  . "s\n";
     66
    5867        fwrite( STDERR, "[{$plugin_slug}] Plugin Import Failed: " . $e->getMessage() . "\n" );
    5968        exit(1);
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r3357 r3373  
    2323                'tested',
    2424                'requires',
    25                 'stable_tag',
    2625                'donate_link',
    2726                'upgrade_notice',
    … …  
    4645         * @throws \Exception
    4746         *
    48          * @param string $plugin_slug The slug of the plugin to import.
    49          */
    50         public function import_from_svn( $plugin_slug ) {
     47         * @param string $plugin_slug      The slug of the plugin to import.
     48         * @param array  $svn_changed_tags A list of tags/trunk which the SVN change touched. Optional.
     49         */
     50        public function import_from_svn( $plugin_slug, $svn_changed_tags = array( 'trunk' ) ) {
    5151                global $wpdb;
    5252
    … …  
    152152                        }
    153153
    154                         if ( 'stable_tag' == $readme_field ) {
    155                                 // The stable_tag needs to come from the trunk readme at all times.
    156                                 $value = $stable_tag;
    157                         } else {
    158                                 $value = $readme->$readme_field;
    159                         }
    160 
    161                         update_post_meta( $plugin->ID, $readme_field, wp_slash( $value ) );
     154                        update_post_meta( $plugin->ID, $readme_field, wp_slash( $readme->$readme_field ) );
    162155                }
    163156
    … …  
    190183                        }
    191184                }
     185
     186                $current_stable_tag = get_post_meta( $plugin->ID, 'stable_tag', true );
     187
     188                $this->rebuild_invalidate_zips( $plugin_slug, $stable_tag, $current_stable_tag, $svn_changed_tags );
     189
     190                // Finally, set the new version live.
     191                update_post_meta( $plugin->ID, 'stable_tag', $stable_tag );
     192        }
     193
     194        /**
     195         * Rebuild and Invalidate plugin ZIPs on all web nodes using the REST API Endpoints.
     196         *
     197         * @param string $plugin_slug        The plugin slug.
     198         * @param string $stable_tag         The new stable tag.
     199         * @param string $current_stable_tag The new stable tag.
     200         * @param array  $svn_changed_tags   The list of SVN tags modified since last import.
     201         */
     202        protected function rebuild_invalidate_zips( $plugin_slug, $stable_tag, $current_stable_tag, $svn_changed_tags ) {
     203                global $wporg_webs;
     204                $invalidate_zips = $rebuild_zips = array();
     205
     206                foreach ( $svn_changed_tags as $tag ) {
     207                        if ( 'trunk' == $tag ) {
     208                                if ( 'trunk' == $stable_tag ) {
     209                                        // Trunk is stable, so we'll need to rebuild the zip
     210                                        $rebuild_zips[] = "{$plugin_slug}.zip";
     211                                } else {
     212                                        // Trunk isn't stable, so we'll just remove it so it's rebuilt on demand
     213                                        $invalidate_zips[] = "{$plugin_slug}.zip";
     214                                }
     215                                continue;
     216                        }
     217                        if ( $tag == $stable_tag || $tag == $current_stable_tag ) {
     218                                $rebuild_zips[] = "{$plugin_slug}.{$tag}.zip";
     219                        } else {
     220                                $invalidate_zips[] = "{$plugin_slug}.{$tag}.zip";
     221                        }
     222                }
     223                if ( $stable_tag != $current_stable_tag ) {
     224                        // plugin is updated, ensure that everything is rebuilt.
     225                        if ( ! in_array( $stable_tag, $svn_changed_tags ) ) {
     226                                $rebuild_zips[] = "{$plugin_slug}" . ( 'trunk' == $tag ? '' : ".{$stable_tag}" ) . '.zip';
     227                        }
     228                }
     229
     230                if ( empty( $wporg_webs ) || ( empty( $invalidate_zips ) && empty( $rebuild_zips ) ) ) {
     231                        return;
     232                }
     233
     234                $urls = array();
     235                foreach ( $wporg_webs as $node ) {
     236                        $urls[] = preg_replace( '!^https?://wordpress.org/!', "http://$node/", site_url( '/wp-json/plugins/v1/zip-management' ) );
     237                }
     238                $headers = array(
     239                        'User-Agent' => 'WordPress.org Plugin Directory',
     240                        'Host' => 'WordPress.org',
     241                        'Authorization' => 'BEARER ' . PLUGIN_API_INTERNAL_BEARER_TOKEN,
     242                );
     243                $body = array(
     244                        'plugins' => array(
     245                                $plugin_slug => array(
     246                                        'invalidate' => $invalidate_zips,
     247                                        'rebuild' => $rebuild_zips,
     248                                )
     249                        )
     250                );
     251
     252                $results = array();
     253                foreach ( $urls as $url ) {
     254                        $results[ $url ] = wp_remote_post( $url, array(
     255                                'body' => $body,
     256                                'headers' => $headers,
     257                                'sslverify' => false
     258                        ) );
     259                }
     260
     261                // TODO Do something with $results to verify all servers said the rebuilt zip was correct or something.
    192262        }
    193263
Note: See TracChangeset for help on using the changeset viewer.