Skip to content

Commit

Permalink
Merge pull request #23 from arturopala/custom-release-notes-arg
Browse files Browse the repository at this point in the history
add option to specify custom release notes appended at the bottom of the default ones
  • Loading branch information
jakobgrunig authored Oct 20, 2017
2 parents 84cc26e + dbe3545 commit fcfd64a
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 39 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ There are release and release candidate repositories in Bintray HMRC for standar
`java -jar target/scala-2.11/releaser-assembly-x.x.x.jar` artifact release-candidate-version release-version

##### Extra flags
- `-d | --dryRun`: perform a dry run of a relase. Downloads files and transforms but does not upload or create releases on github.com. Useful during development
- `--github-name-override`: provide a different github repository to the bintray package. The default is to assume the github repository has the same name as the Bintry repository and this flag allows the user to provide a differnt github.com repository name.
- `-d | --dryRun`: perform a dry run of a release. Downloads files and transforms but does not upload or create releases on github.com. Useful during development
- `--github-name-override`: provide a different github repository to the bintray package. The default is to assume the github repository has the same name as the Bintry repository and this flag allows the user to provide a different github.com repository name.
- `--release-notes`: custom release notes appended at the bottom of the default

#### Configuration Parameters
You can specify custom timeouts to be passed to the play.ws libraries that this project uses with the following System properties (-Dproperty.name=value)
Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/uk/gov/hmrc/releaser/ArgParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ object ArgParser{
githubNameOverride:Option[String] = None,
tag:Boolean = true,
verbose:Boolean = false,
dryRun:Boolean = false)
dryRun:Boolean = false,
releaseNotes: Option[String] = None)

val currentVersion = getClass.getPackage.getImplementationVersion

