Skip to content

Commit be884b1

Browse files
authored
ETCM-[165, 166]: Publish the RLP and Crypto libraries to Sonatype. (#933)
* ETCM-165: Publish the RLP and Crypto libraries to Sonatype. ETCM-165: Accept SNAPSHOT in version number sent in Hello. ETCM-165: Wait for unit tests before publishing. ETCM-165: Check if the GPG key already exists. ETCM-165: Update GPG. ETCM-165: Try restarting the gpg agent. * ETCM-165: Cross publish. * ETCM-165: Update nix. * ETCM-165: Publish bytes as well. * ETCM-165: Remove obsolete nix file. * ETCM-165: Add comment about Nix Flakes * ETCM-165: Fix version regex in mantis.nix * ETCM-165: Update dependency version hash. * ETCM-165: Fix README to talk about the overlay.nix * ETCM-165: Update the dependency sha after fixing the VM submodule version.
1 parent 0a7a3d0 commit be884b1

File tree

11 files changed

+154
-19
lines changed

11 files changed

+154
-19
lines changed

.buildkite/pipeline.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,15 @@ in
153153
nix-shell --run '$SBT benchmark:compile dist'
154154
'';
155155
};
156+
157+
publish = commonAttrs // {
158+
dependsOn = [ test-crypto test-rlp test-unit ];
159+
label = "Publishing libraries to Maven";
160+
command = ''
161+
nix-env -iA nixpkgs.gnupg && nix-shell --run '.buildkite/publish.sh'
162+
'';
163+
branches = "master develop";
164+
timeoutInMinutes = 30;
165+
};
156166
};
157167
}

.buildkite/publish.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
3+
set -euv
4+
5+
# The build agents have gpg 2.0.22, which doesn't have the `--pinentry-mode` option, but
6+
# the sbt-pgp plugin assumes that 2.x has it, and generates an invalid command.
7+
# We can either create a wrapper script that removes that option, or update gpg
8+
# somewhere in pipeline.nix
9+
10+
# Force a restart of the agent becuase it may be out of sync with what Nix installed.
11+
gpgconf --kill all
12+
13+
gpg --version
14+
15+
16+
# The build agent might have this key from before.
17+
GPG_EXISTS=$(gpg --list-keys "$GPG_KEY_ID" >&2 && echo "yes" || echo "no")
18+
19+
if [[ "$GPG_EXISTS" == "no" ]]; then
20+
echo "$GPG_KEY" | base64 --decode | gpg --batch --import
21+
fi
22+
# Local testing showed that without this the SBT plugin got "Bad passphrase".
23+
gpg --passphrase $GPG_PASSPHRASE --batch --yes -a -b LICENSE
24+
25+
# https://github.com/olafurpg/sbt-ci-release#secrets
26+
export PGP_SECRET="$GPG_KEY"
27+
export PGP_PASSPHRASE="$GPG_PASSPHRASE"
28+
export SONATYPE_USERNAME="$OSS_USERNAME"
29+
export SONATYPE_PASSWORD="$OSS_PASSWORD"
30+
31+
set +u
32+
33+
#https://github.com/sbt/sbt/issues/3570
34+
export JAVA_OPTS="$JAVA_OPTS -Dsbt.gigahorse=false"
35+
36+
# ci-release cannot be called on individual modules, but it looks like
37+
# with `publish / skip := true` in build.sbt for the default project,
38+
# without any aggregation, by default it would publish nothing, so
39+
# let's tell it here by using `sbt-ci-release` env vars.
40+
# NOTE: +rlp/publishSigned with the `+` would cross publish,
41+
# but it doesn't work because of scapegoat (see below).
42+
export CI_SNAPSHOT_RELEASE="; bytes/publishSigned; rlp/publishSigned; crypto/publishSigned"
43+
export CI_RELEASE=$CI_SNAPSHOT_RELEASE
44+
export CI_SONATYPE_RELEASE=$"; bytes/sonatypeBundleRelease; rlp/sonatypeBundleRelease; crypto/sonatypeBundleRelease"
45+
46+
# Scala 2.12 has up to scapegoat 1.4.5, while Scala 2.13 starts with 1.4.7.
47+
# I couldn't make build.sbt vary the scapegoat version by the current cross build,
48+
# so as a workaround the combos are called here explicitly.
49+
function release {
50+
SCALA_VERSION=$1
51+
export SCAPEGOAT_VERSION=$2
52+
53+
sbt "++ $SCALA_VERSION ; ci-release"
54+
}
55+
56+
function releaseAll {
57+
release 2.12.10 1.4.5
58+
release 2.13.4 1.4.7
59+
}
60+
61+
if [[ "$BUILDKITE_BRANCH" == "develop" ]]; then
62+
63+
# Publish the -SNAPSHOT version.
64+
releaseAll
65+
66+
elif [[ "$BUILDKITE_BRANCH" == "master" ]]; then
67+
68+
# Remove the -SNAPSHOT from the version file, then publish and release.
69+
sed -i 's/-SNAPSHOT//' version.sbt
70+
71+
# Whether ci-release does a release or a snapshot depends on whether it thinks the build is tagged; setting a dummy value.
72+
# Check https://github.com/olafurpg/sbt-ci-release/blob/main/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala for the rules.
73+
export CI_COMMIT_TAG=$(sbt -Dsbt.supershell=false -error "print version")
74+
75+
releaseAll
76+
77+
else
78+
79+
echo "Skipping the publish step."
80+
81+
fi

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Possible networks: `etc`, `eth`, `mordor`, `testnet-internal`
3232
### Command Line Interface
3333

