Skip to content

Commit 43e7eb8

Browse files
committed
Add travis pipeline publishing to maven central via oss.sonatype.org
* Add docker container with all build and gpg sign prerequisites * Update pom.xml with metadata (groupId, artifactId, name, description, licenses, developers, scm, issueManagement sections) * Add sonatype repository information * Add build-extras profile generating sources.jar and javadoc.jar * Add sign profile signing bundle components with [email protected] gpg maven subkey * Any tag signed by a release engineer in format $SEMVER-SNAPSHOT will be deployed to https://oss.sonatype.org/content/repositories/snapshots * Any tag signed by a release engineer in format $SEMVER will be deployed to https://oss.sonatype.org/service/local/staging/deploy/maven2 and pushed to https://repo1.maven.org/maven2/io/horizen/zendoo-sc-cryptolib * Git tag and pom.xml project.version have to match for deployment to work
1 parent ab4bcf7 commit 43e7eb8

13 files changed

+358
-179
lines changed

.travis.settings.xml

-11
This file was deleted.

.travis.yml

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
os: linux
2-
dist: xenial
3-
language: java
2+
dist: bionic
3+
language: generic
44
addons:
55
apt:
66
packages:
7-
- ant
87
- libxml-xpath-perl
98
services:
109
- docker
1110

11+
env:
12+
global:
13+
- CONTAINER_JAVA_VER="openjdk-8-jdk=8u252-b09-1~16.04"
14+
- CONTAINER_RUST_VER="1.41.0"
15+
1216
script: >-
13-
source ci/check_tag.sh &&
14-
docker build -t zencash/zendoo-sc-cryptolib-builder ./ci &&
15-
docker run --rm -v "$(pwd):/build" -e LOCAL_USER_ID="$(id -u)" -e LOCAL_GRP_ID="$(id -g)" -e PUBLISH -e PACKAGECLOUD_TOKEN zencash/zendoo-sc-cryptolib-builder /build/ci/start_ci.sh
17+
source ci/setup_env.sh &&
18+
docker build --pull --no-cache -t zencash/zendoo-sc-cryptolib-builder ./ci &&
19+
bash -c "docker run --rm -v $(pwd):/build -v ${HOME}/key.asc:/key.asc --tmpfs /tmp:uid=$(id -u),gid=$(id -g),exec,mode=1777 \
20+
--tmpfs /run:uid=$(id -u),gid=$(id -g),exec,mode=1777 -e LOCAL_USER_ID=$(id -u) -e LOCAL_GRP_ID=$(id -g) \
21+
$(env | grep -E '^CONTAINER_' | sed -n '/^[^\t]/s/=.*//p' | sed '/^$/d' | sed 's/^/-e /g' | tr '\n' ' ') \
22+
zencash/zendoo-sc-cryptolib-builder /build/ci/start_ci.sh"

ci/.dockerignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
*
2-
!entrypoint.sh
2+
!entrypoint*

ci/Dockerfile

+44-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,53 @@ FROM ubuntu:16.04
22

33
44

5-
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
5+
SHELL ["/bin/bash", "-c"]
6+
7+
COPY entrypoint.sh entrypoint_setup_gpg.sh /usr/local/bin/
68

