jenkins-bot has submitted this change and it was merged.

Change subject: Add updateBitsBranchPointers script to create/update 'current' 
/ 'stable' symlinks
......................................................................


Add updateBitsBranchPointers script to create/update 'current' / 'stable' 
symlinks

Bits static asset URLs currently reference a specific production branch. This
is fine in most cases, but in certain cases (such as large files in extensions
that change infrequently) we want a stable URL to the latest version of some
asset, so that the referenced asset is not thrown out of the browser cache on
each release. The current case is the UniversalLanguageSelector extension,
which serves large font files out of its repository.

This patch adds a new script to multiversion/, updateBitsBranchPointers. The
script updates a pair of directories in the Bits docroot, static-current &
static-stable, that contain symlinks to the asset paths of the most recent &
secondmost recent production branches, respectively. If only one production
branch exists, both current & stable pointers are pointed to it.

Bug: 55506
Change-Id: If597d70625cf8f06c0e59dd7749442ba05769174
---
A multiversion/updateBitsBranchPointers
1 file changed, 84 insertions(+), 0 deletions(-)

Approvals:
  Reedy: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/multiversion/updateBitsBranchPointers 
b/multiversion/updateBitsBranchPointers
new file mode 100755
index 0000000..c9f18bf
--- /dev/null
+++ b/multiversion/updateBitsBranchPointers
@@ -0,0 +1,84 @@
+#!/usr/bin/env php
+<?php
+/**
+ * Create/update symlinks from docroot/bits/static-current & 
docroot/bits/static-stable
+ * to the latest and next-to-latest production branches, respectively. These 
symlinks
+ * are used to provide stable URLs to large static assets that are served by 
extensions
+ * and which do not change frequently.
+ *
+ * Usage: updateBitsBranchPointers [OPTIONS]
+ *
+ * Options:
+ *   --dry-run: Don't touch the file system; only show what would be done.
+ *
+ */
+error_reporting( E_ALL );
+require_once './defines.php';
+
+function isMain() {
+       return basename( __FILE__ ) === basename( $_SERVER['SCRIPT_FILENAME'] );
+}
+
+function updateBitsBranchPointers( $dryRun ) {
+       $branchDirs = glob( MULTIVER_COMMON_APACHE . '/php-*', GLOB_ONLYDIR );
+
+       if ( !is_array( $branchDirs ) || count( $branchDirs ) < 1 ) {
+               fwrite( STDERR, __FUNCTION__ . ': no deployment branch 
directories found in ' . MULTIVER_COMMON_APACHE . "\n" );
+               exit( 1 );
+       }
+
+       $branches = array();
+       $branches['current'] = array_pop( $branchDirs );
+       // If there's only one deployment branch, make both 'current' & 
'stable' symlinks refer to it.
+       $branches['stable'] = array_pop( $branchDirs ) ?: $branches['current'];
+
+       foreach( $branches as $branch => $target ) {
+               echo "Updating $branch branch pointer...\n";
+
+               $parent = MULTIVER_COMMON_HOME . "/docroot/bits/static-$branch";
+
+               if ( !$dryRun && !file_exists( $parent ) && !mkdir( $parent, 
0775 ) ) {
+                       fwrite( STDERR, __FUNCTION__ . ": $parent does not 
exist and could not be created.\n" );
+                       exit( 1 );
+               }
+
+               foreach( array( 'skins', 'extensions', 'resources' ) as $child 
) {
+                       $link = $parent . '/' . $child;
+                       $dest = $target . '/' . $child;
+
+                       if ( !file_exists( $dest ) ) {
+                               fwrite( STDERR, __FUNCTION__ . ": link target 
$dest does not exist.\n" );
+                               exit( 1 );
+                       }
+
+                       if ( file_exists( $link ) ) {
+                               if ( realpath( $link ) === $dest ) {
+                                       echo "$link is already up-to-date.\n";
+                                       continue;
+                               }
+
+                               if ( !is_link( $link ) ) {
+                                       fwrite( STDERR, __FUNCTION__ . ": $link 
exists and is not a symbolic link.\n" );
+                                       exit( 1 );
+                               }
+
+                               if ( !$dryRun && !unlink( $link ) ) {
+                                       fwrite( STDERR, __FUNCTION__ . ": 
failed to unlink $link\n" );
+                                       exit( 1 );
+                               }
+                       }
+
+                       if ( !$dryRun && !symlink( $dest, $link ) ) {
+                               fwrite( STDERR, __FUNCTION__ . ": failed to 
create $link\n" );
+                               exit( 1 );
+                       }
+                       echo "$link => $dest\n";
+               }
+               echo "\n";
+       }
+}
+
+if ( isMain() ) {
+       $dryRun = in_array( '--dry-run', $argv, true );
+       updateBitsBranchPointers( $dryRun );
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/90085
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If597d70625cf8f06c0e59dd7749442ba05769174
Gerrit-PatchSet: 4
Gerrit-Project: operations/mediawiki-config
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to