Skip to content

Commit 036bbab

Browse files
committed
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.
1 parent 23534aa commit 036bbab

File tree

7 files changed

+189
-3
lines changed

7 files changed

+189
-3
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 ETCM-165-publish";
164+
timeoutInMinutes = 30;
165+
};
156166
};
157167
}

.buildkite/publish.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
23+
# https://github.com/olafurpg/sbt-ci-release#secrets
24+
export PGP_SECRET="$GPG_KEY"
25+
export PGP_PASSPHRASE="$GPG_PASSPHRASE"
26+
export SONATYPE_USERNAME="$OSS_USERNAME"
27+
export SONATYPE_PASSWORD="$OSS_PASSWORD"
28+
29+
set +u
30+
31+
#https://github.com/sbt/sbt/issues/3570
32+
export JAVA_OPTS="$JAVA_OPTS -Dsbt.gigahorse=false"
33+
34+
# ci-release cannot be called on individual modules, but it looks like
35+
# with `publish / skip := true` in build.sbt for the default project,
36+
# without any aggregation, by default it would publish nothing, so
37+
# let's tell it here by using `sbt-ci-release` env vars.
38+
export CI_SNAPSHOT_RELEASE="; rlp/publishSigned; crypto/publishSigned"
39+
export CI_RELEASE=$CI_SNAPSHOT_RELEASE
40+
export CI_SONATYPE_RELEASE=$"; rlp/sonatypeBundleRelease; crypto/sonatypeBundleRelease"
41+
42+
if [[ "$BUILDKITE_BRANCH" == "develop" ]]; then
43+
44+
# Publish the -SNAPSHOT version.
45+
sbt ci-release
46+
47+
elif [[ "$BUILDKITE_BRANCH" == "master" ]]; then
48+
49+
# Remove the -SNAPSHOT from the version file, then publish and release.
50+
sed -i 's/-SNAPSHOT//' version.sbt
51+
52+
# Whether ci-release does a release or a snapshot depends on whether it thinks the build is tagged; setting a dummy value.
53+
# Check https://github.com/olafurpg/sbt-ci-release/blob/main/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala for the rules.
54+
export CI_COMMIT_TAG=$(sbt -Dsbt.supershell=false -error "print version")
55+
56+
sbt ci-release
57+
58+
else
59+
60+
echo "Skipping the publish step."
61+
62+
fi

build.sbt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,24 @@ 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+
1530
def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
1631
name := projectName,
1732
organization := "io.iohk",
18-
version := "3.2.1",
1933
scalaVersion := "2.13.4",
2034
// Scalanet snapshots are published to Sonatype after each build.
2135
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
@@ -38,7 +52,9 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
3852
scalacOptions ~= (options => if (mantisDev) options.filterNot(_ == "-Xfatal-warnings") else options),
3953
Test / parallelExecution := true,
4054
testOptions in Test += Tests.Argument("-oDG"),
41-
(scalastyleConfig in Test) := file("scalastyle-test-config.xml")
55+
(scalastyleConfig in Test) := file("scalastyle-test-config.xml"),
56+
// Only publish selected libraries.
57+
skip in publish := true
4258
)
4359

4460
// Adding an "it" config because in `Dependencies.scala` some are declared with `% "it,test"`
@@ -66,6 +82,7 @@ lazy val crypto = {
6682
.dependsOn(bytes)
6783
.settings(commonSettings("mantis-crypto"))
6884
.settings(
85+
publish / skip := false,
6986
libraryDependencies ++=
7087
Dependencies.akkaUtil ++
7188
Dependencies.crypto ++
@@ -82,6 +99,7 @@ lazy val rlp = {
8299
.dependsOn(bytes)
83100
.settings(commonSettings("mantis-rlp"))
84101
.settings(
102+
publish / skip := false,
85103
libraryDependencies ++=
86104
Dependencies.akkaUtil ++
87105
Dependencies.shapeless ++

nix/pkgs/mantis.nix

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{ src
2+
, lib
3+
, stdenv
4+
, makeWrapper
5+
, writeShellScriptBin
6+
, bash
7+
, protobuf
8+
, coreutils
9+
, jdk8
10+
, gawk
11+
, sbt
12+
, impure ? false
13+
}:
14+
15+
let
16+
17+
# sbt-protoc puts the scala plugin in /tmp/protobridge<some-random-number>.
18+
# it is in fact a shell script with a standard `#!/usr/bin/env sh` shebang
19+
# that makes the Nix sandbox ANGRY and breaks all the things in a cryptic,
20+
# hairpull-inducing way. So we gotta sed it out. Not the prettiest thing
21+
# but it works.
22+
#
23+
# This will be unnecessary in sbt-protoc>=1.0.0, as we can specify a file path
24+
# Also, https://github.com/thesamet/sbt-protoc/issues/209 will need to be resolved
25+
# for the plugins to not fail.
26+
protoc-wrapper = writeShellScriptBin "protoc" ''
27+
set -e
28+
29+
for f in "$@"; do
30+
echo ''${f##*=}
31+
done | grep protocbridge | xargs sed -i "1s|.*|#!${bash}/bin/bash|"
32+
33+
exec ${protobuf}/bin/protoc "$@"
34+
'';
35+
nativeBuildInputs = [ protoc-wrapper jdk8 makeWrapper ];
36+
37+
# read version from build.sbt
38+
version = let
39+
buildSbt = builtins.readFile ../../build.sbt;
40+
captures = builtins.match ''.*version := "([^"]+)".*'' buildSbt;
41+
in builtins.elemAt captures 0;
42+
43+
LD_LIBRARY_PATH = lib.makeLibraryPath [ stdenv.cc.cc.lib ];
44+
PATH = lib.makeBinPath [ coreutils jdk8.jre gawk ];
45+
46+
in sbt.mkDerivation {
47+
pname = "mantis";
48+
49+
inherit src nativeBuildInputs version;
50+
51+
# This sha represents the change dependencies of mantis.
52+
# Update this sha whenever you change the dependencies
53+
depsSha256 = "0csj8kiy44hkqdk69349q5bc3wdljyv19kbmy19g3pl2c329np17";
54+
55+
# this is the command used to to create the fixed-output-derivation
56+
depsWarmupCommand = "sbt compile --debug -Dnix=true";
57+
58+
# just inherit build artifacts from fixed-output-derivation
59+
dontBuild = true;
60+
61+
overrideDepsAttrs = oldAttrs: oldAttrs // {
62+
# $out is a directory, thus the archive will fail to write a file
63+
preInstall = ''
64+
rm -rf $out
65+
'';
66+
};
67+
68+
installPhase = ''
69+
sbt stage -Dnix=true
70+
mkdir -p $out/
71+
cp -r target/universal/stage/* $out/
72+
mkdir -p $out/share/mantis
73+
mv $out/{LICENSE,RELEASE,mantis_config.txt} $_
74+
75+
# wrap executable so that java is available at runtime
76+
for p in $(find $out/bin/* -executable); do
77+
wrapProgram "$p" \
78+
--prefix PATH : ${PATH} \
79+
${lib.optionalString (!stdenv.isDarwin)
80+
"--prefix LD_LIBRARY_PATH : ${LD_LIBRARY_PATH}"
81+
}
82+
done
83+
'';
84+
85+
dontPatchShebangs = impure;
86+
87+
# limit warnings from trying to strip jar files
88+
dontStrip = true;
89+
}

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)