Skip to content

Commit

Permalink
[PLATOPS-977] adding support for providing scala version via CLI para…
Browse files Browse the repository at this point in the history
…meter for the Maven artefacts
  • Loading branch information
arminio committed Jun 5, 2017
1 parent 1490fa5 commit c614e6c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
3 changes: 3 additions & 0 deletions src/main/scala/uk/gov/hmrc/releaser/ArgParser.scala
Expand Up @@ -25,6 +25,7 @@ object ArgParser{
githubNameOverride:Option[String] = None,
tag:Boolean = true,
verbose:Boolean = false,
scalaVersion: String = "2.11",
dryRun:Boolean = false)

val currentVersion = getClass.getPackage.getImplementationVersion
Expand All @@ -47,6 +48,8 @@ object ArgParser{
c.copy(githubNameOverride = Option(x)) } text "provide a different github repository to the bintray package"
opt[Boolean]('v', "verbose") action { (x, c) =>
c.copy(verbose = x) } text "verbose mode (not implemented)"
opt[String]("scalaversion").abbr("sv").optional() action { (x, c) =>
c.copy(scalaVersion = x) } text "provide the scala version to be used by the releaser (eg: 2.12)"
opt[Unit]('d', "dryRun") action { (_, c) =>
c.copy(dryRun = true) } text "dry run"
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/uk/gov/hmrc/releaser/Coordinator.scala
Expand Up @@ -29,9 +29,10 @@ import scala.util.{Failure, Success, Try}
class Coordinator(stageDir: Path,
metaDataProvider: MetaDataProvider,
githubConnector: GithubTagAndRelease,
bintrayConnector: BintrayRepoConnector) extends Logger {
bintrayConnector: BintrayRepoConnector,
scalaVersion: String) extends Logger {

val repositoryFlavors = Seq(mavenRepository, ivyRepository)
val repositoryFlavors = Seq(mavenRepository(scalaVersion), ivyRepository)

def start(artefactName:String,
gitRepo:Repo,
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/uk/gov/hmrc/releaser/Releaser.scala
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.scalaVersion, 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, scalaVersion: String, dryRun: Boolean = false): Int = {
val githubCredsFile = System.getProperty("user.home") + "/.github/.credentials"
val bintrayCredsFile = System.getProperty("user.home") + "/.bintray/.credentials"

Expand All @@ -68,7 +68,7 @@ object Releaser extends Logger {
val bintrayDetails = if (dryRun) BintrayRepoConnector.dryRun(bintrayCredsOpt.get, directories.workDir) else BintrayRepoConnector(bintrayCredsOpt.get, directories.workDir)
val bintrayRepoConnector = new DefaultBintrayRepoConnector(directories.workDir, new BintrayHttp(bintrayCredsOpt.get), new FileDownloader)

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

result match {
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/uk/gov/hmrc/releaser/Repositories.scala
Expand Up @@ -35,12 +35,14 @@ trait IvyRepo extends RepoFlavour with BintrayIvyPaths {
}

trait MavenRepo extends RepoFlavour with BintrayMavenPaths {
val scalaVersion = "2.11"
// val scalaVersion = "2.11"
val artefactBuilder = MavenArtefacts.apply _
}

object RepoFlavours {
val mavenRepository: RepoFlavour = new BintrayRepository("release-candidates", "releases") with MavenRepo
def mavenRepository(scalaVer:String): RepoFlavour = new BintrayRepository("release-candidates", "releases") with MavenRepo {
override def scalaVersion: String = scalaVer
}
val ivyRepository: RepoFlavour = new BintrayRepository("sbt-plugin-release-candidates", "sbt-plugin-releases") with IvyRepo
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/uk/gov/hmrc/releaser/ArtefactsSpecs.scala
Expand Up @@ -91,7 +91,7 @@ class ArtefactsSpecs extends WordSpec with Matchers with OptionValues{
rcVersion:String = "1.3.0-1-g21312cc",
releaseVersion:String = "1.4.0") =
VersionMapping(
RepoFlavours.mavenRepository,
RepoFlavours.mavenRepository("2.11"),
artefactName,
Repo(repoName),
ReleaseCandidateVersion(rcVersion),
Expand Down
18 changes: 9 additions & 9 deletions src/test/scala/uk/gov/hmrc/releaser/CoordinatorSpecs.scala
Expand Up @@ -56,7 +56,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
jarResource = Some(s"$root/libr_2.11-1.3.0-1-g21312cc.jar"),
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)
val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector, "2.11")
coordinator.start("libr", Repo("libr"), ReleaseCandidateVersion("1.3.0-1-g21312cc"), ReleaseType.HOTFIX) match {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
Expand Down Expand Up @@ -105,7 +105,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
s"$root/help-frontend_2.11-1.26.0-3-gd7ed03c.tgz.asc.md5",
s"$root/help-frontend_2.11-1.26.0-3-gd7ed03c-sources.jar"))

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

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

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

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

val coordinator = new Coordinator(tempDir(), metaDataProvider, taggerAndReleaser, fakeRepoConnector)
val coordinator = new Coordinator(tempDir(), metaDataProvider, taggerAndReleaser, fakeRepoConnector, "2.11")
coordinator.start("time", Repo("time"), aReleaseCandidateVersion, ReleaseType.MINOR) match {
case Failure(e) => e shouldBe expectedException
case Success(s) => fail(s"Should have failed with $expectedException")
Expand All @@ -277,7 +277,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
jarResource = Some(s"$root/time_2.11-1.3.0-1-g21312cc.jar"),
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)
val coordinator = new Coordinator(tempDir(), mock[MetaDataProvider], new FakeGithubTagAndRelease, fakeRepoConnector, "2.11")
coordinator.start("time", Repo("time"), aReleaseCandidateVersion, ReleaseType.MINOR) match {
case Failure(e) => e shouldBe an [IllegalArgumentException]
case Success(s) => fail(s"Should have failed with an IllegalArgumentException")
Expand All @@ -290,7 +290,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
override def getRepoMetaData(repoName: String, artefactName: String): Try[Unit] = Failure(new RuntimeException)
}

val coordinator = new Coordinator(tempDir(), mock[MetaDataProvider], new FakeGithubTagAndRelease, fakeRepoConnector)
val coordinator = new Coordinator(tempDir(), mock[MetaDataProvider], new FakeGithubTagAndRelease, fakeRepoConnector, "2.11")
coordinator.start("a", Repo("a"), aReleaseCandidateVersion, ReleaseType.MINOR) 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 @@ -314,7 +314,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
}
}

val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector)
val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector, "2.11")
coordinator.start("sbt-bobby", Repo("sbt-bobby"), ReleaseCandidateVersion("0.8.1-4-ge733d26"), ReleaseType.HOTFIX) match {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
Expand Down

0 comments on commit c614e6c

Please sign in to comment.