diff --git a/composer.json b/composer.json index 3abfe27edf8c8ee1902fda794d9f2af2988dbd6d..0b56ef0cec829aa1a95238654ac5a17fbe7a21b7 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,9 @@ "name": "wikimedia/mediawiki-tools-release", "description": "Tools for releasing MediaWiki", "require": { - "php": ">=7.2.0" + "php": ">=7.2.0", + "ext-curl": "*", + "ext-json": "*" }, "require-dev": { "mediawiki/mediawiki-codesniffer": "40.0.1", diff --git a/make-deploy-notes/functions.php b/make-deploy-notes/functions.php new file mode 100644 index 0000000000000000000000000000000000000000..997c45a70e6540952afe29fe8cd512a930091031 --- /dev/null +++ b/make-deploy-notes/functions.php @@ -0,0 +1,17 @@ +<?php + +/** + * @param string $input A raw version string to extract MediaWiki major/minor version from + * @return array|null + */ +function getMajorMinor( $input ) { + $matches = []; + // match any version like wmf/1.26wmf22 or the new semver wmf/1.27.0-wmf1 + if ( preg_match( "/wmf\/1\.(\d{2})\.0\-wmf\.(\d{1,2})/", $input, $matches ) ) { + // var_dump( $matches ); + $major = intval( $matches[1] ); + $minor = intval( $matches[2] ); + return [ $major, $minor ]; + } + return null; +} diff --git a/make-deploy-notes/jenkinsUploadChangelog.php b/make-deploy-notes/jenkinsUploadChangelog.php index b5c6e8cd5addb0ad8758234b940a4492bfa5e524..1dbcb2369eed0dd9f4c2bb242aeb3a1bc3d8ab19 100644 --- a/make-deploy-notes/jenkinsUploadChangelog.php +++ b/make-deploy-notes/jenkinsUploadChangelog.php @@ -19,6 +19,8 @@ * http://www.gnu.org/copyleft/gpl.html */ +require_once 'functions.php'; + if ( count( $argv ) !== 3 ) { print "usage: $argv[0] 1.31.0-wmf.11 notes-file\n"; exit( 1 ); @@ -37,7 +39,7 @@ require_once __DIR__ . '/botclasses.php'; $wiki = new MediaWikiApi( 'https://www.mediawiki.org/w/api.php' ); $wiki->login( $mwUser, $mwPass ); -list( $major, $minor ) = getMajorMinor( $version ); +[ $major, $minor ] = getMajorMinor( $version ); $wiki->query( 'action=edit', [ 'title' => "MediaWiki 1.{$major}/wmf.{$minor}/Changelog", 'text' => $output, @@ -45,20 +47,67 @@ $wiki->query( 'action=edit', [ 'summary' => "Update changelog for $version" ] ); -print "Changelog updated\n"; +$nextVersion = null; -/** - * @param string $input A raw version string. - * @return array|null - */ -function getMajorMinor( $input ) { - $matches = []; - // match any version like 1.26wmf22 or the new semver 1.27.0-wmf1 - if ( preg_match( "/1\.(\d{2})\.0\-wmf\.(\d{1,2})/", $input, $matches ) ) { - // var_dump( $matches ); - $major = intval( $matches[1] ); - $minor = intval( $matches[2] ); - return [ $major, $minor ]; +function fetchReleaseDates() { + $url = 'https://train-blockers.toolforge.org/api.php'; + $context = stream_context_create( + [ + "http" => [ "method" => "GET", "header" => "User-Agent: jenkinsUploadChangelog.php\r\n" ] + ] + ); + $response = file_get_contents( $url, false, $context ); + $data = json_decode( $response, true ); + + if ( $data && isset( $data['current']['date'] ) && isset( $data['dated'] ) ) { + $currentDate = $data['current']['date']; + $upcomingDates = array_keys( $data['dated'] ); + $nextDate = null; + + foreach ( $upcomingDates as $date => $releaseData ) { + if ( $date > $currentDate ) { + $nextDate = $date; + global $nextVersion; + $nextVersion = $releaseData['version']; + break; + } + } + + return [ $currentDate, $nextDate ]; } - return null; } + +[ $currentVersionDate, $nextVersionDate ] = fetchReleaseDates(); +$wiki->query( 'action=edit', [ + 'title' => "MediaWiki 1.{$major}/wmf.{$minor}", + 'text' => "{{WMFReleasePage|$currentVersionDate}}", + 'token' => $wiki->getedittoken(), + 'summary' => "Update Release for $version" +] ); + +// Check if the page creation/update is successful +if ( isset( $response['edit']['result'] ) && $response['edit']['result'] === 'Success' ) { + print "Release page for '$version' created or updated successfully.\n"; +} else { + print "Failed to create or update the release page for '$version'.\n"; + print "Response: " . print_r( $response, true ); +} + +// TODO: Was it if something failed? +print "Changelog updated\n"; + +// Create placeholders for next release +[ $nextMajor, $nextMinor ] = getMajorMinor( $nextVersion ); +$wiki->query( 'action=edit', [ + 'title' => "MediaWiki 1.{$nextMajor}/wmf.{$nextMinor}/Changelog", + 'text' => $output, + 'token' => $wiki->getedittoken(), + 'summary' => "Created changelog placeholder for $nextVersion" +] ); + +$wiki->query( 'action=edit', [ + 'title' => "MediaWiki 1.{$nextMajor}/wmf.{$nextMinor}", + 'text' => "{{WMFReleasePage|$nextVersionDate}}", + 'token' => $wiki->getedittoken(), + 'summary' => "Created Release placeholder for $nextVersion" +] ); diff --git a/make-deploy-notes/uploadChangelog.php b/make-deploy-notes/uploadChangelog.php index 22e3f9eca9674d450cd2b1501cbd0592cb83071e..693082b2cb341f6390e11263cec45ec74105d5eb 100644 --- a/make-deploy-notes/uploadChangelog.php +++ b/make-deploy-notes/uploadChangelog.php @@ -20,6 +20,8 @@ * @file */ +require_once 'functions.php'; + if ( count( $argv ) !== 2 && count( $argv ) !== 4 ) { print "usage: $argv[0] wmf/1.31.0-wmf.11 [username password]\n"; exit( 1 ); @@ -56,7 +58,7 @@ if ( isset( $argv[2] ) && isset( $argv[3] ) ) { require_once __DIR__ . '/auth.php'; } -list( $major, $minor ) = getMajorMinor( $version ); +[ $major, $minor ] = getMajorMinor( $version ); $wiki->query( 'action=edit', [ 'title' => "MediaWiki 1.{$major}/wmf.{$minor}/Changelog", 'text' => $output, @@ -64,7 +66,32 @@ $wiki->query( 'action=edit', [ 'summary' => "Update changelog for $version", ] ); -print "Changelog updated\n"; +function calculateReleaseDate() { + $today = new DateTime(); + if ( $today->format( 'N' ) !== 2 ) { + $today->modify( 'last Tuesday' ); + } + return $today->format( 'Y-m-d' ); +} + +$releaseDate = calculateReleaseDate(); +$wiki->query( 'action=edit', [ + 'title' => "MediaWiki 1.{$major}/wmf.{$minor}", + 'text' => "{{WMFReleasePage|$releaseDate}}", + 'token' => $wiki->getedittoken(), + 'summary' => "Update Release for $version" +] ); + +// Check if the page creation/updating is successful +if ( isset( $response['edit']['result'] ) && $response['edit']['result'] === 'Success' ) { + print "Release page for '$version' created or updated successfully.\n"; +} else { + print "Failed to create or update the release page for '$version'.\n"; + print "Response: " . print_r( $response, true ); +} + +// TODO: Was it if something failed? +print "Changelog and Release updated\n"; /** * @param string $input A raw version string. @@ -75,7 +102,7 @@ function getPreviousVersion( $input ) { if ( $majorMinor === null ) { return null; } - list( $major, $minor ) = $majorMinor; + [ $major, $minor ] = $majorMinor; if ( $minor === 1 ) { $major--; $minor = getPreviousMinorVersion( $major ); @@ -106,28 +133,12 @@ function getPreviousMinorVersion( $major ) { if ( count( $list ) !== 1 ) { // remove anything before the correct version semantic (wmf/1.26wmf1 // or wmf/1.27.0-wmf.1) using the filter defined above - // the array will start counting at 0 and will has one empty "line" at + // the array will start counting at 0 and will have one empty "line" at // the end, so count all elements and subtract 2 - list( $major, $minor ) = getMajorMinor( strstr( $list[ count( $list ) - 2 ], $filter ) ); + [ $major, $minor ] = getMajorMinor( strstr( $list[ count( $list ) - 2 ], $filter ) ); } - // check, if there was a good result, otherwise assume, that there are 22 + // check, if there was a good result, otherwise assume that there are 22 // previous minor versions and use that return ( $minor !== "" ) ? $minor : 22; } - -/** - * @param string $input A raw version string to extract major/minor version from. - * @return array|null - */ -function getMajorMinor( $input ) { - $matches = []; - // match any version like wmf/1.26wmf22 or the new semver wmf/1.27.0-wmf1 - if ( preg_match( "/wmf\/1\.(\d{2})\.0\-wmf\.(\d{1,2})/", $input, $matches ) ) { - // var_dump( $matches ); - $major = intval( $matches[1] ); - $minor = intval( $matches[2] ); - return [ $major, $minor ]; - } - return null; -}