Skip to content

Commit b7dfd33

Browse files
committed
.travis, build: Build step to push .aar to Maven Central
1 parent 178da7c commit b7dfd33

File tree

6 files changed

+216
-15
lines changed

6 files changed

+216
-15
lines changed

.travis.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,22 @@ matrix:
5353
- CC=aarch64-linux-gnu-gcc go run build/ci.go install -arch arm64
5454
- go run build/ci.go archive -arch arm64 -type tar -signer LINUX_SIGNING_KEY -upload gethstore/builds
5555

56-
# This builder does the OSX Azure uploads
56+
# This builder does the OSX Azure, Android Maven and Azure and iOS CocoaPods and Azure uploads
5757
- os: osx
5858
go: 1.7
5959
env:
6060
- azure-osx
61+
- mobile
6162
script:
6263
- go run build/ci.go install
6364
- go run build/ci.go archive -type tar -signer OSX_SIGNING_KEY -upload gethstore/builds
6465

65-
# This builder does the mobile builds (and nothing else)
66-
- os: osx
67-
go: 1.7
68-
script:
66+
# Build the Android archives and upload them to Maven Central
6967
- brew update
70-
- brew install android-sdk
68+
- brew install android-sdk maven
7169
- export ANDROID_HOME=/usr/local/opt/android-sdk
7270
- echo "y" | android update sdk --no-ui --filter platform
73-
- go get github.com/tools/godep
74-
- godep restore
75-
- go get golang.org/x/mobile/cmd/gomobile
76-
- gomobile init
77-
- gomobile bind --target=android --javapkg=org.ethereum -v github.com/ethereum/go-ethereum/mobile
78-
- gomobile bind --target=ios --tags=ios -v github.com/ethereum/go-ethereum/mobile
71+
- go run build/ci.go aar -signer ANDROID_SIGNING_KEY -deploy https://oss.sonatype.org -upload gethstore/builds
7972

8073
install:
8174
- go get golang.org/x/tools/cmd/cover

build/ci.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Available commands are:
2929
importkeys -- imports signing keys from env
3030
debsrc [ -signer key-id ] [ -upload dest ] -- creates a debian source package
3131
nsis -- creates a Windows NSIS installer
32+
aar [ -sign key-id ] [ -upload dest ] -- creates an android archive
3233
xgo [ options ] -- cross builds according to options
3334
3435
For all commands, -n prevents execution of external programs (dry run mode).
@@ -37,6 +38,7 @@ For all commands, -n prevents execution of external programs (dry run mode).
3738
package main
3839

