@@ -20,20 +20,50 @@ def get_environment_variable(name):
2020
2121github_event_name = get_environment_variable ('github_event_name' )
2222github_run_number = get_environment_variable ('github_run_number' )
23+ github_ref = get_environment_variable ('github_ref' )
2324
2425#==================================================================================================
2526# Determine build settings
2627#==================================================================================================
2728
28- version = f'0.0.0-ci{ github_run_number } '
29+ # For GitHub refs besides main, include the branch/tag name in the default version string
30+ ref_part = ''
31+ if github_ref != 'refs/heads/main' :
32+ ref = github_ref
2933
34+ # Strip the ref prefix
35+ branch_prefix = 'refs/heads/'
36+ tag_prefix = 'refs/tags/'
37+ if ref .startswith (branch_prefix ):
38+ ref = ref [len (branch_prefix ):]
39+ elif ref .startswith (tag_prefix ):
40+ ref = f'tag-{ ref [len (tag_prefix ):]} '
41+
42+ # Replace illegal characters with dashes
43+ ref = re .sub ('[^0-9A-Za-z-]' , '-' , ref )
44+
45+ # Make the ref part
46+ ref_part = f'-{ ref } '
47+
48+ # Build the default version string
49+ version = f'0.0.0{ ref_part } -ci{ github_run_number } '
50+ is_for_release = False
51+
52+ # Handle non-default version strings
53+ # Make sure logic relating to is_for_release matches the publish-packages-nuget-org in the workflow
3054if github_event_name == 'release' :
3155 version = get_environment_variable ('release_version' )
56+ is_for_release = True
3257elif github_event_name == 'workflow_dispatch' :
3358 workflow_dispatch_version = get_environment_variable ('workflow_dispatch_version' )
59+ workflow_dispatch_will_publish_packages = get_environment_variable ('workflow_dispatch_will_publish_packages' )
60+
3461 if workflow_dispatch_version is not None :
3562 version = workflow_dispatch_version
3663
64+ if workflow_dispatch_will_publish_packages .lower () == 'true' :
65+ is_for_release = True
66+
3767# Trim leading v off of version if present
3868if version .startswith ('v' ):
3969 version = version [1 :]
@@ -48,8 +78,9 @@ def get_environment_variable(name):
4878#==================================================================================================
4979# Emit MSBuild properties
5080#==================================================================================================
51- print (f"Configuring build environment to build version { version } " )
81+ print (f"Configuring build environment to build{ ' and release' if is_for_release else '' } version { version } " )
5282gha .set_environment_variable ('CiBuildVersion' , version )
83+ gha .set_environment_variable ('CiIsForRelease' , str (is_for_release ).lower ())
5384
5485#==================================================================================================
5586# Final check to exit with an error code if any errors were printed
0 commit comments