3434
`cli` is a tool that can be used to:
35-
35+
3636
- generate a new private key
3737
```
3838
./bin/mantis cli generate-private-key
@@ -124,10 +124,12 @@ will need to be updated so that it includes the new dependency state.
124124
To do so, please run:
125125
```
126126
./update-nix.sh
127-
git add ./nix/pkgs/mantis.nix
127+
git add ./nix/overlay.nix
128128
git commit -m "Update nix-sbt sha"
129129
```
130130

131+
For this command to work you'll need the [Flakes](https://nixos.wiki/wiki/Flakes) feature enabled in your `nix` environment.
132+
131133
*NOTE:* This should only be necessary when updating dependencies
132134
(For example, edits to build.sbt or project/plugins.sbt will likely need to be regenerated)
133135

@@ -159,9 +161,9 @@ If a new certificate is required, create a new keystore with a certificate by ru
159161
1. Configure the certificate and password file to be used at `mantis.network.rpc.http.certificate` key on the `application.conf` file:
160162

161163
keystore-path: path to the keystore storing the certificates (if generated through our script they are by default located in "./tls/mantisCA.p12")
162-
164+
163165
keystore-type: type of certificate keystore being used (if generated through our script use "pkcs12")
164-
166+
165167
password-file: path to the file with the password used for accessing the certificate keystore (if generated through our script they are by default located in "./tls/password")
166168
2. Enable TLS in specific config:
167169
- For JSON RPC: `mantis.network.rpc.http.mode=https`
@@ -171,9 +173,9 @@ If a new certificate is required, create a new keystore with a certificate by ru
171173
1. Configure the certificate and password file to be used at `mantis.network.rpc.http.certificate` key on the `faucet.conf` file:
172174

173175
keystore-path: path to the keystore storing the certificates (if generated through our script they are by default located in "./tls/mantisCA.p12")
174-
176+
175177
keystore-type: type of certificate keystore being used (if generated through our script use "pkcs12")
176-
178+
177179
password-file: path to the file with the password used for accessing the certificate keystore (if generated through our script they are by default located in "./tls/password")
178180
2. Enable TLS in specific config:
179181
- For JSON RPC: `mantis.network.rpc.http.mode=https`
@@ -200,7 +202,7 @@ volumes:
200202
- $HOME/.mantis:/home/demiourgos728/.mantis/
201203
command: -Dconfig.file=./conf/sagano.conf
202204
```
203-
205+
204206
2. Create a wallet address. Run the following curl command, replacing `<password>` by a password of your choice:
205207
```
206208
curl --request POST \
@@ -209,7 +211,7 @@ curl --request POST \
209211
--header 'Content-Type: application/json' \
210212
--data '{
211213
"jsonrpc": "2.0",
212-
"method": "personal_newAccount",
214+
"method": "personal_newAccount",
213215
"params": ["<password>"],
214216
"id": 1
215217
}'
@@ -244,7 +246,7 @@ curl --request POST \
244246
--header 'Content-Type: application/json' \
245247
--data '{
246248
"jsonrpc": "2.0",
247-
"method": "faucet_sendFunds",
249+
"method": "faucet_sendFunds",
248250
"params": ["<address>"],
249251
"id": 1
250252
}'

build.sbt

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,29 @@ val nixBuild = sys.props.isDefinedAt("nix")
1212
// Enable dev mode: disable certain flags, etc.
1313
val mantisDev = sys.props.get("mantisDev").contains("true") || sys.env.get("MANTIS_DEV").contains("true")
1414

15+
// Releasing. https://github.com/olafurpg/sbt-ci-release
16+
inThisBuild(List(
17+
organization := "io.iohk",
18+
homepage := Some(url("https://github.com/input-output-hk/mantis")),
19+
scmInfo := Some(ScmInfo(url("https://github.com/input-output-hk/mantis"), "[email protected]:input-output-hk/mantis.git")),
20+
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
21+
developers := List()
22+
))
23+
24+
// https://github.com/sbt/sbt/issues/3570
25+
updateOptions := updateOptions.value.withGigahorse(false)
26+
27+
// artifact name will include scala version
28+
crossPaths := true
29+
30+
val `scala-2.12` = "2.12.10"
31+
val `scala-2.13` = "2.13.4"
32+
val supportedScalaVersions = List(`scala-2.12`, `scala-2.13`)
33+
1534
def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
1635
name := projectName,
1736
organization := "io.iohk",
18-
version := "3.2.1",
19-
scalaVersion := "2.13.4",
37+
scalaVersion := `scala-2.13`,
2038
// Scalanet snapshots are published to Sonatype after each build.
2139
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
2240
testOptions in Test += Tests
@@ -38,7 +56,14 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
3856
scalacOptions ~= (options => if (mantisDev) options.filterNot(_ == "-Xfatal-warnings") else options),
3957
Test / parallelExecution := true,
4058
testOptions in Test += Tests.Argument("-oDG"),
41-
(scalastyleConfig in Test) := file("scalastyle-test-config.xml")
59+
(scalastyleConfig in Test) := file("scalastyle-test-config.xml"),
60+
// Only publish selected libraries.
61+
skip in publish := true
62+
)
63+
64+
val publishSettings = Seq(
65+
publish / skip := false,
66+
crossScalaVersions := supportedScalaVersions
4267
)
4368

4469
// Adding an "it" config because in `Dependencies.scala` some are declared with `% "it,test"`
@@ -50,6 +75,7 @@ lazy val bytes = {
5075
.in(file("bytes"))
5176
.configs(Integration)
5277
.settings(commonSettings("mantis-bytes"))
78+
.settings(publishSettings)
5379
.settings(
5480
libraryDependencies ++=
5581
Dependencies.akkaUtil ++
@@ -65,6 +91,7 @@ lazy val crypto = {
6591
.configs(Integration)
6692
.dependsOn(bytes)
6793
.settings(commonSettings("mantis-crypto"))
94+
.settings(publishSettings)
6895
.settings(
6996
libraryDependencies ++=
7097
Dependencies.akkaUtil ++
@@ -81,6 +108,7 @@ lazy val rlp = {
81108
.configs(Integration)
82109
.dependsOn(bytes)
83110
.settings(commonSettings("mantis-rlp"))
111+
.settings(publishSettings)
84112
.settings(
85113
libraryDependencies ++=
86114
Dependencies.akkaUtil ++
@@ -201,6 +229,9 @@ lazy val node = {
201229
batScriptExtraDefines += """call :add_java "-Dconfig.file=%APP_HOME%\conf\app.conf"""",
202230
batScriptExtraDefines += """call :add_java "-Dlogback.configurationFile=%APP_HOME%\conf\logback.xml""""
203231
)
232+
.settings(
233+
crossScalaVersions := List(`scala-2.13`)
234+
)
204235

205236
if (!nixBuild)
206237
node
@@ -252,5 +283,7 @@ addCommandAlias(
252283
|""".stripMargin
253284
)
254285

255-
scapegoatVersion in ThisBuild := "1.4.7"
286+
// Scala 2.12 only has up to 1.4.5, while 2.13 only from 1.4.7
287+
// In theory we should be able to switch on `scalaVersion.value` but it doesn't seem to work.
288+
scapegoatVersion in ThisBuild := (sys.env.getOrElse("SCAPEGOAT_VERSION", "1.4.7"))
256289
scapegoatReports := Seq("xml")

bytes/src/main/scala/io/iohk/ethereum/utils/ByteStringUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ object ByteStringUtils {
6161

6262
def concatByteStrings(elements: Iterator[ByteStringElement]): ByteString = {
6363
val builder = new mutable.ArrayBuilder.ofByte
64-
elements.foreach(el => builder.addAll(el.asByteArray))
64+
elements.foreach(el => builder ++= el.asByteArray)
6565
ByteString(builder.result())
6666
}
6767

bytes/src/main/scala/io/iohk/ethereum/utils/Hex.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ object Hex {
55
bytes.map("%02x".format(_)).mkString
66

77
def decode(hex: String): Array[Byte] =
8-
hex.toSeq.sliding(2, 2).toArray.map(s => Integer.parseInt(s.unwrap, 16).toByte)
8+
hex.toSeq.sliding(2, 2).toArray.map { s =>
9+
Integer.parseInt(s.mkString(""), 16).toByte
10+
}
911
}

nix/mantis.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
let
2121
version = let
22-
buildSbt = builtins.readFile ../build.sbt;
23-
captures = builtins.match ''.*version := "([^"]+)".*'' buildSbt;
22+
versionSbt = builtins.readFile ../version.sbt;
23+
captures = builtins.match ''.*version in ThisBuild := "([^"]+)".*'' versionSbt;
2424
in builtins.elemAt captures 0;
2525

2626
PATH = lib.makeBinPath [ jre solc coreutils gawk gnused ];

nix/overlay.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ rev: final: prev: {
33

44
mantis = final.callPackage ./mantis.nix {
55
src = ../.;
6-
depsSha256 = "sha256-csNBHVOC2bNSOjLjWleiVeS5ts3qFS7V8DxBv2nVDqE=";
6+
depsSha256 = "sha256-FpBrDvN0iR/eEpUunUIRRo6I9pWqpMyPRybEClCqTFs=";
77
};
88

99
mantis-hash = final.mantis.override {

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ addSbtPlugin("io.kamon" % "sbt-kanela-runner" % "2.0.5")
1111
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
1212
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
1313
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
14+
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.6")

src/test/scala/io/iohk/ethereum/utils/VersionInfoSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class VersionInfoSpec extends AnyFlatSpec with Matchers {
88

99
it should "match ethstats expected structure and preserve major and minor Java version" in {
1010
VersionInfo
11-
.nodeName() should fullyMatch regex """mantis/v\d(\.\d+)*-[a-z0-9]{7}/[^/]+-[^/]+/[^/]+-.[^/]+-java-\d+\.\d+[._0-9]*"""
11+
.nodeName() should fullyMatch regex """mantis/v\d(\.\d+)*(-SNAPSHOT)?-[a-z0-9]{7}/[^/]+-[^/]+/[^/]+-.[^/]+-java-\d+\.\d+[._0-9]*"""
1212
}
1313

1414
it should "augment the name with an identity" in {

version.sbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// NOTE: This is replaced with `sed` during release,
2+
// but it could also be removed, and be determined
3+
// based on `git` tags by https://github.com/dwijnand/sbt-dynver,
4+
// which is a dependency of `sbt-ci-release`.
5+
6+
version in ThisBuild := "3.2.1-SNAPSHOT"

0 commit comments

Comments
 (0)