@@ -43,6 +43,26 @@ async function getAvailableWordPressVersions() {
4343 } )
4444}
4545
46+ /**
47+ * Compare two dotted version strings (e.g. WordPress "5.0" vs "4.5").
48+ * @param {string } a
49+ * @param {string } b
50+ * @return {number } negative if a < b, 0 if equal, positive if a > b
51+ */
52+ function compareVersionStrings ( a , b ) {
53+ const aParts = String ( a ) . trim ( ) . split ( '.' ) . map ( n => parseInt ( n , 10 ) || 0 )
54+ const bParts = String ( b ) . trim ( ) . split ( '.' ) . map ( n => parseInt ( n , 10 ) || 0 )
55+ const len = Math . max ( aParts . length , bParts . length )
56+ for ( let i = 0 ; i < len ; i ++ ) {
57+ const av = aParts [ i ] || 0
58+ const bv = bParts [ i ] || 0
59+ if ( av !== bv ) {
60+ return av - bv
61+ }
62+ }
63+ return 0
64+ }
65+
4666function calculateMinVersion ( latestVersion , availableVersions ) {
4767 const parts = latestVersion . split ( '.' )
4868 if ( parts . length >= 2 ) {
@@ -126,10 +146,17 @@ async function syncVersions() {
126146 console . log ( '✅ readme.txt stable tag updated successfully' )
127147 }
128148 const testedUpToMatch = readmeTxt . match ( / ^ T e s t e d u p t o : \s * ( [ ^ \r \n ] + ) / m )
129- if ( testedUpToMatch && testedUpToMatch [ 1 ] . trim ( ) !== latestWordPressVersion ) {
130- const updated = ( fs . readFileSync ( 'readme.txt' , 'utf8' ) ) . replace ( / ^ T e s t e d u p t o : \s * [ ^ \r \n ] + / m, `Tested up to: ${ latestWordPressVersion } ` )
131- fs . writeFileSync ( 'readme.txt' , updated )
132- console . log ( '✅ readme.txt tested up to updated successfully' )
149+ if ( testedUpToMatch ) {
150+ const currentTestedUpTo = testedUpToMatch [ 1 ] . trim ( )
151+ // Only bump "Tested up to" when the API version is newer; keep a higher manual value.
152+ if (
153+ currentTestedUpTo !== latestWordPressVersion &&
154+ compareVersionStrings ( currentTestedUpTo , latestWordPressVersion ) < 0
155+ ) {
156+ const updated = ( fs . readFileSync ( 'readme.txt' , 'utf8' ) ) . replace ( / ^ T e s t e d u p t o : \s * [ ^ \r \n ] + / m, `Tested up to: ${ latestWordPressVersion } ` )
157+ fs . writeFileSync ( 'readme.txt' , updated )
158+ console . log ( '✅ readme.txt tested up to updated successfully' )
159+ }
133160 }
134161 const requiresAtLeastMatch = readmeTxt . match ( / ^ R e q u i r e s a t l e a s t : \s * ( [ ^ \r \n ] + ) / m )
135162 if ( requiresAtLeastMatch && requiresAtLeastMatch [ 1 ] . trim ( ) !== minWordPressVersion ) {
0 commit comments