Skip to content

Commit 310a37d

Browse files
authored
Merge pull request #211 from fslaborg/tag-based-release
Tag-based release
2 parents 3751f8b + dfd63c8 commit 310a37d

2 files changed

Lines changed: 39 additions & 37 deletions

File tree

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
name: Dev Release
1+
name: Build and publish NuGet package
22

33
on:
4-
workflow_run:
5-
workflows: [".NET Core"]
6-
branches: [ dev ]
7-
types:
8-
- completed
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
97

108
jobs:
119
publish-nuget:
1210
runs-on: ubuntu-latest
1311
steps:
1412
- uses: actions/checkout@v2
15-
with:
16-
ref: dev
17-
- name: Setup .NET Core
18-
uses: actions/setup-dotnet@v1
13+
- name: Setup .NET SDK
14+
uses: actions/setup-dotnet@v3
1915
with:
2016
dotnet-version: '8.x'
2117
- name: Build solution and generate NuGet Package

build/Build.fs

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let rootDir = __SOURCE_DIRECTORY__ </> ".."
1313
let solutionFile = "Flips.sln"
1414

1515
// Github repo
16-
let repo = "https://github.com/matthewcrews/flips"
16+
let repo = "https://github.com/fslaborg/flips"
1717

1818
// Read additional information from the release notes document
1919
let release = ReleaseNotes.load (rootDir @@ "RELEASE_NOTES.md")
@@ -186,43 +186,50 @@ let initTargets () =
186186
// --------------------------------------------------------------------------------------
187187
// Release Scripts
188188

189-
let gitPush msg =
190-
Git.Staging.stageAll ""
191-
Git.Commit.exec "" msg
192-
Git.Branches.push ""
193-
194-
Target.create "GitPush"
189+
Target.create "Publish"
195190
<| fun p ->
196-
p.Context.Arguments
197-
|> List.choose (fun s ->
198-
match s.StartsWith("--Msg=") with
199-
| true -> Some(s.Substring 6)
200-
| false -> None)
201-
|> List.tryHead
202-
|> function
203-
| Some(s) -> s
204-
| None -> (sprintf "Bump version to %s" release.NugetVersion)
205-
|> gitPush
206-
207-
Target.create "GitTag"
208-
<| fun _ ->
209-
Git.Branches.tag "" release.NugetVersion
210-
Git.Branches.pushTag "" "origin" release.NugetVersion
191+
// Expect version to be released a argument as a sanity check to prevent releases by accident.
192+
let announcedVersion =
193+
match p.Context.Arguments |> List.tryHead with
194+
| None -> failwithf "Please specify a version number, e.g. '... -t Publish 2.5.0'"
195+
| Some version -> version
196+
197+
if announcedVersion <> release.NugetVersion then
198+
failwithf
199+
"Version '%s' does not match latest version in the RELEASE_NOTES '%s'"
200+
announcedVersion
201+
release.NugetVersion
202+
203+
let currentBranch = Git.Information.getBranchName ""
204+
205+
if not (Git.Information.isCleanWorkingCopy "") then
206+
failwith "You must have a clean working copy to release. Please commit or stash your changes."
207+
208+
if currentBranch <> "main" then
209+
failwithf "You must be on the 'main' branch to release. Current branch is '%s'" currentBranch
210+
211+
let local = Git.Information.getCurrentSHA1 ""
212+
let remote = Git.Branches.getSHA1 "" ("origin/" + currentBranch)
213+
214+
if Git.Information.isAheadOf "" local remote then
215+
failwithf
216+
"Your local branch must not be ahead of the remote branch '%s'. Please push your changes before releasing."
217+
currentBranch
218+
219+
let tagName = sprintf "v%s" release.NugetVersion
220+
Git.Branches.tag "" tagName
211221

212222
// --------------------------------------------------------------------------------------
213223
// Run all targets by default. Invoke 'build -t <Target>' to override
214224

215225
Target.create "All" ignore
216226
Target.create "Dev" ignore
217227
Target.create "Release" ignore
218-
Target.create "Publish" ignore
219228

220229
"Clean" ==> "Restore" ==> "Build" |> ignore
221230

222231
"Build" ==> "RunTests" |> ignore
223232

224-
"All" ==> "GitPush" ?=> "GitTag" |> ignore
225-
226233
"All" <== [ "RunTests" ]
227234

228235
"CleanDocs" ==> "CopyDocFiles" ==> "PrepDocs" |> ignore
@@ -238,8 +245,7 @@ let initTargets () =
238245

239246
"Release" <== [ "All"; "NuGet"; "ConfigRelease" ]
240247

241-
"Publish"
242-
<== [ "Release"; "ConfigRelease"; "NuGetPublish"; "Build"; "GitTag"; "GitPush" ]
248+
"Release" ==> "Publish" |> ignore
243249

244250
[<EntryPoint>]
245251
let main argv =

0 commit comments

Comments
 (0)