3940
import (
41+
"bufio"
4042
"bytes"
4143
"encoding/base64"
4244
"flag"
@@ -48,6 +50,7 @@ import (
4850
"os"
4951
"os/exec"
5052
"path/filepath"
53+
"regexp"
5154
"runtime"
5255
"strings"
5356
"time"
@@ -125,6 +128,8 @@ func main() {
125128
doDebianSource(os.Args[2:])
126129
case "nsis":
127130
doWindowsInstaller(os.Args[2:])
131+
case "aar":
132+
doAndroidArchive(os.Args[2:])
128133
case "xgo":
129134
doXgo(os.Args[2:])
130135
default:
@@ -331,6 +336,9 @@ func archiveBasename(arch string, env build.Environment) string {
331336
if arch == "arm" {
332337
platform += os.Getenv("GOARM")
333338
}
339+
if arch == "android" {
340+
platform = "android-all"
341+
}
334342
archive := platform + "-" + build.VERSION()
335343
if isUnstableBuild(env) {
336344
archive += "-unstable"
@@ -630,6 +638,125 @@ func doWindowsInstaller(cmdline []string) {
630638
if err := archiveUpload(installer, *upload, *signer); err != nil {
631639
log.Fatal(err)
632640
}
641+
642+
// Android archives
643+
644+
func doAndroidArchive(cmdline []string) {
645+
var (
646+
signer = flag.String("signer", "", `Environment variable holding the signing key (e.g. ANDROID_SIGNING_KEY)`)
647+
deploy = flag.String("deploy", "", `Where to upload the deploy the archive (usually "https://oss.sonatype.org")`)
648+
upload = flag.String("upload", "", `Destination to upload the archives (usually "gethstore/builds")`)
649+
)
650+
flag.CommandLine.Parse(cmdline)
651+
env := build.Env()
652+
653+
// Build the Android archive and Maven resources
654+
build.MustRun(goTool("get", "golang.org/x/mobile/cmd/gomobile"))
655+
build.MustRun(gomobileTool("init"))
656+
build.MustRun(gomobileTool("bind", "--target", "android", "--javapkg", "org.ethereum", "-v", "github.com/ethereum/go-ethereum/mobile"))
657+
658+
meta := newMavenMetadata(env)
659+
build.Render("build/mvn.pom", meta.PackageString()+".pom", 0755, meta)
660+
661+
// Skip Maven deploy and Azure upload for PR builds
662+
maybeSkipArchive(env)
663+
664+
// Sign and upload all the artifacts to Maven Central
665+
os.Rename("geth.aar", meta.PackageString()+".aar")
666+
if *signer != "" && *deploy != "" {
667+
// Import the signing key into the local GPG instance
668+
if b64key := os.Getenv(*signer); b64key != "" {
669+
key, err := base64.StdEncoding.DecodeString(b64key)
670+
if err != nil {
671+
log.Fatalf("invalid base64 %s", *signer)
672+
}
673+
gpg := exec.Command("gpg", "--import")
674+
gpg.Stdin = bytes.NewReader(key)
675+
build.MustRun(gpg)
676+
}
677+
// Upload the artifacts to Sonatype and/or Maven Central
678+
repo := *deploy + "/service/local/staging/deploy/maven2"
679+
if meta.Unstable {
680+
repo = *deploy + "/content/repositories/snapshots"
681+
}
682+
build.MustRunCommand("mvn", "gpg:sign-and-deploy-file",
683+
"-settings=build/mvn.settings", "-Durl="+repo, "-DrepositoryId=ossrh",
684+
"-DpomFile="+meta.PackageString()+".pom", "-Dfile="+meta.PackageString()+".aar")
685+
}
686+
// Sign and upload the archive to Azure
687+
archive := "geth-" + archiveBasename("android", env) + ".aar"
688+
os.Rename(meta.PackageString()+".aar", archive)
689+
690+
if err := archiveUpload(archive, *upload, *signer); err != nil {
691+
log.Fatal(err)
692+
}
693+
}
694+
695+
func gomobileTool(subcmd string, args ...string) *exec.Cmd {
696+
cmd := exec.Command(filepath.Join(GOBIN, "gomobile"), subcmd)
697+
cmd.Args = append(cmd.Args, args...)
698+
cmd.Env = []string{
699+
"GOPATH=" + build.GOPATH(),
700+
}
701+
for _, e := range os.Environ() {
702+
if strings.HasPrefix(e, "GOPATH=") {
703+
continue
704+
}
705+
cmd.Env = append(cmd.Env, e)
706+
}
707+
return cmd
708+
}
709+
710+
type mavenMetadata struct {
711+
Env build.Environment
712+
Version string
713+
Unstable bool
714+
Contributors []mavenContributor
715+
}
716+
717+
type mavenContributor struct {
718+
Name string
719+
Email string
720+
}
721+
722+
func newMavenMetadata(env build.Environment) mavenMetadata {
723+
// Collect the list of authors from the repo root
724+
contribs := []mavenContributor{}
725+
if authors, err := os.Open("AUTHORS"); err == nil {
726+
defer authors.Close()
727+
728+
scanner := bufio.NewScanner(authors)
729+
for scanner.Scan() {
730+
// Skip any whitespace from the authors list
731+
line := strings.TrimSpace(scanner.Text())
732+
if line == "" || line[0] == '#' {
733+
continue
734+
}
735+
// Split the author and insert as a contributor
736+
re := regexp.MustCompile("([^<]+) <(.+>)")
737+
parts := re.FindStringSubmatch(line)
738+
if len(parts) == 3 {
739+
contribs = append(contribs, mavenContributor{Name: parts[1], Email: parts[2]})
740+
}
741+
}
742+
}
743+
return mavenMetadata{
744+
Env: env,
745+
Version: build.VERSION(),
746+
Unstable: isUnstableBuild(env),
747+
Contributors: contribs,
748+
}
749+
}
750+
751+
func (meta mavenMetadata) VersionString() string {
752+
if meta.Unstable {
753+
return meta.Version + "-SNAPSHOT"
754+
}
755+
return meta.Version
756+
}
757+
758+
func (meta mavenMetadata) PackageString() string {
759+
return "geth-" + meta.VersionString()
633760
}
634761

635762
// Cross compilation

build/mvn.pom

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.ethereum</groupId>
8+
<artifactId>geth</artifactId>
9+
<version>{{.VersionString}}</version>
10+
<packaging>aar</packaging>
11+
12+
<name>Android Ethereum Client</name>
13+
<description>Android port of the go-ethereum libraries and node</description>
14+
<url>https://github.com/ethereum/go-ethereum</url>
15+
<inceptionYear>2015</inceptionYear>
16+
17+
<licenses>
18+
<license>
19+
<name>GNU Lesser General Public License, Version 3.0</name>
20+
<url>https://www.gnu.org/licenses/lgpl-3.0.en.html</url>
21+
<distribution>repo</distribution>
22+
</license>
23+
</licenses>
24+
25+
<organization>
26+
<name>Ethereum</name>
27+
<url>https://ethereum.org</url>
28+
</organization>
29+
30+
<developers>
31+
<developer>
32+
<id>karalabe</id>
33+
<name>Péter Szilágyi</name>
34+
<email>peterke@gmail.com</email>
35+
<url>https://github.com/karalabe</url>
36+
<properties>
37+
<picUrl>https://www.gravatar.com/avatar/2ecbf0f5b4b79eebf8c193e5d324357f?s=256</picUrl>
38+
</properties>
39+
</developer>
40+
</developers>
41+
42+
<contributors>{{range .Contributors}}
43+
<contributor>
44+
<name>{{.Name}}</name>
45+
<email>{{.Email}}</email>
46+
</contributor>{{end}}
47+
</contributors>
48+
49+
<issueManagement>
50+
<system>GitHub Issues</system>
51+
<url>https://github.com/ethereum/go-ethereum/issues/</url>
52+
</issueManagement>
53+
54+
<scm>
55+
<url>https://github.com/ethereum/go-ethereum</url>
56+
</scm>
57+
</project>

build/mvn.settings

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
4+
http://maven.apache.org/xsd/settings-1.0.0.xsd">
5+
<servers>
6+
<server>
7+
<id>ossrh</id>
8+
<username>${env.ANDROID_SONATYPE_USERNAME}</username>
9+
<password>${env.ANDROID_SONATYPE_PASSWORD}</password>
10+
</server>
11+
</servers>
12+
<profiles>
13+
<profile>
14+
<id>ossrh</id>
15+
<activation>
16+
<activeByDefault>true</activeByDefault>
17+
</activation>
18+
<properties>
19+
<gpg.executable>gpg</gpg.executable>
20+
<gpg.passphrase></gpg.passphrase>
21+
</properties>
22+
</profile>
23+
</profiles>
24+
</settings>

internal/build/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func GOPATH() string {
5656
if len(path) == 0 {
5757
log.Fatal("GOPATH is not set")
5858
}
59-
// Ensure that our internal vendor folder in on GOPATH
59+
// Ensure that our internal vendor folder is on GOPATH
6060
vendor, _ := filepath.Abs(filepath.Join("build", "_vendor"))
6161
for _, dir := range path {
6262
if dir == vendor {

mobile/geth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"github.com/ethereum/go-ethereum/ethclient"
3333
"github.com/ethereum/go-ethereum/node"
3434
"github.com/ethereum/go-ethereum/p2p/nat"
35-
"github.com/ethereum/go-ethereum/whisper"
35+
"github.com/ethereum/go-ethereum/whisper/whisperv2"
3636
)
3737

3838
// NodeConfig represents the collection of configuration values to fine tune the Geth
@@ -150,7 +150,7 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) {
150150
}
151151
// Register the Whisper protocol if requested
152152
if config.WhisperEnabled {
153-
if err := stack.Register(func(*node.ServiceContext) (node.Service, error) { return whisper.New(), nil }); err != nil {
153+
if err := stack.Register(func(*node.ServiceContext) (node.Service, error) { return whisperv2.New(), nil }); err != nil {
154154
return nil, fmt.Errorf("whisper init: %v", err)
155155
}
156156
}

0 commit comments

Comments
 (0)