Skip to content

Commit

Permalink
Add Java release workflow (#1557)
Browse files Browse the repository at this point in the history
Add Java release workflow
  • Loading branch information
samuel-rufi authored Nov 15, 2022
1 parent 48db2d2 commit f944264
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 36 deletions.
133 changes: 133 additions & 0 deletions .github/workflows/java_binding_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Create Java release

on: workflow_dispatch

jobs:
release-java:
name: Create Java release
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
java: ["11"]

steps:
- uses: actions/checkout@v3

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Install LLVM and Clang (Windows) # required for bindgen to work, see https://github.com/rust-lang/rust-bindgen/issues/1797
uses: KyleMayes/install-llvm-action@32c4866ebb71e0949e8833eb49beeebed48532bd
if: matrix.os == 'windows-2019'
with:
version: "11.0"
directory: ${{ runner.temp }}/llvm

- name: Set LIBCLANG_PATH (Windows)
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
if: matrix.os == 'windows-2019'

- name: Get current date
run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
if: matrix.os == 'macos-latest' || ${{ startsWith(matrix.os, 'ubuntu') }}

- name: Get current date
if: matrix.os == 'windows-2019'
run: echo "CURRENT_DATE=$(Get-Date -Format "yyyy-MM-dd")" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Install required packages (Ubuntu)
if: ${{ startsWith(matrix.os, 'ubuntu') }}
run: |
sudo apt-get update
sudo apt-get install libudev-dev libusb-1.0-0-dev
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
# Add date to the cache to keep it up to date
key: ${{ matrix.os }}-stable-cargo-registry-${{ hashFiles('**/Cargo.lock') }}-${{ env.CURRENT_DATE }}
# Restore from outdated cache for speed
restore-keys: |
${{ matrix.os }}-stable-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
${{ matrix.os }}-stable-cargo-registry-
- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
# Add date to the cache to keep it up to date
key: ${{ matrix.os }}-stable-cargo-index-${{ hashFiles('**/Cargo.lock') }}-${{ env.CURRENT_DATE }}
# Restore from outdated cache for speed
restore-keys: |
${{ matrix.os }}-stable-cargo-index-${{ hashFiles('**/Cargo.lock') }}
${{ matrix.os }}-stable-cargo-index-
- name: Set Up Java ${{ matrix.java }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'

- name: Build JAR for default target
shell: bash
working-directory: bindings/java/iota-wallet-java/
run: |
chmod +x gradlew
./gradlew build
- name: Build JAR for aarch64-apple-darwin target
if: matrix.os == 'macos-latest'
shell: bash
env:
ORG_GRADLE_PROJECT_buildTarget: aarch64-apple-darwin
working-directory: bindings/java/iota-wallet-java/
run: |
rustup target add aarch64-apple-darwin
./gradlew build
- name: Get filename for tag construction
shell: bash
id: filename
working-directory: bindings/java/iota-wallet-java/
run: |
cd lib/build/libs/
fileName="$(ls | grep -m 1 jar)"
echo "FILE_NAME=$fileName" >> $GITHUB_OUTPUT
- name: Construct tag
uses: actions-ecosystem/action-regex-match@v2
id: tag
with:
text: ${{ steps.filename.outputs.FILE_NAME }}
regex: '.*\d.\d.\d(-rc.\d)?'
flags: m

- name: Upload JAR to Github
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: |
bindings/java/iota-wallet-java/lib/build/libs/*.jar
tag_name: ${{ steps.tag.outputs.match }}
append_body: true
prerelease: true

- name: Publish JAR to Maven Central
env:
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_PASSWORD }}
ORG_GRADLE_PROJECT_base64EncodedAsciiArmoredSigningKey: ${{ secrets.ORG_GRADLE_PROJECT_BASE64_ENCODED_ASCII_ARMORED_SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PASSWORD }}
shell: bash
working-directory: bindings/java/iota-wallet-java/
run: |
./gradlew publishToSonatype
if [ "$RUNNER_OS" == "macOS" ];
then ORG_GRADLE_PROJECT_buildTarget=aarch64-apple-darwin ./gradlew publishToSonatype
fi
6 changes: 6 additions & 0 deletions bindings/java/iota-wallet-java/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security -->

## 1.0.0-rc.2 - 2022-11-10

### Changed

- Updating native dependencies;

## 1.0.0-rc.1 - 2022-10-06

### Added
Expand Down
11 changes: 11 additions & 0 deletions bindings/java/iota-wallet-java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
}

group 'org.iota'

nexusPublishing {
repositories {
sonatype()
}
}
3 changes: 0 additions & 3 deletions bindings/java/iota-wallet-java/examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ repositories {
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'

implementation 'com.google.guava:guava:31.0.1-jre'
implementation project(':lib')
}

Expand Down
77 changes: 50 additions & 27 deletions bindings/java/iota-wallet-java/lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@ plugins {
id 'com.google.osdetector' version '1.7.1'
}

group 'org.iota'
version '1.0.0-rc.1'

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
// Dependencies that are used internally, and not exposed to consumers on their own compile classpath.
implementation group: 'com.google.code.gson', name: 'gson', version: '2.7'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.9'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
implementation group: 'commons-codec', name: 'commons-codec', version: '1.15'
}
Expand All @@ -44,25 +36,40 @@ test {
useJUnitPlatform()
}

version = '1.0.0-rc.2'

task buildRustRelease(type:Exec){
workingDir 'native'
commandLine 'cargo', 'build', '--release'

if (!project.hasProperty('buildTarget')) {
commandLine 'cargo', 'build', '--release'
} else {
commandLine 'cargo', 'build', '--target=' + buildTarget, '--release'
}
}

archivesBaseName = 'iota-wallet-java'

jar {
dependsOn 'buildRustRelease'

duplicatesStrategy = DuplicatesStrategy.EXCLUDE

from('native/target/release') {
include '*.so', '*.dylib', '*.dll'
if (!project.hasProperty('buildTarget')) {
from('native/target/release') {
include '*.so', '*.dylib', '*.dll'
}
} else {
from('native/target/' + findProperty('buildTarget') + '/release') {
include '*.so', '*.dylib', '*.dll'
}
}

from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}

classifier = osdetector.classifier
classifier = getJarClassifier()
}

publishing {
Expand All @@ -71,7 +78,7 @@ publishing {

groupId = 'org.iota'
artifactId = 'iota-wallet-java'
version = '1.0.0-rc.1'
version = project.version

from components.java

Expand Down Expand Up @@ -105,19 +112,35 @@ publishing {
}
}
}

repositories {
maven {
name = "OSSRH"
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username = project.properties["ossrhUsername"]
password = project.properties["ossrhPassword"]
}
}
}
}

signing {
// The ASCII armored signing key contains important new line characters that are lost when loading the content for example like: `def signingKey = findProperty("signingKey"))`
// To solve this, encode the ASCII armored signing key in base64 and store it in the `ORG_GRADLE_PROJECT_base64EncodedAsciiArmoredSigningKey` environment variable.
// The following line will decode it correctly:
def signingKey = base64Decode(findProperty("base64EncodedAsciiArmoredSigningKey"))
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.mavenJava
}

repositories {
mavenCentral()
}

def base64Decode(encodedString){
if(encodedString != null) {
byte[] decoded = encodedString.decodeBase64()
String decode = new String(decoded)
return decode
}
return null;
}

def getJarClassifier(){
def buildTarget = findProperty("buildTarget")
if(buildTarget != null)
return buildTarget
else
return osdetector.classifier
}
9 changes: 3 additions & 6 deletions bindings/java/iota-wallet-java/lib/native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f944264

Please sign in to comment.