-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathVersioning.fsx
executable file
·108 lines (84 loc) · 3.55 KB
/
Versioning.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#r @"../../../packages/FAKE/tools/FakeLib.dll"
#load "./Utils.fsx"
open System
open System.Text.RegularExpressions
open System.Xml
open Fake
open Fake.Git
open Utils
let private readAssemblyVersion file =
ReadFile file
|> Seq.find (fun line -> not (line.StartsWith("//") || line.StartsWith("'")) && line.Contains "AssemblyVersion")
|> (fun line -> Regex.Match(line, @"(?<=\().+?(?=\))").Value)
|> (fun version -> Version (version.Trim [|'"'|]))
let private escapeBranchName rawName =
let regex = System.Text.RegularExpressions.Regex(@"[^0-9A-Za-z-]")
let safeChars = regex.Replace(rawName, "-")
safeChars.[0..(min 9 <| String.length safeChars - 1)]
let private constructInfoVersion (config: Map<string, string>) (fileVersion: Version) file branchName =
let infoVersion =
Version (
fileVersion.Major,
fileVersion.Minor,
fileVersion.Build)
let suffix =
match isLocalBuild with
| true ->
"-" + (branchName |> escapeBranchName) + "-local"
| _ ->
match config.get "versioning:branch" with
| "master"
| "hotfix" ->
"." + config.get "versioning:build"
| _ ->
"-" + (config.get "versioning:branch" |> escapeBranchName) + "-" + config.get "versioning:build" + "-ci"
infoVersion.ToString() + suffix
let private constructVersions (config: Map<string, string>) file branchName =
let fileVersion = readAssemblyVersion file
let assemblyVersion =
Version (
fileVersion.Major,
fileVersion.Minor,
fileVersion.Build,
int <| config.get "versioning:build")
assemblyVersion.ToString(), (constructInfoVersion config fileVersion file branchName)
let private updateAssemblyInfo config branchName file =
let versions = constructVersions config file branchName
ReplaceAssemblyInfoVersions (fun x ->
{
x with
OutputFileName = file
AssemblyConfiguration = config.get "build:configuration"
AssemblyVersion = fst versions
AssemblyFileVersion = fst versions
AssemblyInformationalVersion = snd versions
})
let private updateDeployNuspec config branchName (file:string) =
let xdoc = new XmlDocument()
ReadFileAsString file |> xdoc.LoadXml
let versionNode = xdoc.SelectSingleNode "/package/metadata/version"
let semVer = SemVerHelper.parse(versionNode.InnerText.ToString())
let fileVersion = new Version(semVer.Major, semVer.Minor, semVer.Patch, 0)
versionNode.InnerText <- (constructInfoVersion config fileVersion file branchName)
WriteStringToFile false file (xdoc.OuterXml.ToString().Replace("><",">\n<"))
let update config _ =
let branchName =
try
getBranchName "."
with
| _ -> "<default>"
!! "./**/AssemblyInfo.cs"
++ "./**/AssemblyInfo.vb"
++ "./**/AssemblyInfo.fs"
|> Seq.iter (updateAssemblyInfo config branchName)
let updateDeploy (config : Map<string, string>) _ =
let branchName =
try
getBranchName "."
with
| _ -> "<default>"
let nuspecSearch = match config.TryFind "packaging:deploynuspecsearch" with
| Some x when String.IsNullOrEmpty x = false -> x
| _ -> "./**/Deploy/*.nuspec"
!! nuspecSearch
|> Seq.iter (updateDeployNuspec config branchName)