Expand All @@ -41,6 +42,8 @@ object ArgParser{
c.copy(releaseType = ReleaseType.withName(x)) } validate { x =>
if (ReleaseType.stringValues.contains(x)) success else failure(releaseTypeErrorMessage(x))
} text "the release type. Permitted values are: " + ReleaseType.stringValues.mkString(" ")
opt[String]("release-notes") action { (x, c) =>
c.copy(releaseNotes = Some(x)) } text "release notes"
opt[Boolean]("tag") action { (x, c) =>
c.copy(tag = x) } text "tag in github"
opt[String]("github-name-override") action { (x, c) =>
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/uk/gov/hmrc/releaser/Coordinator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class Coordinator(stageDir: Path,
def start(artefactName:String,
gitRepo:Repo,
releaseCandidateVersion: ReleaseCandidateVersion,
releaseType: ReleaseType.Value): Try[ReleaseVersion] = {
releaseType: ReleaseType.Value,
releaseNotes: Option[String]): Try[ReleaseVersion] = {

for {
targetVersion <- VersionNumberCalculator.calculateTarget(releaseCandidateVersion, releaseType)
Expand All @@ -51,7 +52,7 @@ class Coordinator(stageDir: Path,
transd <- transformFiles(repo, map, remotes)
_ <- uploadFiles(repo, map.targetArtefact, transd)
_ <- bintrayConnector.publish(map.targetArtefact)
_ <- githubConnector.createGithubTagAndRelease(new DateTime(), commitSha, commitAuthor, commitDate, artefactName, gitRepo, releaseCandidateVersion.value, targetVersion.value)
_ <- githubConnector.createGithubTagAndRelease(new DateTime(), commitSha, commitAuthor, commitDate, artefactName, gitRepo, releaseCandidateVersion.value, targetVersion.value, releaseNotes)
}
yield targetVersion
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/uk/gov/hmrc/releaser/Releaser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ object Releaser extends Logger {
parser.parse(args, Config()) match {
case Some(config) =>
val githubName = config.githubNameOverride.getOrElse(config.artefactName)
run(config.artefactName, ReleaseCandidateVersion(config.rcVersion), config.releaseType, githubName, config.dryRun)
run(config.artefactName, ReleaseCandidateVersion(config.rcVersion), config.releaseType, githubName, config.releaseNotes, config.dryRun)
case None => -1
}
}

def run(artefactName: String, rcVersion: ReleaseCandidateVersion, releaseType: ReleaseType.Value, gitHubName: String, dryRun: Boolean = false): Int = {
def run(artefactName: String, rcVersion: ReleaseCandidateVersion, releaseType: ReleaseType.Value, gitHubName: String, releaseNotes: Option[String], dryRun: Boolean = false): Int = {
val githubCredsFile = System.getProperty("user.home") + "/.github/.credentials"
val bintrayCredsFile = System.getProperty("user.home") + "/.bintray/.credentials"

Expand All @@ -69,7 +69,7 @@ object Releaser extends Logger {
val bintrayRepoConnector = new DefaultBintrayRepoConnector(directories.workDir, new BintrayHttp(bintrayCredsOpt.get), new FileDownloader)

val coordinator = new Coordinator(directories.stageDir, metaDataProvider, gitHubDetails, bintrayRepoConnector)
val result = coordinator.start(artefactName, Repo(gitHubName), rcVersion, releaseType)
val result = coordinator.start(artefactName, Repo(gitHubName), rcVersion, releaseType, releaseNotes)

result match {
case Success(targetVersion) =>
Expand Down
24 changes: 17 additions & 7 deletions src/main/scala/uk/gov/hmrc/releaser/github/GithubConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ class GithubConnector(githubHttp : GithubHttp, releaserVersion : String, comitte

def createGithubTagAndRelease(tagDate: DateTime, commitSha: CommitSha,
commitAuthor: String, commitDate: DateTime,
artefactName: String, gitRepo: Repo, releaseCandidateVersion: String, version: String): Try[Unit] =
artefactName: String, gitRepo: Repo, releaseCandidateVersion: String, version: String,
releaseNotes: Option[String]): Try[Unit] =
for (
tagSha <- createTagObject(tagDate, gitRepo, version, commitSha);
_ <- createTagRef(gitRepo, version, tagSha);
_ <- createRelease(commitSha, commitAuthor, commitDate, artefactName, gitRepo, releaseCandidateVersion, version))
_ <- createRelease(commitSha, commitAuthor, commitDate, artefactName, gitRepo, releaseCandidateVersion, version, releaseNotes))
yield ()

private def createTagObject(tagDate: DateTime, repo:Repo, tag: String, commitSha:CommitSha): Try[CommitSha] = {
Expand All @@ -95,11 +96,12 @@ class GithubConnector(githubHttp : GithubHttp, releaserVersion : String, comitte

private def createRelease(commitSha: CommitSha, commitAuthor: String,
commitDate: DateTime, artefactName: String,
gitRepo: Repo, releaseCandidateVersion: String, version: String): Try[Unit] = {
gitRepo: Repo, releaseCandidateVersion: String, version: String,
releaseNotes: Option[String]): Try[Unit] = {
log.debug(s"creating release from $commitSha version " + version)

val url = buildReleasePostUrl(gitRepo)
val message = buildMessage(artefactName, version, releaserVersion, releaseCandidateVersion, commitSha, commitAuthor, commitDate)
val message = buildMessage(artefactName, version, releaserVersion, releaseCandidateVersion, commitSha, commitAuthor, commitDate, releaseNotes)
val body = buildReleaseBody(message, version)

githubHttp.postUnit(url, body)
Expand All @@ -120,12 +122,19 @@ class GithubConnector(githubHttp : GithubHttp, releaserVersion : String, comitte
Json.toJson(GitRelease(version, tagName, message, draft = false, prerelease = false))
}

private def customReleaseNotes(releaseNotesOpt: Option[String]) =
releaseNotesOpt.map(releaseNotes =>
s"""|
|$releaseNotes""".stripMargin
).getOrElse("")

private def buildMessage(
name: String,
version: String,
releaserVersion: String,
releaseCandidateVersion: String,
commitSha: CommitSha, commitAuthor: String, commitDate: DateTime) =
commitSha: CommitSha, commitAuthor: String, commitDate: DateTime,
releaseNotes: Option[String]) =
s"""
|Release : $name $version
|Release candidate : $name $releaseCandidateVersion
Expand All @@ -134,7 +143,8 @@ class GithubConnector(githubHttp : GithubHttp, releaserVersion : String, comitte
|Last commit author : $commitAuthor
|Last commit time : ${DateTimeFormat.longDateTime().print(commitDate)}
|
|Release and tag created by [Releaser](https://github.com/hmrc/releaser) $releaserVersion""".stripMargin
|Release and tag created by [Releaser](https://github.com/hmrc/releaser) $releaserVersion
|${customReleaseNotes(releaseNotes)}""".stripMargin

private def buildCommitGetUrl(repo:Repo, sha:CommitSha)={
s"https://api.github.com/repos/hmrc/${repo.value}/git/commits/$sha"
Expand All @@ -161,5 +171,5 @@ class DryRunGithubConnector(releaserVersion: String) extends GithubTagAndRelease

def createGithubTagAndRelease(tagDate: DateTime, commitSha: CommitSha,
commitAuthor: String, commitDate: DateTime,
artefactName: String, gitRepo: Repo, releaseCandidateVersion: String, version: String): Try[Unit] = Success(Unit)
artefactName: String, gitRepo: Repo, releaseCandidateVersion: String, version: String, releaseNotes: Option[String]): Try[Unit] = Success(Unit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ import scala.util.Try

trait GithubTagAndRelease {

def verifyGithubTagExists(repo:Repo, sha:CommitSha): Try[Unit]
def verifyGithubTagExists(repo: Repo, sha: CommitSha): Try[Unit]

def createGithubTagAndRelease(tagDate: DateTime, commitSha: CommitSha,
commitAuthor: String, commitDate: DateTime,
artefactName: String, gitRepo: Repo, releaseCandidateVersion: String, version: String): Try[Unit]
def createGithubTagAndRelease(tagDate: DateTime,
commitSha: CommitSha,
commitAuthor: String,
commitDate: DateTime,
artefactName: String,
gitRepo: Repo,
releaseCandidateVersion: String,
version: String,
releaseNotes: Option[String]): Try[Unit]

}
20 changes: 10 additions & 10 deletions src/test/scala/uk/gov/hmrc/releaser/CoordinatorSpecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
bintrayFiles = Set(s"$root/libr_2.11-1.3.0-1-g21312cc.pom", s"$root/libr_2.11-1.3.0-1-g21312cc-assembly.jar"))

val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector)
coordinator.start("libr", Repo("libr"), ReleaseCandidateVersion("1.3.0-1-g21312cc"), ReleaseType.HOTFIX) match {
coordinator.start("libr", Repo("libr"), ReleaseCandidateVersion("1.3.0-1-g21312cc"), ReleaseType.HOTFIX, None) match {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
fail(e)
Expand Down Expand Up @@ -106,7 +106,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
s"$root/help-frontend_2.11-1.26.0-3-gd7ed03c-sources.jar"))

val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector)
coordinator.start("help-frontend", Repo("help-frontend"), ReleaseCandidateVersion("1.26.0-3-gd7ed03c"), ReleaseType.MAJOR) match {
coordinator.start("help-frontend", Repo("help-frontend"), ReleaseCandidateVersion("1.26.0-3-gd7ed03c"), ReleaseType.MAJOR, None) match {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
fail(e)
Expand Down Expand Up @@ -143,7 +143,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
bintrayFiles = Set(s"$root/time_2.11-1.3.0-1-g21312cc.pom"))

val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector)
coordinator.start("time", Repo("time"), ReleaseCandidateVersion("1.3.0-1-g21312cc"), ReleaseType.MINOR) match {
coordinator.start("time", Repo("time"), ReleaseCandidateVersion("1.3.0-1-g21312cc"), ReleaseType.MINOR, None) match {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
fail(e)
Expand Down Expand Up @@ -184,7 +184,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
))

val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeBintrayRepoConnector)
coordinator.start("time", Repo("time"), ReleaseCandidateVersion("1.3.0-1-g21312cc"), ReleaseType.MINOR) match {
coordinator.start("time", Repo("time"), ReleaseCandidateVersion("1.3.0-1-g21312cc"), ReleaseType.MINOR, None) match {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
fail(e)
Expand Down Expand Up @@ -228,7 +228,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
s"$root/paye-estimator_sjs0.6_2.11-0.1.0-1-g1906708-javadoc.jar"))

val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector)
coordinator.start("paye-estimator", Repo("paye-estimator"), ReleaseCandidateVersion("0.1.0-1-g1906708"), ReleaseType.MINOR) match {
coordinator.start("paye-estimator", Repo("paye-estimator"), ReleaseCandidateVersion("0.1.0-1-g1906708"), ReleaseType.MINOR, None) match {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
fail(e)
Expand Down Expand Up @@ -272,7 +272,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
s"$root/paye-estimator_sjs0.6_2.11-0.1.0-1-g1906708.zip"))

val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector)
coordinator.start("paye-estimator", Repo("paye-estimator"), ReleaseCandidateVersion("0.1.0-1-g1906708"), ReleaseType.MINOR) match {
coordinator.start("paye-estimator", Repo("paye-estimator"), ReleaseCandidateVersion("0.1.0-1-g1906708"), ReleaseType.MINOR, None) match {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
fail(e)
Expand Down Expand Up @@ -305,7 +305,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
bintrayFiles = Set(s"$root/time_2.11-1.3.0-1-g21312cc.pom"))

val coordinator = new Coordinator(tempDir(), metaDataProvider, taggerAndReleaser, fakeRepoConnector)
coordinator.start("time", Repo("time"), aReleaseCandidateVersion, ReleaseType.MINOR) match {
coordinator.start("time", Repo("time"), aReleaseCandidateVersion, ReleaseType.MINOR, None) match {
case Failure(e) => e shouldBe expectedException
case Success(s) => fail(s"Should have failed with $expectedException")
}
Expand All @@ -320,7 +320,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
bintrayFiles = Set(s"$root/time_2.11-1.3.0-1-g21312cc.pom"), targetExists = true)

val coordinator = new Coordinator(tempDir(), mock[MetaDataProvider], new FakeGithubTagAndRelease, fakeRepoConnector)
coordinator.start("time", Repo("time"), aReleaseCandidateVersion, ReleaseType.MINOR) match {
coordinator.start("time", Repo("time"), aReleaseCandidateVersion, ReleaseType.MINOR, None) match {
case Failure(e) => e shouldBe an [IllegalArgumentException]
case Success(s) => fail(s"Should have failed with an IllegalArgumentException")
}
Expand All @@ -333,7 +333,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
}

val coordinator = new Coordinator(tempDir(), mock[MetaDataProvider], new FakeGithubTagAndRelease, fakeRepoConnector)
coordinator.start("a", Repo("a"), aReleaseCandidateVersion, ReleaseType.MINOR) match {
coordinator.start("a", Repo("a"), aReleaseCandidateVersion, ReleaseType.MINOR, None) match {
case Failure(e) => e.getMessage shouldBe "Didn't find a release candidate repository for 'a' in repos List(release-candidates, sbt-plugin-release-candidates)"
case Success(s) => fail(s"Should have failed")
}
Expand All @@ -357,7 +357,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
}

val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector)
coordinator.start("sbt-bobby", Repo("sbt-bobby"), ReleaseCandidateVersion("0.8.1-4-ge733d26"), ReleaseType.HOTFIX) match {
coordinator.start("sbt-bobby", Repo("sbt-bobby"), ReleaseCandidateVersion("0.8.1-4-ge733d26"), ReleaseType.HOTFIX, None) match {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
fail(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import scala.util.{Success, Try}
class FakeGithubTagAndRelease extends GithubTagAndRelease {
override def createGithubTagAndRelease(tagDate: DateTime, commitSha: CommitSha,
commitAuthor: String, commitDate: DateTime,
artefactName: String, gitRepo: Repo, releaseCandidateVersion: String, version: String): Try[Unit] = Success(Unit)
artefactName: String, gitRepo: Repo, releaseCandidateVersion: String, version: String, releaseNotes: Option[String]): Try[Unit] = Success(Unit)

override def verifyGithubTagExists(repo: Repo, sha: CommitSha): Try[Unit] = Success(Unit)
}
Loading

0 comments on commit fcfd64a

Please sign in to comment.