Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 29 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ jobs:

build:
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Java and Gradle
id: setup-java-gradle
uses: ConsenSys/github-actions/java-setup-gradle@main
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@39e147cb9de83bb9910b8ef8bd7fff0ee20fcd6f # v6.0.1
- name: Build
run: ./gradlew --no-daemon --parallel build sourcesJar
run: ./gradlew --no-daemon --parallel build
- name: Upload test results
uses: actions/upload-artifact@v7
if: always()
Expand All @@ -47,21 +53,25 @@ jobs:
retention-days: 7

publish:
needs: build
needs: [build]
environment: publish
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-24.04
if: |
github.ref == 'refs/heads/master' ||
startsWith(github.ref, 'refs/heads/release-') ||
startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Java and Gradle
id: setup-java-gradle
uses: ConsenSys/github-actions/java-setup-gradle@main
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@39e147cb9de83bb9910b8ef8bd7fff0ee20fcd6f # v6.0.1
- name: Publish
env:
CLOUDSMITH_USER: ${{ secrets.CLOUDSMITH_USER }}
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
run: ./gradlew --no-daemon --parallel publish
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.JRELEASER_MAVENCENTRAL_USERNAME }}
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.JRELEASER_MAVENCENTRAL_PASSWORD }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
run: ./gradlew --no-daemon --parallel publish jreleaserFullRelease
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.log
*.db
.classpath
.factorypath
.DS_Store
.gradletasknamecache
.externalToolBuilders/
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# discovery

