Skip to content

Rework publishing and simplify build #3577

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

Merged
merged 1 commit into from
Nov 28, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ pipeline:
- NIGHTLYBUILD=yes
commands:
- ./project/scripts/sbtPublish ";dotty-bootstrapped/publishSigned ;sonatypeRelease"
volumes:
- /home/drone/keys:/keys
secrets: [ sonatype_user, sonatype_pw, pgp_pw ]
secrets: [ sonatype_user, sonatype_pw, pgp_pw, pgp_secret ]
when:
event: deployment
environment: nightly
Expand All @@ -87,9 +85,7 @@ pipeline:
# Produces dotty-version.{tar.gz, zip}
- ./project/scripts/sbt dist-bootstrapped/packArchive
- ./project/scripts/sbtPublish ";dotty-bootstrapped/publishSigned ;sonatypeRelease"
volumes:
- /home/drone/keys:/keys
secrets: [ sonatype_user, sonatype_pw, pgp_pw ]
secrets: [ sonatype_user, sonatype_pw, pgp_pw, pgp_secret ]
when:
event: tag

Expand All @@ -111,9 +107,7 @@ pipeline:
- RELEASEBUILD=yes
commands:
- ./project/scripts/sbtPublish ";sbt-dotty/publishSigned ;sonatypeRelease"
volumes:
- /home/drone/keys:/keys
secrets: [ sonatype_user, sonatype_pw, pgp_pw ]
secrets: [ sonatype_user, sonatype_pw, pgp_pw, pgp_secret ]
when:
event: deployment
environment: sbt_release
Expand Down
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ val `sbt-dotty` = Build.`sbt-dotty`
val `vscode-dotty` = Build.`vscode-dotty`

inThisBuild(Build.thisBuildSettings)
inScope(Global)(Build.globalSettings)
97 changes: 60 additions & 37 deletions project/Build.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sbt.Keys._
import sbt._
import complete.DefaultParsers._
import java.io.{File, RandomAccessFile}
import java.io.File
import java.nio.channels.FileLock
import java.nio.file.{ Files, FileSystemException }
import java.nio.file._
import java.util.Calendar

import scala.reflect.io.Path
Expand All @@ -20,6 +20,8 @@ import dotty.tools.sbtplugin.DottyIDEPlugin.autoImport._
import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._

import com.typesafe.sbt.pgp.PgpKeys

import pl.project13.scala.sbt.JmhPlugin
import JmhPlugin.JmhKeys.Jmh

