Skip to content

Commit a020eaa

Browse files
committed
setup release and publish stages
- if changelog has unreleased tag, it is a preview and github has pre- release flag. long tag x.y.z-commit - if changelog is final, release is full. Short tag x.y.z
1 parent 81c2b53 commit a020eaa

File tree

6 files changed

+343
-210
lines changed

6 files changed

+343
-210
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,4 @@ __pycache__/
301301
/e2e/data/cache/
302302
/e2e/stress/paket-*/
303303
/e2e/stress/paket/paket.lock
304+
/pkg/

build.fsx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ open Fake.DotNet
1111
open Fake.Core
1212
open Fake.Tools.Git.CommandHelper
1313
open Fake.Tools.Git
14+
open Fake.Api
1415
open Fake.DotNet.Testing.XUnit2
1516
open Fake.Testing.Common
1617
open System.Linq
1718

1819
let project = "BaGet"
20+
let gitOwner = "ai-traders"
1921
// Pattern specifying assemblies to be tested using XUnit
2022
let testAssemblies = !! "tests/*.Tests/bin/Release/*/publish/*.Tests.dll"
2123

2224
// Read additional information from the release notes document
25+
let changelogFile = "CHANGELOG.md"
2326
let release = File.read "CHANGELOG.md" |> ReleaseNotes.parse
2427
let changelogVersion = release.AssemblyVersion
2528

@@ -172,10 +175,77 @@ Target.create "RunTests" (fun _ ->
172175
})
173176
)
174177

178+
// --------------------------------------------------------------------------------------
179+
// Releases
180+
181+
let changelogUnreleased =
182+
let changeLogString = File.readAsString changelogFile
183+
changeLogString.Contains("Unreleased")
184+
185+
let gitDir = (findGitDir System.Environment.CurrentDirectory).FullName
186+
let currentSha = gitDir |> Information.getCurrentSHA1
187+
let tagVersion =
188+
if changelogUnreleased then
189+
sprintf "%s-%s" release.AssemblyVersion (currentSha.Substring(0, 8))
190+
else
191+
release.AssemblyVersion
192+
193+
let isCurrentCommitTagged =
194+
let ok,msg,error = runGitCommand gitDir <| sprintf "describe --contains %s" currentSha
195+
if ok then
196+
Trace.tracefn "Current SHA %s is tagged" currentSha
197+
else
198+
Trace.tracefn "Current SHA %s is not tagged" currentSha
199+
ok
200+
201+
let zipFile = sprintf @"pkg/baget-%s.zip" tagVersion
202+
203+
Target.create "Zip" (fun _ ->
204+
Directory.create "pkg"
205+
!! "src/BaGet/bin/Release/netcoreapp2.1/publish/**/*"
206+
|> Zip.zip "src/BaGet/bin/Release/netcoreapp2.1/publish" zipFile
207+
)
208+
209+
Target.create "GitTag" (fun _ ->
210+
if isCurrentCommitTagged then
211+
failwithf "Already tagged"
212+
if changelogUnreleased then
213+
Trace.tracefn "Changelog is set as Unreleased - this is a preview release"
214+
215+
Trace.tracefn "Executing git tag version=%s" tagVersion
216+
Branches.tag gitDir tagVersion
217+
Branches.pushTag gitDir "origin" tagVersion
218+
Trace.tracefn "Released code version=%s" tagVersion
219+
)
220+
221+
Target.create "GitHubRelease" (fun _ ->
222+
let token =
223+
match Environment.environVarOrDefault "GITHUB_TOKEN" "" with
224+
| s when not (System.String.IsNullOrWhiteSpace s) -> s
225+
| _ -> failwith "please set the GITHUB_TOKEN environment variable to a github personal access token with repro access."
226+
227+
let notes =
228+
if changelogUnreleased then
229+
[
230+
"*This is a preview release, which has passed all end-to-end tests, but may not contain all final features.*\n"
231+
sprintf "Try docker image `tomzo/baget:%s`\n" tagVersion
232+
]
233+
else
234+
(sprintf "Docker image `tomzo/baget:%s`\n" tagVersion)::release.Notes
235+
236+
GitHub.createClientWithToken token
237+
|> GitHub.draftNewRelease gitOwner project tagVersion changelogUnreleased notes
238+
|> GitHub.uploadFiles [zipFile]
239+
|> GitHub.publishDraft
240+
|> Async.RunSynchronously)
241+
175242
open Fake.Core.TargetOperators
176243

177244
Target.create "All" ignore
178245

246+
"GitTag" ==> "GitHubRelease"
247+
"Zip" ==> "GitHubRelease"
248+
179249
"SpaRestore"
180250
==> "SpaBuild"
181251
==> "SpaPublish"

gocd/pipeline.gocd.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,56 @@ pipelines:
109109
arguments:
110110
- -c
111111
- dmesg | tail -n 100
112+
- publish:
113+
clean_workspace: true
114+
jobs:
115+
docker_private:
116+
resources:
117+
- docker_builder
118+
tasks:
119+
- fetch:
120+
stage: test_pack
121+
job: docker
122+
source: imagerc
123+
destination:
124+
is_file: true
125+
- exec:
126+
command: /bin/bash
127+
arguments:
128+
- -c
129+
- ./tasks.sh publish_docker_private
130+
docker_public:
131+
resources:
132+
- docker_builder
133+
secure_variables:
134+
DOCKERHUB_PASSWORD: CioRNFm+WifCZPcqU+78+A==
135+
tasks:
136+
- fetch:
137+
stage: test_pack
138+
job: docker
139+
source: imagerc
140+
destination:
141+
is_file: true
142+
- exec:
143+
command: /bin/bash
144+
arguments:
145+
- -c
146+
- ./tasks.sh publish_docker_public
147+
- github_release:
148+
clean_workspace: true
149+
jobs:
150+
github:
151+
elastic_profile_id: w.c2.m2048.e10
152+
secure_variables:
153+
GITHUB_TOKEN: J2VpEh3xtuzZuU+kaHVCLM/glpKCSXKhGt3XCmZZTOLARPVLXFPKUaKiqeQ5smiT
154+
tasks:
155+
- fetch:
156+
stage: build
157+
job: build
158+
source: src/BaGet/bin/Release/netcoreapp2.1/publish
159+
destination: src/BaGet/bin/Release/netcoreapp2.1
160+
- exec:
161+
command: /bin/bash
162+
arguments:
163+
- -c
164+
- ./tasks.sh github_release

paket.dependencies

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ group Tools
3333
nuget Fake.Core.ReleaseNotes
3434
nuget Fake.DotNet.Cli
3535
nuget Fake.Tools.Git
36+
nuget Fake.Api.GitHub
3637
nuget Fake.DotNet.Testing.XUnit2
38+
nuget Fake.IO.Zip
3739

3840
group Test
3941
source https://api.nuget.org/v3/index.json

0 commit comments

Comments
 (0)