Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix publishing with implicit publish.version coming from a git tag #2154

Merged
merged 2 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,16 @@
}
]
},
{
"name": "org.eclipse.jgit.lib.CoreConfig$LogRefUpdates",
"methods": [
{
"name": "values",
"parameterTypes": [
]
}
]
},
{
"name": "org.eclipse.jgit.lib.CoreConfig$TrustPackedRefsStat",
"methods": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect

abstract class PublishLocalTestDefinitions(val scalaVersionOpt: Option[String])
extends ScalaCliSuite with TestScalaVersionArgs {
protected def extraOptions: Seq[String] =
scalaVersionArgs ++ TestUtil.extraOptions ++ Seq("--suppress-experimental-feature-warning")

def testedPublishedScalaVersion: String =
if (actualScalaVersion.startsWith("3"))
actualScalaVersion.split('.').take(1).mkString
else actualScalaVersion.split('.').take(2).mkString(".")

def testPublishVersion: String = "1.5.6"

private object PublishTestInputs {
def testOrg: String = "test-local-org.sth"
def testName: String = "my-proj"
def projFile(message: String): String =
s"""//> using scala "$testedPublishedScalaVersion"
|//> using dep "com.lihaoyi::os-lib:0.9.1"
|
|object Project {
| def message = "$message"
|
| def main(args: Array[String]): Unit =
| println(message)
|}
|""".stripMargin

private def publishConfFile(includePublishVersion: Boolean): String = {
val publishVersionDirective =
if (includePublishVersion) s"//> using publish.version $testPublishVersion"
else ""
s"""//> using publish.organization $testOrg
|//> using publish.name $testName
|$publishVersionDirective
|""".stripMargin
}

def inputs(message: String = "Hello", includePublishVersion: Boolean = true): TestInputs =
TestInputs(
os.rel / "project.scala" -> projFile(message),
os.rel / "publish-conf.scala" -> publishConfFile(includePublishVersion)
)
}

for (includePublishVersion <- Seq(true, false)) {
val withPublishVersionString =
if (includePublishVersion) " with publish.version"
else " without explicit publish.version, reading it from git:tag"
test(s"publish local$withPublishVersionString") {
val expectedFiles = {
val modName = s"${PublishTestInputs.testName}_$testedPublishedScalaVersion"
val base = os.rel / PublishTestInputs.testOrg / modName / testPublishVersion
val baseFiles = Seq(
base / "jars" / s"$modName.jar",
base / "docs" / s"$modName-javadoc.jar",
base / "srcs" / s"$modName-sources.jar",
base / "poms" / s"$modName.pom",
base / "ivys" / "ivy.xml"
)
baseFiles
.flatMap { f =>
val md5 = f / os.up / s"${f.last}.md5"
val sha1 = f / os.up / s"${f.last}.sha1"
Seq(f, md5, sha1)
}
.toSet
}

PublishTestInputs.inputs(includePublishVersion = includePublishVersion)
.fromRoot { root =>
val ciOptions =
if (!includePublishVersion) {
TestUtil.initializeGit(cwd = root, tag = testPublishVersion)
Seq("--ci=false") // when running on CI, version wouldn't be read from a git tag
}
else Seq.empty
os.proc(
TestUtil.cli,
"--power",
"publish",
"local",
".",
"--ivy2-home",
os.rel / "ivy2",
extraOptions,
ciOptions
)
.call(cwd = root)
val ivy2Local = root / "ivy2" / "local"
val foundFiles = os.walk(ivy2Local)
.filter(os.isFile(_))
.map(_.relativeTo(ivy2Local))
.toSet
val missingFiles = expectedFiles -- foundFiles
val unexpectedFiles = foundFiles -- expectedFiles
if (missingFiles.nonEmpty)
pprint.err.log(missingFiles)
if (unexpectedFiles.nonEmpty)
pprint.err.log(unexpectedFiles)
expect(missingFiles.isEmpty)
expect(unexpectedFiles.isEmpty)
}
}
}

test("publish local twice") {
PublishTestInputs.inputs().fromRoot { root =>
def publishLocal(): os.CommandResult =
os.proc(
TestUtil.cli,
"--power",
"publish",
"local",
".",
"--ivy2-home",
os.rel / "ivy2",
"--working-dir",
os.rel / "work-dir",
extraOptions
)
.call(cwd = root)

def output(): String =
os.proc(
TestUtil.cs,
s"-J-Divy.home=${root / "ivy2"}",
"launch",
s"${PublishTestInputs.testOrg}:${PublishTestInputs.testName}_$testedPublishedScalaVersion:$testPublishVersion"
)
.call(cwd = root)
.out.trim()

publishLocal()
val output1 = output()
expect(output1 == "Hello")

os.write.over(root / "project.scala", PublishTestInputs.projFile("olleH"))
publishLocal()
val output2 = output()
expect(output2 == "olleH")
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package scala.cli.integration

class PublishLocalTests212
extends PublishLocalTestDefinitions(scalaVersionOpt = Some(Constants.scala212))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package scala.cli.integration

class PublishLocalTests213
extends PublishLocalTestDefinitions(scalaVersionOpt = Some(Constants.scala213))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package scala.cli.integration

class PublishLocalTestsDefault extends PublishLocalTestDefinitions(scalaVersionOpt = None)
Original file line number Diff line number Diff line change
Expand Up @@ -3,115 +3,6 @@ package scala.cli.integration
import com.eed3si9n.expecty.Expecty.expect

class PublishTestsDefault extends PublishTestDefinitions(scalaVersionOpt = None) {

private object PublishTestInputs {
def testOrg = "test-local-org.sth"
def testName = "my-proj"
def testVersion = "1.5.6"
def sbv = "2.13"
def projFile(message: String): String =
s"""//> using publish.organization "$testOrg"
|//> using publish.name "$testName"
|//> using publish.version "$testVersion"
|
|//> using scala "$sbv"
|//> using dep "com.lihaoyi::os-lib:0.8.1"
|
|object Project {
| def message = "$message"
|
| def main(args: Array[String]): Unit =
| println(message)
|}
|""".stripMargin
val inputs = TestInputs(
os.rel / "Project.scala" -> projFile("Hello")
)
}

test("publish local") {
val expectedFiles = {
val modName = s"${PublishTestInputs.testName}_2.13"
val base = os.rel / PublishTestInputs.testOrg / modName / PublishTestInputs.testVersion
val baseFiles = Seq(
base / "jars" / s"$modName.jar",
base / "docs" / s"$modName-javadoc.jar",
base / "srcs" / s"$modName-sources.jar",
base / "poms" / s"$modName.pom",
base / "ivys" / "ivy.xml"
)
baseFiles
.flatMap { f =>
val md5 = f / os.up / s"${f.last}.md5"
val sha1 = f / os.up / s"${f.last}.sha1"
Seq(f, md5, sha1)
}
.toSet
}

PublishTestInputs.inputs.fromRoot { root =>
os.proc(
TestUtil.cli,
"--power",
"publish",
"local",
"Project.scala",
"--ivy2-home",
os.rel / "ivy2"
)
.call(cwd = root)
val ivy2Local = root / "ivy2" / "local"
val foundFiles = os.walk(ivy2Local)
.filter(os.isFile(_))
.map(_.relativeTo(ivy2Local))
.toSet
val missingFiles = expectedFiles -- foundFiles
val unexpectedFiles = foundFiles -- expectedFiles
if (missingFiles.nonEmpty)
pprint.err.log(missingFiles)
if (unexpectedFiles.nonEmpty)
pprint.err.log(unexpectedFiles)
expect(missingFiles.isEmpty)
expect(unexpectedFiles.isEmpty)
}
}

test("publish local twice") {
PublishTestInputs.inputs.fromRoot { root =>
def publishLocal(): os.CommandResult =
os.proc(
TestUtil.cli,
"--power",
"publish",
"local",
"Project.scala",
"--ivy2-home",
os.rel / "ivy2",
"--working-dir",
os.rel / "work-dir"
)
.call(cwd = root)
def output(): String =
os.proc(
TestUtil.cs,
s"-J-Divy.home=${root / "ivy2"}",
"launch",
s"${PublishTestInputs.testOrg}:${PublishTestInputs.testName}_${PublishTestInputs.sbv}:${PublishTestInputs.testVersion}"
)
.call(cwd = root)
.out.trim()

publishLocal()
val output1 = output()
expect(output1 == "Hello")

os.write.over(root / "Project.scala", PublishTestInputs.projFile("olleH"))
publishLocal()
val output2 = output()
expect(output2 == "olleH")
}
}

test("Pure Java") {
val testOrg = "test-org.foo"
val testName = "foo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,25 @@ object TestUtil {
textAcc.replace(colorStr, "")
}
}

def initializeGit(
cwd: os.Path,
tag: String = "test-inputs",
gitUserName: String = "testUser",
gitUserEmail: String = "testUser@scala-cli-tests.com"
): Unit = {
println(s"Initializing git in $cwd...")
os.proc("git", "init").call(cwd = cwd)
println(s"Setting git user.name to $gitUserName")
os.proc("git", "config", "--local", "user.name", gitUserName).call(cwd = cwd)
println(s"Setting git user.email to $gitUserEmail")
os.proc("git", "config", "--local", "user.email", gitUserEmail).call(cwd = cwd)
println(s"Adding $cwd to git...")
os.proc("git", "add", ".").call(cwd = cwd)
println(s"Doing an initial commit...")
os.proc("git", "commit", "-m", "git init test inputs").call(cwd = cwd)
println(s"Tagging as $tag...")
os.proc("git", "tag", tag).call(cwd = cwd)
println(s"Git initialized at $cwd")
}
}