Expand Down Expand Up @@ -96,27 +98,14 @@ object Build {

lazy val bootstrapFromPublishedJars = settingKey[Boolean]("If true, bootstrap dotty from published non-bootstrapped dotty")

// Used in build.sbt
lazy val thisBuildSettings = Def.settings(
// Change this to true if you want to bootstrap using a published non-bootstrapped compiler
bootstrapFromPublishedJars := false,

// Override `runCode` from sbt-dotty to use the language-server and
// vscode extension from the source repository of dotty instead of a
// published version.
runCode := (run in `dotty-language-server`).toTask("").value
)

// Only available in vscode-dotty
lazy val unpublish = taskKey[Unit]("Unpublish a package")



lazy val commonSettings = publishSettings ++ Seq(
// Settings shared by the build (scoped in ThisBuild). Used in build.sbt
lazy val thisBuildSettings = Def.settings(
organization := dottyOrganization,
organizationName := "LAMP/EPFL",
organizationHomepage := Some(url("http://lamp.epfl.ch")),
homepage := Some(url(dottyGithubUrl)),

scalacOptions ++= Seq(
"-feature",
Expand All @@ -129,6 +118,60 @@ object Build {

javacOptions ++= Seq("-Xlint:unchecked", "-Xlint:deprecation"),

// Change this to true if you want to bootstrap using a published non-bootstrapped compiler
bootstrapFromPublishedJars := false,

// Override `runCode` from sbt-dotty to use the language-server and
// vscode extension from the source repository of dotty instead of a
// published version.
runCode := (run in `dotty-language-server`).toTask("").value
)

// Settings shared globally (scoped in Global). Used in build.sbt
lazy val globalSettings = Def.settings(
// Override `runCode` from sbt-dotty to use the language-server and
// vscode extension from the source repository of dotty instead of a
// published version.
runCode := (run in `dotty-language-server`).toTask("").value,

onLoad := (onLoad in Global).value andThen { state =>
def exists(submodule: String) = {
val path = Paths.get(submodule)
Files.exists(path) && {
val fileStream = Files.list(path)
val nonEmpty = fileStream.iterator().hasNext()
fileStream.close()
nonEmpty
}
}

// Make sure all submodules are properly cloned
val submodules = List("scala-backend", "scala2-library", "collection-strawman")
if (!submodules.forall(exists)) {
sLog.value.log(Level.Error,
s"""Missing some of the submodules
|You can initialize the modules with:
| > git submodule update --init
""".stripMargin)
}

// Copy default configuration from .vscode-template/ unless configuration files already exist in .vscode/
sbt.IO.copyDirectory(new File(".vscode-template/"), new File(".vscode/"), overwrite = false)

state
},

// Credentials to release to Sonatype
credentials ++= (
for {
username <- sys.env.get("SONATYPE_USER")
password <- sys.env.get("SONATYPE_PW")
} yield Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", username, password)
).toList,
PgpKeys.pgpPassphrase := sys.env.get("PGP_PW").map(_.toCharArray())
)

lazy val commonSettings = publishSettings ++ Seq(
scalaSource in Compile := baseDirectory.value / "src",
scalaSource in Test := baseDirectory.value / "test",
javaSource in Compile := baseDirectory.value / "src",
Expand Down Expand Up @@ -881,7 +924,6 @@ object Build {
settings(commonSettings).
settings(
EclipseKeys.skipProject := true,

version := "0.1.2", // Keep in sync with package.json

autoScalaLibrary := false,
Expand Down Expand Up @@ -1097,22 +1139,6 @@ object Build {
))
}

lazy val dottyProjectFolderChecks = onLoad in Global := (onLoad in Global).value andThen { state =>
val submodules = List(new File("scala-backend"), new File("scala2-library"), new File("collection-strawman"))
if (!submodules.forall(f => f.exists && f.listFiles().nonEmpty)) {
sLog.value.log(Level.Error,
s"""Missing some of the submodules
|You can initialize the modules with:
| > git submodule update --init
""".stripMargin)
}

// Copy default configuration from .vscode-template/ unless configuration files already exist in .vscode/
sbt.IO.copyDirectory(new File(".vscode-template/"), new File(".vscode/"), overwrite = false)

state
}

lazy val commonDistSettings = packSettings ++ Seq(
packMain := Map(),
publishArtifact := false,
Expand All @@ -1134,9 +1160,6 @@ object Build {
dependsOn(dottyCompiler).
dependsOn(dottyLibrary).
nonBootstrappedSettings(
triggeredMessage in ThisBuild := Watched.clearWhenTriggered,
dottyProjectFolderChecks,

addCommandAlias("run", "dotty-compiler/run") ++
addCommandAlias("legacyTests", "dotty-compiler/testOnly dotc.tests")
)
Expand Down
8 changes: 2 additions & 6 deletions project/scripts/sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/usr/bin/env bash
set -e

# Usage:
# ./sbt <cmd>

CMD="$1"

if [ -z "$CMD" ]; then
echo "Error: missing sbt command"
exit 1
fi
CMD="${1:?Missing sbt command}"

# run sbt with the supplied arg
sbt -J-Xmx4096m \
Expand Down
31 changes: 12 additions & 19 deletions project/scripts/sbtPublish
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
#!/usr/bin/env bash
set -e

# Usage:
# SONATYPE_USER=<sonatype user> SONATYPE_PW=<sonatype pw> PGP_PW=<pgp pw> ./sbtPublish <publish cmd>

set -e
# SONATYPE_USER=<sonatype user> SONATYPE_PW=<sonatype pw> PGP_PW=<pgp pw> PGP_SECRET=<pgp secret> ./sbtPublish <publish cmd>

# Release command:
RELEASE_CMD="$1"
RELEASE_CMD="${1:?Missing publish command}"

if [ -z "$SONATYPE_USER" ] || [ -z "$SONATYPE_PW" ] || [ -z "$PGP_PW" ]; then
echo "Error: SONATYPE_USER, SONATYPE_PW or PGP_PW env unset"
exit 1
fi
# Make sure required environment variable are set
: "${SONATYPE_USER:?not set}"
: "${SONATYPE_PW:?not set}"
: "${PGP_PW:?not set}"
: "${PGP_SECRET:?is not set}"

if [ ! "$NIGHTLYBUILD" = "yes" ] && [ ! "$RELEASEBUILD" = "yes" ]; then
echo "Neither NIGHTLYBUILD nor RELEASEBUILD env var set to \"yes\""
exit 1
fi

if [ -z "$RELEASE_CMD" ]; then
echo "Error: missing publish command"
exit 1
fi

CMD=" ;set credentials in ThisBuild := Seq(Credentials(\"Sonatype Nexus Repository Manager\", \"oss.sonatype.org\", \"$SONATYPE_USER\", \"$SONATYPE_PW\"))"
CMD="$CMD ;set pgpPassphrase := Some(\"\"\"$PGP_PW\"\"\".toCharArray)"
CMD="$CMD ;set pgpSecretRing := file(\"/keys/secring.asc\")"
CMD="$CMD ;set pgpPublicRing := file(\"/keys/pubring.asc\")"
CMD="$CMD $RELEASE_CMD"
# Write down PGP secret key to the location expected by sbt-pgp
mkdir -p "$HOME/.sbt/gpg"
echo "$PGP_SECRET" > "$HOME/.sbt/gpg/secring.asc"

# run sbt with the supplied arg
SBT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/sbt"
"$SBT" "$CMD"
"$SBT" "$RELEASE_CMD"