36
36
from datetime import timedelta
37
37
import os
38
38
import re
39
- import sys
40
39
import time
40
+ import urllib .request
41
41
from utils import BuildType
42
42
from utils import CodeModule
43
- from utils import UpdateType
44
43
from utils import version_regex_str_with_names_anchored
45
44
from utils import prerelease_data_version_regex
46
45
from utils import prerelease_version_regex_with_name
46
+ import xml .etree .ElementTree as ET
47
47
48
48
# some things that should not be updated for devops builds, in the case where everything is being updated in one call
49
49
items_we_should_not_update = ['com.azure:azure-sdk-all' , 'com.azure:azure-sdk-parent' , 'com.azure:azure-client-sdk-parent' , 'com.azure.v2:azure-client-sdk-parent' , 'com.azure:azure-data-sdk-parent' , 'com.azure:azure-perf-test-parent' , 'com.azure:azure-code-customization-parent' , 'io.clientcore:clientcore-parent' ]
@@ -275,7 +275,9 @@ def increment_or_set_library_version(build_type, artifact_id, group_id, new_vers
275
275
module = CodeModule (stripped_line )
276
276
# Tick up the version here. If the version is already a pre-release
277
277
# version then just increment the revision. Otherwise increment the
278
- # minor version, zero the patch and add "-beta.1" to the end
278
+ # minor version, zero the patch and determine which "-beta.x" version
279
+ # to use based on what has been released to Maven central. If "beta.1"
280
+ # exists in Maven central then use "beta.2" and so on.
279
281
# https://github.com/Azure/azure-sdk/blob/main/docs/policies/releases.md#java
280
282
if module .name == library_to_update and hasattr (module , 'current' ):
281
283
artifact_found = True
@@ -302,9 +304,10 @@ def increment_or_set_library_version(build_type, artifact_id, group_id, new_vers
302
304
rev += 1
303
305
new_version = '{}.{}.{}-beta.{}' .format (vmatch .group ('major' ), vmatch .group ('minor' ), vmatch .group ('patch' ), str (rev ))
304
306
else :
307
+ major = int (vmatch .group ('major' ))
305
308
minor = int (vmatch .group ('minor' ))
306
309
minor += 1
307
- new_version = '{}.{}.{} -beta.1 ' .format (vmatch . group ( ' major' ) , minor , 0 )
310
+ new_version = '{}.{}.0 -beta.{} ' .format (major , minor , get_beta_version_to_use ( group_id , artifact_id , major , minor ) )
308
311
# The dependency version only needs to be updated it if is different from the current version.
309
312
# This would be the case where a library hasn't been released yet and has been released (either GA or preview)
310
313
if (module .dependency != module .current ):
@@ -334,6 +337,46 @@ def increment_or_set_library_version(build_type, artifact_id, group_id, new_vers
334
337
for line in newlines :
335
338
f .write (line )
336
339
340
+ # Determines which beta version to use when incrementing the version of a library without a version specified.
341
+ def get_beta_version_to_use (group_id : str , artifact_id : str , major_version : int , minor_version : int ):
342
+ # Pull version information from Maven central to determine which beta version to use.
343
+ # If beta.1 exists then use beta.2, etc. If beta.1 doesn't exist then use beta.1
344
+ url = 'https://repo1.maven.org/maven2/{}/{}/maven-metadata.xml' .format (group_id .replace ('.' , '/' ), artifact_id )
345
+ with urllib .request .urlopen (urllib .request .Request (url = url , method = 'GET' )) as f :
346
+ if (f .status != 200 ):
347
+ raise ValueError ('Unable to get maven-metadata.xml for groupId {} and artifactId {}. The status code was {}' .format (group_id , artifact_id , f .status ))
348
+
349
+ # maven-metadata.xml as the following format:
350
+ # <metadata>
351
+ # <groupId>groupId</groupId>
352
+ # <artifactId>artifactId</artifactId>
353
+ # <versioning>
354
+ # <latest>version-latest</latest>
355
+ # <release>version-release</release>
356
+ # <versions>
357
+ # <version>a-version</version>
358
+ # ... (more versions)
359
+ # </versions>
360
+ # </versioning>
361
+ # </metadata>
362
+ root = ET .fromstring (f .read ().decode ('utf-8' ))
363
+ starts_with = '{}.{}.0-beta.' .format (major_version , minor_version )
364
+ highest_beta_version = 0
365
+ for version in root .findall ('./versioning/versions//version' ):
366
+ version_text = version .text
367
+ if version_text .startswith (starts_with ):
368
+ # A beta version with the same major and minor version was already released.
369
+ # Track the beta version number, at the end of this function we'll return the
370
+ # highest beta version match found + 1.
371
+ # For example, if the version is 1.2.0-beta.3 exists, return 4.
372
+ beta_version_str = version_text [len (starts_with ):]
373
+ if beta_version_str != '' :
374
+ beta_version_int = int (beta_version_str )
375
+ if beta_version_int > highest_beta_version :
376
+ highest_beta_version = beta_version_int
377
+
378
+ return highest_beta_version + 1
379
+
337
380
# Verify that the current version of an artifact matches our versioning scheme. This is meant to be called
338
381
# as part of the release pipeline for a given artifact to verify that we don't accidentally release a version
339
382
# that doesn't match our versioning scheme
0 commit comments