Skip to content

Commit

Permalink
setup release and publish stages
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tomzo committed Oct 9, 2018
1 parent 81c2b53 commit a020eaa
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 210 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,4 @@ __pycache__/
/e2e/data/cache/
/e2e/stress/paket-*/
/e2e/stress/paket/paket.lock
/pkg/
70 changes: 70 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ open Fake.DotNet
open Fake.Core
open Fake.Tools.Git.CommandHelper
open Fake.Tools.Git
open Fake.Api
open Fake.DotNet.Testing.XUnit2
open Fake.Testing.Common
open System.Linq

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

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

Expand Down Expand Up @@ -172,10 +175,77 @@ Target.create "RunTests" (fun _ ->
})
)

// --------------------------------------------------------------------------------------
// Releases

let changelogUnreleased =
let changeLogString = File.readAsString changelogFile
changeLogString.Contains("Unreleased")

let gitDir = (findGitDir System.Environment.CurrentDirectory).FullName
let currentSha = gitDir |> Information.getCurrentSHA1
let tagVersion =
if changelogUnreleased then
sprintf "%s-%s" release.AssemblyVersion (currentSha.Substring(0, 8))
else
release.AssemblyVersion

let isCurrentCommitTagged =
let ok,msg,error = runGitCommand gitDir <| sprintf "describe --contains %s" currentSha
if ok then
Trace.tracefn "Current SHA %s is tagged" currentSha
else
Trace.tracefn "Current SHA %s is not tagged" currentSha
ok

let zipFile = sprintf @"pkg/baget-%s.zip" tagVersion

Target.create "Zip" (fun _ ->
Directory.create "pkg"
!! "src/BaGet/bin/Release/netcoreapp2.1/publish/**/*"
|> Zip.zip "src/BaGet/bin/Release/netcoreapp2.1/publish" zipFile
)

Target.create "GitTag" (fun _ ->
if isCurrentCommitTagged then
failwithf "Already tagged"
if changelogUnreleased then
Trace.tracefn "Changelog is set as Unreleased - this is a preview release"

Trace.tracefn "Executing git tag version=%s" tagVersion
Branches.tag gitDir tagVersion
Branches.pushTag gitDir "origin" tagVersion
Trace.tracefn "Released code version=%s" tagVersion
)

Target.create "GitHubRelease" (fun _ ->
let token =
match Environment.environVarOrDefault "GITHUB_TOKEN" "" with
| s when not (System.String.IsNullOrWhiteSpace s) -> s
| _ -> failwith "please set the GITHUB_TOKEN environment variable to a github personal access token with repro access."

let notes =
if changelogUnreleased then
[
"*This is a preview release, which has passed all end-to-end tests, but may not contain all final features.*\n"
sprintf "Try docker image `tomzo/baget:%s`\n" tagVersion
]
else
(sprintf "Docker image `tomzo/baget:%s`\n" tagVersion)::release.Notes

GitHub.createClientWithToken token
|> GitHub.draftNewRelease gitOwner project tagVersion changelogUnreleased notes
|> GitHub.uploadFiles [zipFile]
|> GitHub.publishDraft
|> Async.RunSynchronously)

open Fake.Core.TargetOperators

Target.create "All" ignore

"GitTag" ==> "GitHubRelease"
"Zip" ==> "GitHubRelease"

"SpaRestore"
==> "SpaBuild"
==> "SpaPublish"
Expand Down
53 changes: 53 additions & 0 deletions gocd/pipeline.gocd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,56 @@ pipelines:
arguments:
- -c
- dmesg | tail -n 100
- publish:
clean_workspace: true
jobs:
docker_private:
resources:
- docker_builder
tasks:
- fetch:
stage: test_pack
job: docker
source: imagerc
destination:
is_file: true
- exec:
command: /bin/bash
arguments:
- -c
- ./tasks.sh publish_docker_private
docker_public:
resources:
- docker_builder
secure_variables:
DOCKERHUB_PASSWORD: CioRNFm+WifCZPcqU+78+A==
tasks:
- fetch:
stage: test_pack
job: docker
source: imagerc
destination:
is_file: true
- exec:
command: /bin/bash
arguments:
- -c
- ./tasks.sh publish_docker_public
- github_release:
clean_workspace: true
jobs:
github:
elastic_profile_id: w.c2.m2048.e10
secure_variables:
GITHUB_TOKEN: J2VpEh3xtuzZuU+kaHVCLM/glpKCSXKhGt3XCmZZTOLARPVLXFPKUaKiqeQ5smiT
tasks:
- fetch:
stage: build
job: build
source: src/BaGet/bin/Release/netcoreapp2.1/publish
destination: src/BaGet/bin/Release/netcoreapp2.1
- exec:
command: /bin/bash
arguments:
- -c
- ./tasks.sh github_release
2 changes: 2 additions & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ group Tools
nuget Fake.Core.ReleaseNotes
nuget Fake.DotNet.Cli
nuget Fake.Tools.Git
nuget Fake.Api.GitHub
nuget Fake.DotNet.Testing.XUnit2
nuget Fake.IO.Zip

group Test
source https://api.nuget.org/v3/index.json
Expand Down
Loading

0 comments on commit a020eaa

Please sign in to comment.