66
77open System
88open System.IO
9+ open Paket
910open Fake.BuildServer
1011open Fake.Core
1112open Fake.DotNet
@@ -111,9 +112,59 @@ Target.create "PublishNuGet" (fun _ ->
111112 )
112113)
113114
115+ let anchor ( path : string ) =
116+ System.IO.Path.GetFullPath( Path.Combine(__ SOURCE_ DIRECTORY__, path))
117+
118+ let bumpMajor ( semver : Paket.SemVerInfo ) =
119+ { semver with Major = semver.Major + 1 u
120+ Minor = 0 u
121+ Patch = 0 u }
122+
123+ let bumpMinor ( semver : Paket.SemVerInfo ) =
124+ { semver with Minor = semver.Minor + 1 u
125+ Patch = 0 u }
126+
127+ let bumpPatch ( semver : Paket.SemVerInfo ) =
128+ { semver with Patch = semver.Patch + 1 u }
129+
130+ let (| WithinRange | OutsideRange |) ( leftSemver , ( magnitude : SynVer.Version ), rightSemver ) =
131+ let allowedMin =
132+ match magnitude with
133+ | SynVer.Version.Major -> bumpMajor leftSemver
134+ | SynVer.Version.Minor -> bumpMinor leftSemver
135+ | SynVer.Version.Patch -> bumpPatch leftSemver
136+
137+ if rightSemver < allowedMin || rightSemver < leftSemver then OutsideRange else WithinRange
138+
139+ Target.create " ValidateVersionBump" ( fun _ ->
140+ let intendedVersion = Paket.PublicAPI.ParseSemVer release.NugetVersion
141+ let lockfile = Paket.LockFile.LoadFrom " paket.lock"
142+ let refGroup = lockfile.Groups.[ Paket.Domain.GroupName " reference" ]
143+ let oldPackage = refGroup.Resolution.[ Paket.Domain.PackageName " FSharp.Compiler.Service" ]
144+ let oldVersion = oldPackage.Version
145+ let oldSurfaceArea = SynVer.SurfaceArea.ofAssembly ( System.Reflection.Assembly.LoadFile ( anchor " packages/reference/FSharp.Compiler.Service/lib/netstandard2.0/FSharp.Compiler.Service.dll" ))
146+ let newSurfaceArea = SynVer.SurfaceArea.ofAssembly ( System.Reflection.Assembly.LoadFile ( anchor " ../artifacts/bin/fcs/Release/netstandard2.0/FSharp.Compiler.Service.dll" ))
147+ let ( computedVersion , computedMagnitude ) = SynVer.SurfaceArea.bump ( string oldVersion) oldSurfaceArea newSurfaceArea
148+ let parsedComputedVersion = Paket.PublicAPI.ParseSemVer computedVersion
149+ let apiDiffs = SynVer.SurfaceArea.diff oldSurfaceArea newSurfaceArea |> String.concat " \n "
150+ match oldVersion, computedMagnitude, intendedVersion with
151+ | WithinRange ->
152+ Trace.tracefn " Version %A is within the allowed range of %A from the prior version of %A " intendedVersion computedMagnitude oldVersion
153+ | OutsideRange ->
154+ failwithf """ Version bump invalid.
155+ Version packaged was %A
156+ Version computed due to API diffs was %A
157+ Allowed version magnitude change is %A
158+ The full set of API diffs is:
159+ %A
160+ """ intendedVersion parsedComputedVersion computedMagnitude apiDiffs
161+ )
162+
114163// --------------------------------------------------------------------------------------
115164// Run all targets by default. Invoke 'build <Target>' to override
116165
166+
167+
117168Target.create " Start" ignore
118169Target.create " Release" ignore
119170Target.create " GenerateDocs" ignore
@@ -140,6 +191,7 @@ open Fake.Core.TargetOperators
140191
141192" Build"
142193 ==> " NuGet"
194+ ==> " ValidateVersionBump"
143195 ==> " PublishNuGet"
144196 ==> " Release"
145197
0 commit comments