Skip to content

Commit

Permalink
PLATOPS-1013 - Remove the scala version from the Releaser to make it …
Browse files Browse the repository at this point in the history
…release across Scala versions
  • Loading branch information
thomas-vogel444 committed Jun 21, 2017
1 parent c614e6c commit 84cc26e
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 36 deletions.
3 changes: 0 additions & 3 deletions src/main/scala/uk/gov/hmrc/releaser/ArgParser.scala
Expand Up @@ -25,7 +25,6 @@ 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 @@ -48,8 +47,6 @@ 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
8 changes: 4 additions & 4 deletions src/main/scala/uk/gov/hmrc/releaser/Coordinator.scala
Expand Up @@ -29,10 +29,9 @@ import scala.util.{Failure, Success, Try}
class Coordinator(stageDir: Path,
metaDataProvider: MetaDataProvider,
githubConnector: GithubTagAndRelease,
bintrayConnector: BintrayRepoConnector,
scalaVersion: String) extends Logger {
bintrayConnector: BintrayRepoConnector) extends Logger {

val repositoryFlavors = Seq(mavenRepository(scalaVersion), ivyRepository)
val repositoryFlavors: Seq[RepoFlavour] = Seq(mavenRepository, ivyRepository)

def start(artefactName:String,
gitRepo:Repo,
Expand Down Expand Up @@ -75,8 +74,9 @@ class Coordinator(stageDir: Path,

private def getMetaData(repo: RepoFlavour, map: VersionMapping, files: List[String]): Try[ArtefactMetaData] = {

// To get the metadata, you only need one of the jars irrespective of having multiple scala versions
val jarPath = for {
jarFileName <- files.find(f => f.endsWith(repo.jarFilenameFor(map.sourceArtefact)))
jarFileName <- files.find(f => f.endsWith(repo.jarFilenameEndingFor(map.sourceArtefact)))
jarUrl = repo.fileDownloadFor(map.sourceArtefact, jarFileName)
jarPath <- bintrayConnector.findJar(jarFileName, jarUrl, map.sourceArtefact)
}
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.scalaVersion, config.dryRun)
run(config.artefactName, ReleaseCandidateVersion(config.rcVersion), config.releaseType, githubName, config.dryRun)
case None => -1
}
}

def run(artefactName: String, rcVersion: ReleaseCandidateVersion, releaseType: ReleaseType.Value, gitHubName: String, scalaVersion: String, dryRun: Boolean = false): Int = {
def run(artefactName: String, rcVersion: ReleaseCandidateVersion, releaseType: ReleaseType.Value, gitHubName: 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, scalaVersion)
val coordinator = new Coordinator(directories.stageDir, metaDataProvider, gitHubDetails, bintrayRepoConnector)
val result = coordinator.start(artefactName, Repo(gitHubName), rcVersion, releaseType)

result match {
Expand Down
8 changes: 3 additions & 5 deletions src/main/scala/uk/gov/hmrc/releaser/Repositories.scala
Expand Up @@ -22,15 +22,15 @@ import uk.gov.hmrc.releaser.bintray.{BintrayIvyPaths, BintrayMavenPaths, Bintray

trait RepoFlavour extends BintrayPaths {

def scalaVersion: String
// def scalaVersion: String
def releaseCandidateRepo: String
def releaseRepo: String

val artefactBuilder:(VersionMapping, Path) => TransformerProvider
}

trait IvyRepo extends RepoFlavour with BintrayIvyPaths {
val scalaVersion = "2.10"
// val scalaVersion = "2.10"
val artefactBuilder = IvyArtefacts.apply _
}

Expand All @@ -40,9 +40,7 @@ trait MavenRepo extends RepoFlavour with BintrayMavenPaths {
}

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

Expand Down
Expand Up @@ -39,7 +39,7 @@ trait BintrayPaths {
val packageExistsRoot = s"https://bintray.com/hmrc/"

def releaseExistsFor(v: VersionDescriptor): String
def jarFilenameFor(v: VersionDescriptor): String
def jarFilenameEndingFor(v: VersionDescriptor): String

def fileDownloadFor(v: VersionDescriptor, fileName:String): String
def fileUploadFor(v: VersionDescriptor, fileName:String): String
Expand All @@ -50,7 +50,7 @@ trait BintrayIvyPaths extends BintrayPaths {
s"$packageExistsRoot/${v.repo}/${`package`}/${v.version}"
}

override def jarFilenameFor(v:VersionDescriptor):String={
override def jarFilenameEndingFor(v:VersionDescriptor):String={
s"${v.artefactName}.jar"
}

Expand All @@ -64,14 +64,13 @@ trait BintrayIvyPaths extends BintrayPaths {
}

trait BintrayMavenPaths extends BintrayPaths {
def scalaVersion: String

def releaseExistsFor(v:VersionDescriptor) : String = {
s"$packageExistsRoot/${v.repo}/$path/${v.version}"
}

def jarFilenameFor(v:VersionDescriptor) : String = {
s"${v.artefactName}_$scalaVersion-${v.version}.jar"
def jarFilenameEndingFor(v:VersionDescriptor) : String = {
s"-${v.version}.jar"
}

def fileDownloadFor(v: VersionDescriptor, fileName:String)={
Expand Down
Binary file not shown.
@@ -0,0 +1,108 @@
<?xml version='1.0' encoding='UTF-8'?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>uk.gov.hmrc</groupId>
<artifactId>time_2.11</artifactId>
<packaging>jar</packaging>
<description>time</description>
<version>1.3.0-1-g21312cc</version>
<licenses>
<license>
<name>Apache-2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<name>time</name>
<organization>
<name>uk.gov.hmrc</name>
</organization>
<url>https://www.gov.uk/government/organisations/hm-revenue-customs</url>
<licenses>
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<scm>
<connection>scm:git@github.com:hmrc/time.git</connection>
<developerConnection>scm:git@github.com:hmrc/time.git</developerConnection>
<url>git@github.com:hmrc/time.git</url>
</scm>
<developers>
<developer>
<id>duncancrawford</id>
<name>Duncan Crawford</name>
<url>http://www.equalexperts.com</url>
</developer>
<developer>
<id>xnejp03</id>
<name>Petr Nejedly</name>
<url>http://www.equalexperts.com</url>
</developer>
<developer>
<id>alvarovilaplana</id>
<name>Alvaro Vilaplana</name>
<url>http://www.equalexperts.com</url>
</developer>
<developer>
<id>jakobgrunig</id>
<name>Jakob Grunig</name>
<url>http://www.equalexperts.com</url>
</developer>
<developer>
<id>vaughansharman</id>
<name>Vaughan Sharman</name>
<url>http://www.equalexperts.com</url>
</developer>
<developer>
<id>davesammut</id>
<name>Dave Sammut</name>
<url>http://www.equalexperts.com</url>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.6</version>
</dependency>
<dependency>
<groupId>com.github.nscala-time</groupId>
<artifactId>nscala-time_2.11</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.11</artifactId>
<version>2.2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.pegdown</groupId>
<artifactId>pegdown</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>typesafereleases</id>
<name>typesafe-releases</name>
<url>http://repo.typesafe.com/typesafe/releases/</url>
<layout>default</layout>
</repository>
<repository>
<id>sonatypereleases</id>
<name>sonatype-releases</name>
<url>https://oss.sonatype.org/content/repositories/releases/</url>
<layout>default</layout>
</repository>
<repository>
<id>bintrayhmrcreleases</id>
<name>bintray-hmrc-releases</name>
<url>https://dl.bintray.com/hmrc/releases/</url>
<layout>default</layout>
</repository>
</repositories>
</project>
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("2.11"),
RepoFlavours.mavenRepository,
artefactName,
Repo(repoName),
ReleaseCandidateVersion(rcVersion),
Expand Down
60 changes: 51 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, "2.11")
val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector)
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, "2.11")
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 {
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, "2.11")
val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector)
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 All @@ -166,6 +166,48 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
pomVersionText shouldBe "1.4.0"
}

"release version 1.4.0 of a maven-based library with multiple Scala versions when given the inputs 'time', '1.3.0-1-g21312cc' and 'minor' as the artefact, release candidate and release type" in {

val metaDataProvider = mock[MetaDataProvider]
when(metaDataProvider.fromJarFile(any())).thenReturn(Success(ArtefactMetaData("sha", "author", DateTime.now())))

val root_2_11 = "uk/gov/hmrc/time_2.11/1.3.0-1-g21312cc"
val root_2_12 = "uk/gov/hmrc/time_2.12/1.3.0-1-g21312cc"

val fakeBintrayRepoConnector = new FakeBintrayRepoConnector(
"/time/",
jarResource = Some(s"$root_2_11/time_2.11-1.3.0-1-g21312cc.jar"),
bintrayFiles = Set(
s"$root_2_11/time_2.11-1.3.0-1-g21312cc.pom",
s"$root_2_12/time_2.12-1.3.0-1-g21312cc.jar",
s"$root_2_12/time_2.12-1.3.0-1-g21312cc.pom"
))

val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeBintrayRepoConnector)
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}")
fail(e)
case _ =>
}

fakeBintrayRepoConnector.uploadedFiles.size shouldBe 4
fakeBintrayRepoConnector.lastPublishDescriptor should not be None

val Some((pomVersion, pomFile, _)) = fakeBintrayRepoConnector.uploadedFiles.find(_._2.toString.endsWith(".pom"))
val Some((jarVersion, jarFile, _)) = fakeBintrayRepoConnector.uploadedFiles.find(_._2.toString.endsWith("1.4.0.jar"))

jarFile.getFileName.toString should endWith(".jar")
jarVersion.version shouldBe "1.4.0"

val jarManifest = manifestFromZipFile(jarFile)
jarManifest.value.getValue("Implementation-Version") shouldBe "1.4.0"

val pomVersionText = (XML.loadFile(pomFile.toFile) \ "version").text
pomVersionText shouldBe "1.4.0"
}


"Require only a .pom and a commit manifest in order to release an artifact" in {

val sha = "c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c"
Expand All @@ -185,7 +227,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, "2.11")
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 {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
Expand Down Expand Up @@ -229,7 +271,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, "2.11")
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 {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
Expand Down Expand Up @@ -262,7 +304,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, "2.11")
val coordinator = new Coordinator(tempDir(), metaDataProvider, taggerAndReleaser, fakeRepoConnector)
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 +319,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, "2.11")
val coordinator = new Coordinator(tempDir(), mock[MetaDataProvider], new FakeGithubTagAndRelease, fakeRepoConnector)
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 +332,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, "2.11")
val coordinator = new Coordinator(tempDir(), mock[MetaDataProvider], new FakeGithubTagAndRelease, fakeRepoConnector)
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 +356,7 @@ class CoordinatorSpecs extends WordSpec with Matchers with OptionValues with Try
}
}

val coordinator = new Coordinator(tempDir(), metaDataProvider, new FakeGithubTagAndRelease, fakeRepoConnector, "2.11")
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 {
case Failure(e) =>
log.error(s"Test failed with: ${e.getMessage} - ${e.toString}")
Expand Down
Expand Up @@ -37,7 +37,7 @@ class BintrayIvyPathsSpecs extends WordSpec with Matchers{

val version = VersionDescriptor(repoName, artefactName, githubRepoName, releaseCandidateVersion)

ivyPaths.jarFilenameFor(version) shouldBe "sbt-bobby.jar"
// ivyPaths.jarFilenameFor(version) shouldBe "sbt-bobby.jar"
ivyPaths.fileDownloadFor(version, "uk.gov.hmrc/sbt-bobby/scala_2.10/sbt_0.13/0.8.1-4-ge733d26/jars/sbt-bobby-assembly.jar") shouldBe expectedAssemblyJarUrl
ivyPaths.fileDownloadFor(version, "uk.gov.hmrc/sbt-bobby/scala_2.10/sbt_0.13/0.8.1-4-ge733d26/ivys/ivy.xml") shouldBe expectedPomUrl
}
Expand Down

0 comments on commit 84cc26e

Please sign in to comment.