Skip to content

Commit 8751c94

Browse files
committed
Deploy JAR files to Maven Central for PPDTs
1 parent 289fa27 commit 8751c94

4 files changed

Lines changed: 221 additions & 7 deletions

File tree

.github/workflows/deploy_jar.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Publish JAR file to release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
create_release:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
v-version: ${{ steps.version.outputs.v-version }}
14+
steps:
15+
# Can be major, minor, or patch, Update environment variable INCREMENT_TYPE in GitHub Actions Settings
16+
- name: Set increment type from environment variable
17+
run: |
18+
if [ -z "${{ secrets.INCREMENT_TYPE }}" ]; then
19+
echo "increment=patch" >> $GITHUB_ENV
20+
else
21+
echo "increment=${{ secrets.INCREMENT_TYPE }}" >> $GITHUB_ENV
22+
fi
23+
- name: Get next version
24+
uses: reecetech/version-increment@2023.10.2
25+
id: version
26+
with:
27+
release_branch: main
28+
use_api: true
29+
increment: ${{ env.increment }}
30+
31+
upload_release:
32+
needs: [ create_release ]
33+
if: github.repository == 'adwise-fiu/Level-Site-PPDT'
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout project sources
37+
uses: actions/checkout@v4
38+
39+
- name: Create JAR file
40+
uses: actions/setup-java@v4
41+
with:
42+
distribution: 'oracle'
43+
java-version: '17'
44+
cache: 'gradle'
45+
# Remove the leading v from the version string and set it as an environment variable
46+
- run: |
47+
VERSION=${{ needs.create_release.outputs.v-version }}
48+
VERSION=${VERSION#v}
49+
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
50+
51+
# https://central.sonatype.org/publish/publish-portal-api/
52+
# https://central.sonatype.com/api-doc
53+
- name: Create Bundle.zip file and use Publisher API
54+
run: |
55+
./gradlew publishToMavenLocal
56+
bash create_bundle.sh $VERSION
57+
curl --request POST \
58+
--verbose \
59+
--header "Authorization: Bearer ${BEARER_TOKEN}" \
60+
--form bundle=@bundle.zip \
61+
--form publishingType=AUTOMATIC \
62+
https://central.sonatype.com/api/v1/publisher/upload \
63+
--fail --write-out "%{http_code}" --output /dev/null
64+
if [ $? -ne 0 ]; then
65+
echo "Error: curl did not return 201. Failing the step."
66+
exit 1
67+
fi
68+
env:
69+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
70+
BEARER_TOKEN: ${{ secrets.BEARER_TOKEN }}
71+
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
72+
VERSION: ${{ env.RELEASE_VERSION }}
73+
74+
- name: Release the JAR file
75+
uses: softprops/action-gh-release@v2
76+
with:
77+
tag_name: ${{ needs.create_release.outputs.v-version }}
78+
files: build/libs/*.jar
79+
token: ${{ secrets.GITHUB_TOKEN }}

build.gradle

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
plugins {
22
id 'java'
3+
id 'java-library'
34
id 'jacoco'
45
id 'application'
6+
id 'maven-publish'
7+
id 'signing'
58
}
69

710
group 'io.github.andrewquijano'
@@ -17,17 +20,26 @@ java {
1720
}
1821

1922
dependencies {
20-
implementation 'junit:junit:4.13.2'
21-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.0-M2'
22-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.0-M2'
23+
testImplementation 'junit:junit:4.13.2'
2324

24-
implementation 'io.github.andrewquijano:ciphercraft:1.0.3'
25+
implementation 'io.github.andrewquijano:ciphercraft:1.0.6'
2526
// https://mvnrepository.com/artifact/commons-io/commons-io
2627
implementation 'commons-io:commons-io:2.16.1'
2728
// https://mvnrepository.com/artifact/nz.ac.waikato.cms.weka/weka-dev
2829
implementation 'nz.ac.waikato.cms.weka:weka-dev:3.9.6'
29-
implementation 'org.apache.logging.log4j:log4j-core:3.0.0-beta1'
30-
implementation fileTree(dir: 'libs', include: ['*.jar'])
30+
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
31+
implementation 'org.apache.logging.log4j:log4j-core:2.24.3'
32+
}
33+
34+
// To create the JAR file with 'gradlew jar'
35+
tasks.named('jar') {
36+
archiveFileName = "${project.name}-${project.version}.jar"
37+
manifest {
38+
attributes(
39+
'Implementation-Title': project.name,
40+
'Implementation-Version': System.getenv('VERSION') ?: project.version
41+
)
42+
}
3143
}
3244

3345
// Commenting because it doesn't work well on TravisCI
@@ -89,3 +101,84 @@ check.dependsOn jacocoTestReport
89101
application {
90102
mainClass.set(project.findProperty("chooseRole").toString())
91103
}
104+
105+
tasks.register('generateJavadoc', Javadoc) {
106+
source = sourceSets.main.allJava
107+
classpath = sourceSets.main.compileClasspath
108+
options.encoding = 'UTF-8'
109+
options.memberLevel = JavadocMemberLevel.PUBLIC
110+
options.addStringOption('Xdoclint:none', '-quiet')
111+
options.docTitle = 'Level-Site Privacy-Preserving Decision Tree'
112+
}
113+
114+
// This is for publishing the library to Maven Central
115+
publishing {
116+
publications {
117+
register("mavenJava", MavenPublication) {
118+
from components.java
119+
120+
pom {
121+
name.set('level-site-ppdt')
122+
description.set('This JAR file is used for implementing the Level-Site Privacy-Preserving Decision Trees (PPDT). ' +
123+
'See the paper "Enhanced Outsourced and Secure Inference for Tall Sparse Decision Trees" which describes the implementation and ' +
124+
'performance gains this approach has in avoiding the conversion to a complete binary tree as in the Joye and Salehi paper.')
125+
url.set('https://github.com/adwise-fiu/Level-Site-PPDT')
126+
127+
licenses {
128+
license {
129+
name.set('MIT License')
130+
url.set('https://opensource.org/licenses/MIT')
131+
}
132+
}
133+
134+
developers {
135+
developer {
136+
id.set('AndrewQuijano')
137+
name.set('Andrew Quijano')
138+
email.set('andrew.quijano@nyu.edu')
139+
}
140+
}
141+
142+
scm {
143+
connection.set('scm:git:git://github.com/adwise-fiu/Level-Site-PPDT.git')
144+
developerConnection.set('scm:git:ssh://github.com:adwise-fiu/Level-Site-PPDT.git')
145+
url.set('https://github.com/adwise-fiu/Level-Site-PPDT')
146+
}
147+
}
148+
}
149+
}
150+
}
151+
152+
// Update this file, ~/.gnupg/dirmngr.conf
153+
// and add this line to the file 'keyserver hkps://keyserver.ubuntu.com'
154+
// then run 'gpg --send-keys YOUR_KEY_ID'
155+
signing {
156+
// Point to the key file on your machine, used for local testing
157+
def signingKeyFile = findProperty("signingKeyFile") ?: System.getenv("SIGNING_KEY_FILE")
158+
// gpg --armor --export-secret-keys YOUR_KEY_ID, export the key into a secret
159+
def signingKey = findProperty("signingKey") ?: System.getenv("SIGNING_KEY") ?: ""
160+
// If no property or environment variable is found, it will be empty password
161+
def signingPassword = findProperty("signingPassword") ?: System.getenv("SIGNING_PASSWORD") ?: ""
162+
163+
if (signingKeyFile) {
164+
println("Reading signing key from file: $signingKeyFile")
165+
def signingKey_content = new File(signingKeyFile.toString()).text
166+
useInMemoryPgpKeys(signingKey_content.toString(), signingPassword.toString())
167+
publishing.publications.named("mavenJava").configure { publication ->
168+
signing.sign(publication)
169+
}
170+
}
171+
else {
172+
println("No signing key file found, will attempt to use in-memory key")
173+
if (signingKey) {
174+
println("Using in-memory signing key")
175+
useInMemoryPgpKeys(signingKey.toString(), signingPassword?.toString())
176+
publishing.publications.named("mavenJava").configure { publication ->
177+
signing.sign(publication)
178+
}
179+
}
180+
else {
181+
println("No signing key found. Skipping signing.")
182+
}
183+
}
184+
}

create_bundle.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Check if a version argument is provided
4+
if [ -z "$1" ]; then
5+
echo "Usage: $0 <version>"
6+
exit 1
7+
fi
8+
9+
# First, you do need to run './gradlew publish' to generate the artifacts.
10+
# I can't publish via API, but I can create a bundle for manual upload.
11+
12+
VERSION=$1
13+
GROUP_ID=io/github/andrewquijano
14+
# This needs to match name in settings.gradle
15+
PROJECT=level-site-ppdt
16+
17+
# Use this script as a stop gap for manual uploading
18+
mkdir -p $GROUP_ID/$PROJECT/$VERSION
19+
cp build/libs/* $GROUP_ID/$PROJECT/$VERSION/
20+
cp build/publications/mavenJava/pom-default.xml $GROUP_ID/$PROJECT/$VERSION/$PROJECT-$VERSION.pom
21+
cp build/publications/mavenJava/pom-default.xml.asc $GROUP_ID/$PROJECT/$VERSION/$PROJECT-$VERSION.pom.asc
22+
23+
# Loop through all files in the specified directory
24+
for file in $GROUP_ID/$PROJECT/$VERSION/*; do
25+
# Print the file being checked
26+
echo "Processing file: $file"
27+
28+
# Skip files ending with .asc
29+
if [[ -f "$file" && ! "$file" =~ \.asc$ ]]; then
30+
echo "Generating hashes for: $file"
31+
32+
# Generate SHA1 checksum
33+
sha1sum "$file" | awk '{print $1}' > "${file}.sha1"
34+
35+
# Generate MD5 checksum
36+
md5sum "$file" | awk '{print $1}' > "${file}.md5"
37+
else
38+
echo "Skipping file: $file"
39+
fi
40+
done
41+
42+
zip -r bundle.zip io/

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rootProject.name = 'ppdt'
1+
rootProject.name = 'level-site-ppdt'
22

0 commit comments

Comments
 (0)