79
# Get Ubuntu packages
8-
RUN export DEBIAN_FRONTEND=noninteractive \
10+
RUN set -eux && export GOSU_VERSION=1.12 && export DEBIAN_FRONTEND=noninteractive \
911
&& apt-get update \
10-
&& apt-get install -y --no-install-recommends build-essential curl \
11-
gcc-mingw-w64-x86-64 gosu maven openjdk-8-jdk=8u252-b09-1~16.04 \
12-
&& chmod +x /usr/local/bin/entrypoint.sh \
12+
&& apt-get install -y --no-install-recommends build-essential ca-certificates curl dirmngr \
13+
gcc-mingw-w64-x86-64 gnupg2 gnupg-curl wget; \
14+
# save list of currently installed packages for later so we can clean up
15+
savedAptMark="$(apt-mark showmanual)"; \
16+
apt-get update; \
17+
apt-get install -y --no-install-recommends ca-certificates wget; \
18+
if ! command -v gpg; then \
19+
apt-get install -y --no-install-recommends gnupg2 dirmngr; \
20+
elif gpg --version | grep -q '^gpg (GnuPG) 1\.'; then \
21+
# "This package provides support for HKPS keyservers." (GnuPG 1.x only)
22+
apt-get install -y --no-install-recommends gnupg-curl; \
23+
fi; \
24+
rm -rf /var/lib/apt/lists/*; \
25+
\
26+
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
27+
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
28+
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
29+
\
30+
# verify the signature
31+
export GNUPGHOME="$(mktemp -d)"; \
32+
gpg2 --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 || \
33+
gpg2 --batch --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 || \
34+
gpg2 --batch --keyserver hkp://ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 || \
35+
gpg2 --batch --keyserver pgp.mit.edu --recv-key B42F6819007F00F88E364FD4036A9C25BF357DD4 || \
36+
gpg2 --batch --keyserver keyserver.pgp.com --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 || \
37+
gpg2 --batch --keyserver pgp.key-server.io --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
38+
gpg2 --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
39+
command -v gpgconf && gpgconf --kill all || :; \
40+
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
41+
\
42+
# clean up fetch dependencies
43+
apt-mark auto '.*' > /dev/null; \
44+
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
45+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
46+
\
47+
chmod +x /usr/local/bin/gosu; \
48+
# verify that the binary works
49+
gosu --version; \
50+
gosu nobody true \
51+
&& chmod +x /usr/local/bin/{entrypoint.sh,entrypoint_setup_gpg.sh} \
1352
&& apt-get -y clean \
1453
&& apt-get -y autoclean \
1554
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*.deb

ci/build_jar.sh

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
#!/bin/bash
22

3-
set -eo pipefail
3+
set -euo pipefail
44

55
cargo clean
66

77
cargo build -j$(($(nproc)+1)) --release --target=x86_64-pc-windows-gnu
88
cargo build -j$(($(nproc)+1)) --release --target=x86_64-unknown-linux-gnu
99

10-
1110
mkdir -p jni/src/main/resources/native/linux64
1211
cp target/x86_64-unknown-linux-gnu/release/libzendoo_sc.so jni/src/main/resources/native/linux64/libzendoo_sc.so
1312

1413
mkdir -p jni/src/main/resources/native/windows64
1514
cp target/x86_64-pc-windows-gnu/release/zendoo_sc.dll jni/src/main/resources/native/windows64/zendoo_sc.dll
1615

1716
cd jni
18-
mvn clean package
19-
20-
if [ "$PUBLISH" = "true" ]; then
21-
echo "Deploying package to maven repository."
22-
mvn deploy
17+
echo "Building jar"
18+
mvn clean package -P !build-extras -DskipTests=true -Dmaven.javadoc.skip=true -B
19+
echo "Testing jar"
20+
mvn test -P !build-extras -B
21+
22+
if [ "$CONTAINER_PUBLISH" = "true" ]; then
23+
echo "Deploying bundle to maven repository"
24+
mvn deploy -P sign,build-extras --settings ../ci/mvn_settings.xml -B
2325
fi

ci/check_tag.sh

-34
This file was deleted.

ci/devtools/lint_pom.xml.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
CONTENT="$(xmllint --format --encode UTF-8 jni/pom.xml)"
4+
echo "${CONTENT}" > jni/pom.xml
5+
6+
SETTINGS_CONTENT="$(xmllint --format --encode UTF-8 ci/mvn_settings.xml)"
7+
echo "${SETTINGS_CONTENT}" > ci/mvn_settings.xml

ci/entrypoint.sh

100644100755
+31-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/bin/bash
2-
set -e
2+
set -euo pipefail
3+
4+
# check required vars are set
5+
if [ -z "${CONTAINER_JAVA_VER+x}" ] && [ -z "${CONTAINER_RUST_VER+x}" ]; then
6+
echo "CONTAINER_JAVA_VER and CONTAINER_RUST_VER environment variables need to be set!"
7+
exit 1
8+
fi
39

410
# Add local zenbuilder user
511
# Either use LOCAL_USER_ID:LOCAL_GRP_ID if set via environment
@@ -22,20 +28,33 @@ echo "Starting with UID/GID: $LOCAL_UID:$LOCAL_GID"
2228

2329
export HOME=/home/zenbuilder
2430

25-
# Fix ownership recursively
26-
chown -RH zenbuilder:zenbuilder /build
31+
# Get Java $CONTAINER_JAVA_VER
32+
apt-get update
33+
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y "$CONTAINER_JAVA_VER" maven
34+
apt-get -y clean
35+
apt-get -y autoclean
36+
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*.deb
2737

28-
# Get Rust
29-
curl https://sh.rustup.rs -sSf | gosu zenbuilder bash -s -- -y
38+
# Get Rust $CONTAINER_RUST_VER
39+
curl https://sh.rustup.rs -sSf | gosu zenbuilder bash -s -- --default-toolchain none -y
3040
gosu zenbuilder echo 'source $HOME/.cargo/env' >> $HOME/.bashrc
3141
export PATH="/home/zenbuilder/.cargo/bin:${PATH}"
42+
gosu zenbuilder rustup toolchain install "$CONTAINER_RUST_VER"
43+
gosu zenbuilder rustup target add --toolchain "$CONTAINER_RUST_VER" x86_64-pc-windows-gnu
44+
# fix "error: could not compile `api`." "/usr/bin/ld: unrecognized option '--nxcompat'"
45+
# https://github.com/rust-lang/rust/issues/32859#issuecomment-284308455
46+
# appears to be fixed in rust 1.42.0
47+
gosu zenbuilder cat << EOF > $HOME/.cargo/config
48+
[target.x86_64-pc-windows-gnu]
49+
linker = "$(which x86_64-w64-mingw32-gcc)"
50+
EOF
51+
52+
# Print version information
53+
gosu zenbuilder java -version
54+
gosu zenbuilder rustc --version
3255

56+
# Fix ownership recursively
57+
chown -RH zenbuilder:zenbuilder /build
3358

34-
# Set Rust
35-
gosu zenbuilder /home/zenbuilder/.cargo/bin/rustup target add x86_64-pc-windows-gnu
36-
37-
#Add maven settings
38-
gosu zenbuilder bash -c "mkdir -p $HOME/.m2 && cp /build/.travis.settings.xml $HOME/.m2/settings.xml"
39-
40-
exec gosu zenbuilder "$@"
59+
exec gosu zenbuilder /usr/local/bin//entrypoint_setup_gpg.sh "$@"
4160

ci/entrypoint_setup_gpg.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
if [ "${CONTAINER_PUBLISH}" = "true" ]; then
6+
export GNUPGHOME="$(mktemp -d 2>/dev/null || mktemp -d -t 'GNUPGHOME')"
7+
# gpg: setting pinentry mode 'loopback' failed: Not supported https://www.fluidkeys.com/tweak-gpg-2.1.11/
8+
echo "allow-loopback-pinentry" > "${GNUPGHOME}"/gpg-agent.conf
9+
gpg2 --batch --fast-import /key.asc
10+
fi
11+
12+
exec "$@"

ci/mvn_settings.xml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings>
3+
<servers>
4+
<server>
5+
<id>ossrh</id>
6+
<username>${env.CONTAINER_OSSRH_JIRA_USERNAME}</username>
7+
<password>${env.CONTAINER_OSSRH_JIRA_PASSWORD}</password>
8+
</server>
9+
</servers>
10+
<profiles>
11+
<profile>
12+
<id>ossrh</id>
13+
<activation>
14+
<activeByDefault>true</activeByDefault>
15+
</activation>
16+
<properties>
17+
<gpg.executable>gpg2</gpg.executable>
18+
<gpg.keyname>${env.CONTAINER_GPG_KEY_NAME}</gpg.keyname>
19+
<gpg.passphrase>${env.CONTAINER_GPG_PASSPHRASE}</gpg.passphrase>
20+
</properties>
21+
</profile>
22+
</profiles>
23+
</settings>

ci/setup_env.sh

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
pom_version="$(xpath -q -e '/project/version/text()' jni/pom.xml)"
6+
7+
echo "TRAVIS_TAG: $TRAVIS_TAG"
8+
echo "jni/pom.xml version: $pom_version"
9+
10+
export CONTAINER_PUBLISH="false"
11+
# empty key.asc file in case we're not signing
12+
touch "${HOME}/key.asc"
13+
14+
if [ ! -z "${TRAVIS_TAG}" ]; then
15+
export GNUPGHOME="$(mktemp -d 2>/dev/null || mktemp -d -t 'GNUPGHOME')"
16+
echo "Tagged build, fetching maintainer keys."
17+
gpg -v --batch --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys $MAINTAINER_KEYS ||
18+
gpg -v --batch --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys $MAINTAINER_KEYS ||
19+
gpg -v --batch --keyserver hkp://pgp.mit.edu:80 --recv-keys $MAINTAINER_KEYS
20+
if git verify-tag -v "${TRAVIS_TAG}"; then
21+
echo "Valid signed tag"
22+
if [ "${TRAVIS_TAG}" != "${pom_version}" ]; then
23+
echo "Aborting, tag differs from the pom file."
24+
exit 1
25+
else
26+
export CONTAINER_PUBLISH="true"
27+
echo "Fetching gpg signing keys."
28+
curl -sLH "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw" "$MAVEN_KEY_ARCHIVE_URL" |
29+
openssl enc -d -aes-256-cbc -md sha256 -pass pass:$MAVEN_KEY_ARCHIVE_PASSWORD |
30+
tar -xzf- -C "${HOME}"
31+
fi
32+
fi
33+
fi
34+
35+
# unset credentials if not publishing
36+
if [ "${CONTAINER_PUBLISH}" = "false" ]; then
37+
export CONTAINER_OSSRH_JIRA_USERNAME=""
38+
export CONTAINER_OSSRH_JIRA_PASSWORD=""
39+
export CONTAINER_GPG_KEY_NAME=""
40+
export CONTAINER_GPG_PASSPHRASE=""
41+
unset CONTAINER_OSSRH_JIRA_USERNAME
42+
unset CONTAINER_OSSRH_JIRA_PASSWORD
43+
unset CONTAINER_GPG_KEY_NAME
44+
unset CONTAINER_GPG_PASSPHRASE
45+
fi
46+
47+
# unset credentials after use
48+
export GITHUB_TOKEN=""
49+
export MAVEN_KEY_ARCHIVE_URL=""
50+
export MAVEN_KEY_ARCHIVE_PASSWORD=""
51+
unset GITHUB_TOKEN
52+
unset MAVEN_KEY_ARCHIVE_URL
53+
unset MAVEN_KEY_ARCHIVE_PASSWORD
54+
55+
set +eo pipefail

0 commit comments

Comments
 (0)