[![ci](https://github.com/Consensys/discovery/actions/workflows/ci.yml/badge.svg)](https://github.com/Consensys/discovery/actions/workflows/ci.yml)
[![Latest version of 'discovery' @ Cloudsmith](https://api-prd.cloudsmith.io/v1/badges/version/consensys/maven/maven/discovery/latest/a=noarch;xg=tech.pegasys.discovery/?render=true&show_latest=true)](https://cloudsmith.io/~consensys/repos/maven/packages/detail/maven/discovery/latest/a=noarch;xg=tech.pegasys.discovery/)
[![Maven Central](https://img.shields.io/maven-central/v/io.consensys.protocols/discovery)](https://central.sonatype.com/artifact/io.consensys.protocols/discovery)

## Overview

Expand All @@ -12,10 +12,10 @@ peer discovery protocol.

```groovy
repositories {
maven { url "https://artifacts.consensys.net/public/maven/maven/" }
mavenCentral()
}

dependencies {
implementation("tech.pegasys:discovery:<version>")
implementation("io.consensys.protocols:discovery:<version>")
}
```
150 changes: 82 additions & 68 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
//discovery v5
buildscript {
configurations.classpath {
// Force JGit 6.x to resolve conflict between git-versioning (7.x) and JReleaser (5.x)
// JGit 7.x removed GpgObjectSigner which JReleaser still references
// See: https://github.com/jreleaser/jreleaser/discussions/1897
resolutionStrategy.force 'org.eclipse.jgit:org.eclipse.jgit:6.10.0.202406032230-r'
}
}

plugins {
id 'java-library'
id 'maven-publish'
id 'com.diffplug.spotless' version '6.25.0'
id 'com.github.ben-manes.versions' version '0.51.0'
id 'com.github.hierynomus.license' version '0.16.1'
id 'io.spring.dependency-management' version '1.1.5'
id 'net.ltgt.errorprone' version '4.0.1'
id 'org.ajoberstar.grgit' version '5.2.2'
id 'net.ltgt.errorprone' version '5.1.0'
id 'me.qoomon.git-versioning' version '6.4.4'
id 'org.jreleaser' version '1.23.0'
}

rootProject.version = calculatePublishVersion()
def specificVersion = calculateVersion()
group = "io.consensys.protocols"
version = "UNKNOWN"

gitVersioning.apply {
refs {
tag(".+") {
version = "\${ref}"
}
branch("master") {
version = "develop"
}
branch("release-.+") {
version = "\${ref}-develop"
}
branch(".+") {
version = "\${ref}"
}
}
rev {
version = "UNKNOWN"
}
}

apply from: "${rootDir}/gradle/versions.gradle"
apply from: "${rootDir}/gradle/check-licenses.gradle"
Expand Down Expand Up @@ -48,7 +77,7 @@ dependencies {
testRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl'

errorprone("com.google.errorprone:error_prone_core")
errorprone("tech.pegasys.tools.epchecks:errorprone-checks")
errorprone("io.consensys.protocols:errorprone-checks")
}

spotless {
Expand Down Expand Up @@ -104,6 +133,8 @@ tasks.withType(JavaCompile) {
check('CanIgnoreReturnValueSuggester', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
// We prefer to be more explicit in address selection especially in tests, so removing this check
check('AddressSelection', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
// Interface constant initializing a subclass is intentional in IdentitySchemaInterpreter
check('ClassInitializationDeadlock', net.ltgt.gradle.errorprone.CheckSeverity.OFF)

// These are experimental checks that we want enabled.
check('MissingBraces', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
Expand Down Expand Up @@ -135,12 +166,17 @@ tasks.withType(JavaCompile) {
'Specification-Title': project.name,
'Specification-Version': project.version,
'Implementation-Title': project.name,
'Implementation-Version': specificVersion
'Implementation-Version': project.version
)
}
}
}

java {
withJavadocJar()
withSourcesJar()
}

test {
jvmArgs = [
'-Xmx4g',
Expand All @@ -153,57 +189,43 @@ test {
}

javadoc {
options.addStringOption('Xdoclint:all', '-quiet')
options.addStringOption('Xdoclint:all,-missing', '-quiet')
options.addStringOption('Xwerror', '-html5')
options.encoding = 'UTF-8'
}

task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}

task runTestDiscovery(type:JavaExec) {
mainClass = 'org.ethereum.beacon.discovery.app.DiscoveryTestServer'
classpath = sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath
systemProperty "log4j.configurationFile", "log4j2-test-discovery.xml"
}

def cloudsmithUser = project.hasProperty('cloudsmithUser') ? project.property('cloudsmithUser') : System.getenv('CLOUDSMITH_USER')
def cloudsmithKey = project.hasProperty('cloudsmithApiKey') ? project.property('cloudsmithApiKey') : System.getenv('CLOUDSMITH_API_KEY')

apply plugin: 'maven-publish'
publishing {
repositories {
maven {
name = "cloudsmith"
url = "https://api-g.cloudsmith.io/maven/consensys/maven/"
credentials {
username = cloudsmithUser
password = cloudsmithKey
}
}
}
publications {
mavenJava(MavenPublication) {
groupId "tech.pegasys.discovery"
version project.version
groupId "io.consensys.protocols"
from components.java
artifact sourcesJar

versionMapping {
usage('java-api') { fromResolutionOf('runtimeClasspath') }
usage('java-runtime') { fromResolutionResult() }
}
pom {
name = "${project.name}"
url = 'http://github.com/ConsenSys/discovery'
description = 'Java implementation of the Ethereum Discovery v5 protocol'
url = 'https://github.com/ConsenSys/discovery'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = "consensys"
name = "Protocols Team"
email = "devops@consensys.net"
}
}
scm {
connection = 'scm:git:git://github.com/ConsenSys/discovery.git'
developerConnection = 'scm:git:ssh://github.com/ConsenSys/discovery.git'
Expand All @@ -212,46 +234,38 @@ publishing {
}
}
}
}


// Calculate the version that this build would be published under (if it is published)
// If this exact commit is tagged, use the tag
// If this is on a release-* branch, use the most recent tag appended with +develop (e.g. 0.1.1-RC1+develop)
// Otherwise, use develop
def calculatePublishVersion() {
if (!grgit) {
return 'UNKNOWN'
}
def specificVersion = calculateVersion()
def isReleaseBranch = grgit.branch.current().name.startsWith('release-')
if (specificVersion.contains('+')) {
return isReleaseBranch ? "${specificVersion.substring(0, specificVersion.indexOf('+'))}+develop" : "develop"
repositories {
maven {
url = layout.buildDirectory.dir("staging-deploy")
}
}
return specificVersion
}

// Calculate the version that teku --version will report (among other places)
// If this exact commit is tagged, use the tag
// Otherwise use git describe --tags and replace the - after the tag with a +
def calculateVersion() {
if (!grgit) {
return 'UNKNOWN'
}
String version = grgit.describe(tags: true)
if (version == null) {
return "UNKNOWN+g${grgit.head().abbreviatedId}"
jreleaser {
release {
github {
// Creating and tagging a release is done manually
skipRelease = true
skipTag = true
// injecting a fake value to make JReleaser happy
token = "foobar"
}
}
def versionPattern = ~/^(?<lastVersion>.*)-(?<devVersion>[0-9]+-g[a-z0-9]+)$/
def matcher = version =~ versionPattern
if (matcher.find()) {
return "${matcher.group("lastVersion")}+${matcher.group("devVersion")}"
signing {
active = 'ALWAYS'
armored = true
}
return version
}

task printVersion() {
doFirst {
print "Specific version: ${specificVersion} Publish version: ${project.version}"
deploy {
maven {
mavenCentral {
sonatype {
active = 'ALWAYS'
url = 'https://central.sonatype.com/api/v1/publisher'
stagingRepository('build/staging-deploy')
retryDelay = 15
maxRetries = 100
}
}
}
}
}
4 changes: 2 additions & 2 deletions gradle/versions.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
dependencyManagement {
dependencies {
dependencySet(group: 'com.google.errorprone', version: '2.28.0') {
dependencySet(group: 'com.google.errorprone', version: '2.36.0') {
entry 'error_prone_annotation'
entry 'error_prone_check_api'
entry 'error_prone_core'
entry 'error_prone_test_helpers'
}

dependency 'tech.pegasys.tools.epchecks:errorprone-checks:1.1.1'
dependency 'io.consensys.protocols:errorprone-checks:1.1.2'

dependency 'com.google.guava:guava:33.2.1-jre'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Set-alike collection with data expiring in configured time. This structure is not thread safe,
* please, synchronize usage
*
* @param <V> data type should extend Comparable<V> to avoid collisions
* @param <V> data type should extend {@code Comparable<V>} to avoid collisions
*/
public class ExpirationSet<V extends Comparable<V>> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/**
* Schedules `runnable` in delay which is set by constructor. When runnable is renewed by putting it
* in map again, old task is cancelled and removed. Task are equalled by the <Key>
* in map again, old task is cancelled and removed. Task are equalled by the {@code Key}
*/
public class ExpirationScheduler<Key> {
private final ScheduledExecutorService scheduler;
Expand Down
Loading