@@ -19,12 +19,15 @@ public static class VariableProvider
19
19
public const string FullSemVerPadded = "FullSemVerPadded" ;
20
20
public const string AssemblySemVer = "AssemblySemVer" ;
21
21
public const string ClassicVersion = "ClassicVersion" ;
22
+ public const string ClassicVersionWithTag = "ClassicVersionWithTag" ;
22
23
public const string PreReleaseTag = "PreReleaseTag" ;
23
24
public const string PreReleaseTagWithDash = "PreReleaseTagWithDash" ;
24
25
public const string InformationalVersion = "InformationalVersion" ;
25
26
26
27
public static Dictionary < string , string > GetVariablesFor ( SemanticVersion semanticVersion )
27
28
{
29
+ var formatter = semanticVersion . BuildMetaData . Branch == "develop" ? new CiFeedFormatter ( ) : null ;
30
+
28
31
var variables = new Dictionary < string , string > ( StringComparer . InvariantCultureIgnoreCase )
29
32
{
30
33
{ Major , semanticVersion . Major . ToString ( ) } ,
@@ -35,18 +38,48 @@ public static Dictionary<string, string> GetVariablesFor(SemanticVersion semanti
35
38
{ BuildMetaData , semanticVersion . BuildMetaData } ,
36
39
{ FullBuildMetaData , semanticVersion . BuildMetaData . ToString ( "f" ) } ,
37
40
{ MajorMinorPatch , string . Format ( "{0}.{1}.{2}" , semanticVersion . Major , semanticVersion . Minor , semanticVersion . Patch ) } ,
38
- { SemVer , semanticVersion . ToString ( ) } ,
39
- { SemVerPadded , semanticVersion . ToString ( "sp" ) } ,
41
+ { SemVer , semanticVersion . ToString ( null , formatter ) } ,
42
+ { SemVerPadded , semanticVersion . ToString ( "sp" , formatter ) } ,
40
43
{ AssemblySemVer , semanticVersion . ToString ( "j" ) + ".0" } ,
41
44
{ FullSemVer , semanticVersion . ToString ( "f" ) } ,
42
- { FullSemVerPadded , semanticVersion . ToString ( "fp" ) } ,
43
- { InformationalVersion , semanticVersion . ToString ( "i" ) } ,
45
+ { FullSemVerPadded , semanticVersion . ToString ( "fp" , formatter ) } ,
46
+ { InformationalVersion , semanticVersion . ToString ( "i" , formatter ) } ,
44
47
{ ClassicVersion , string . Format ( "{0}.{1}" , semanticVersion . ToString ( "j" ) , ( semanticVersion . BuildMetaData . CommitsSinceTag ?? 0 ) ) } ,
48
+ { ClassicVersionWithTag , string . Format ( "{0}.{1}{2}" , semanticVersion . ToString ( "j" ) ,
49
+ semanticVersion . BuildMetaData . CommitsSinceTag ?? 0 ,
50
+ semanticVersion . PreReleaseTag . HasTag ( ) ? "-" + semanticVersion . PreReleaseTag : null ) } ,
45
51
{ BranchName , semanticVersion . BuildMetaData . Branch } ,
46
- { Sha , semanticVersion . BuildMetaData . Sha } ,
52
+ { Sha , semanticVersion . BuildMetaData . Sha }
47
53
} ;
48
54
49
55
return variables ;
50
56
}
51
57
}
58
+
59
+ public class CiFeedFormatter : IFormatProvider , ICustomFormatter
60
+ {
61
+ public object GetFormat ( Type formatType )
62
+ {
63
+ if ( formatType == typeof ( SemanticVersion ) )
64
+ return this ;
65
+
66
+ return null ;
67
+ }
68
+
69
+ public string Format ( string format , object arg , IFormatProvider formatProvider )
70
+ {
71
+ var semanticVersion = ( SemanticVersion ) arg ;
72
+
73
+ switch ( format )
74
+ {
75
+ case "s" :
76
+ case "sp" :
77
+ return string . Format ( "{0}.{1}{2}" , semanticVersion . ToString ( "j" ) ,
78
+ semanticVersion . BuildMetaData . CommitsSinceTag ?? 0 ,
79
+ semanticVersion . PreReleaseTag . HasTag ( ) ? "-" + semanticVersion . PreReleaseTag . Name : null ) ;
80
+ default :
81
+ return semanticVersion . ToString ( format ) ;
82
+ }
83
+ }
84
+ }
52
85
}
0 commit comments