Skip to content

Commit 3db4e08

Browse files
ivo.liondovivo.liondov
authored andcommitted
Enable maven package upload
1 parent c5979f3 commit 3db4e08

File tree

7 files changed

+381
-15
lines changed

7 files changed

+381
-15
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Maven Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+' # Matches tags in the form 3.3.0
7+
8+
jobs:
9+
maven-publish:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 30
12+
env:
13+
WORKSPACE: "${{ github.workspace }}"
14+
GIT_BRANCH: "${{ github.ref }}"
15+
CURRENT_TAG: "${{ github.ref_name }}"
16+
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
17+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
18+
PGP_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
19+
PGP_KEY_ID: ${{ secrets.PGP_KEY_ID }}
20+
GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
21+
steps:
22+
- name: Set up Git
23+
run: git config --global --add safe.directory '*'
24+
25+
- name: Checkout Repository
26+
uses: actions/checkout@v3
27+
28+
- name: Set Up Java
29+
uses: actions/setup-java@v3
30+
with:
31+
distribution: 'temurin' # Use Eclipse Temurin distribution
32+
java-version: '11' # Use Java 11 for Android builds
33+
34+
- name: Install Android SDK
35+
run: |
36+
sudo apt-get update
37+
sudo apt-get install -y unzip curl
38+
mkdir -p $ANDROID_HOME/cmdline-tools
39+
curl -o android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-9123335_latest.zip
40+
unzip -q android-sdk.zip -d $ANDROID_HOME/cmdline-tools
41+
mv $ANDROID_HOME/cmdline-tools/cmdline-tools $ANDROID_HOME/cmdline-tools/tools
42+
rm android-sdk.zip
43+
echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV
44+
echo "PATH=$ANDROID_HOME/cmdline-tools/tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH" >> $GITHUB_ENV
45+
- name: Accept Android SDK Licenses
46+
shell: bash
47+
run: |
48+
source $GITHUB_ENV
49+
yes | sdkmanager --licenses || true
50+
- name: Install Required SDK Packages
51+
shell: bash
52+
run: |
53+
source $GITHUB_ENV
54+
sdkmanager "platform-tools" "platforms;android-33" "build-tools;33.0.2"
55+
56+
57+
- name: Install GPG
58+
run: |
59+
sudo apt-get update
60+
sudo apt-get install -y gnupg
61+
62+
- name: Import GPG Private Key
63+
run: |
64+
echo "${{ secrets.GPG_PRIVATE_KEY }}" > private.key
65+
gpg --batch --import private.key
66+
rm private.key
67+
68+
- name: Trust GPG Key
69+
run: |
70+
KEY_ID=$(gpg --list-keys --with-colons | grep pub | cut -d: -f5)
71+
echo -e "trust\n5\ny\nquit" | gpg --batch --yes --command-fd 0 --edit-key $KEY_ID
72+
73+
- name: Build AAR
74+
run: ./gradlew assembleRelease
75+
76+
- name: Create Package
77+
run: cd .maven && ./build-and-sign.sh
78+
79+
- name: Publish Package
80+
run: cd .maven && ./maven-publish.sh
81+
82+
- name: Upload Artifact
83+
uses: actions/upload-artifact@v3
84+
with:
85+
name: full-repo-artifact-${{ github.ref_name }}
86+
path: ${{ github.workspace }}

.maven/build-and-sign.sh

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
#!/bin/bash
2+
3+
## set variables/constants required by the script
4+
5+
# The version of the package that will be build and will be visible in maven central
6+
# For Approov SDK release 3.3.0 (library 7257) the version was 3.3.0
7+
# This is also used to rename the folder where the package is stored by replacing the TAG-RENAME-DIR
8+
# THE POM FILE MUST BE UPDATED WITH THE CORRECT VERSION WHICH MUST MATCH THIS VARIABLE
9+
VERSION="3.3.0"
10+
11+
# Constant: current package name
12+
CURRENT_PACKAGE_NAME="service.httpsurlconn"
13+
14+
# Constant: Required package subdir structure
15+
PACKAGE_DIR_STRUCTURE="io/approov/${CURRENT_PACKAGE_NAME}"
16+
17+
# Constant: The file prefix for each file placed in the above directory
18+
# NOTE: This is also the name of the binary SDK file expected by Maven
19+
FILE_PREFIX="${CURRENT_PACKAGE_NAME}-${VERSION}"
20+
21+
# The PGP Key ID to use for signing the package; set by CI/CD
22+
# export PGP_KEY_ID=""
23+
# Verify that the PGP_KEY_ID is set
24+
if [ -z "$PGP_KEY_ID" ]; then
25+
echo "Error: PGP_KEY_ID is not set. This script requires a PGP key ID to be set."
26+
exit 1
27+
fi
28+
# Password for the GPG key; set by CI/CD
29+
# export GPG_PASSWORD=""
30+
# Verify that the GPG_PASSWORD is set
31+
if [ -z "$GPG_PASSWORD" ]; then
32+
echo "Error: GPG_PASSWORD is not set. This script requires a GPG password to be set."
33+
exit 1
34+
fi
35+
36+
# The full path to the service aar package generated by gradle build.
37+
AAR_PATH="../approov-service/build/outputs/aar/approov-service-release.aar"
38+
39+
40+
# The path to the javadoc.jar file that will be uploaded to maven central
41+
JAVADOC_JAR_PATH="../approov-service/docs/javadoc.jar"
42+
43+
# Path to the POM file: YOU MUST UPDATE THIS FILE WITH THE CORRECT <version
44+
# which MUST match the VERSION variable above
45+
POM_FILE_PATH="../approov-service/pom.xml"
46+
47+
# Check if the above files exist before proceeding further
48+
if [ ! -f ${AAR_PATH} ]; then
49+
echo "File not found: ${AAR_PATH}"
50+
echo "Please make sure the file exists or change the location in the script and try again"
51+
exit 1
52+
fi
53+
54+
if [ ! -f ${JAVADOC_JAR_PATH} ]; then
55+
echo "File not found: ${JAVADOC_JAR_PATH}"
56+
echo "Please make sure the file exists or change the location in the script and try again"
57+
exit 1
58+
fi
59+
60+
if [ ! -f ${POM_FILE_PATH} ]; then
61+
echo "File not found: ${POM_FILE_PATH}"
62+
echo "Please make sure the file exists or change the location in the script and try again"
63+
exit 1
64+
fi
65+
66+
67+
# The destination directory to place all the files
68+
DESTINATION_DIR="${PACKAGE_DIR_STRUCTURE}/${VERSION}"
69+
70+
echo "Will create destination directory: ${DESTINATION_DIR}"
71+
# Create destination directory in current location
72+
mkdir -p ${DESTINATION_DIR}
73+
# Check if the command was successful
74+
if [ $? -eq 0 ]; then
75+
echo "File successfully created: ${DESTINATION_DIR}"
76+
else
77+
echo "Failed to create directory ${DESTINATION_DIR}"
78+
exit 1
79+
fi
80+
81+
# Copy operations to destination directory
82+
# 1. Copy javadoc.jar file and rename to destination:
83+
# Maven expects for version 3.2.2 of the javadoc.jar the following file
84+
# service.httpsurlconn-3.2.2-javadoc.jar
85+
cp ${JAVADOC_JAR_PATH} ${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar
86+
87+
# Check if the command was successful
88+
if [ $? -eq 0 ]; then
89+
echo "File successfully copied: ${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar"
90+
else
91+
echo "Failed to copy file as ${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar"
92+
exit 1
93+
fi
94+
95+
# Sign the target javadoc file
96+
OUTPUT_SIGNATURE="${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar.asc"
97+
gpg --batch --yes --passphrase "$GPG_PASSWORD" --pinentry-mode loopback --output "$OUTPUT_SIGNATURE" --detach-sign --local-user "$PGP_KEY_ID" "${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar"
98+
99+
# Check if the command was successful
100+
if [ $? -eq 0 ]; then
101+
echo "File successfully signed: ${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar.asc"
102+
else
103+
echo "Failed to sign file as ${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar.asc"
104+
exit 1
105+
fi
106+
# Compute hashes for the javadoc file
107+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar.sha1"
108+
# Compute SHA-1 and extract only the hash
109+
shasum "${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar" | awk '{print $1}' > "$OUTPUT_FILE"
110+
# sha256
111+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar.sha256"
112+
shasum -a 256 "${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar" | awk '{print $1}' > "$OUTPUT_FILE"
113+
# sha512
114+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar.sha512"
115+
shasum -a 512 "${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar" | awk '{print $1}' > "$OUTPUT_FILE"
116+
# md5
117+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar.md5"
118+
md5sum "${DESTINATION_DIR}/${FILE_PREFIX}-javadoc.jar" | awk '{print $1}' > "$OUTPUT_FILE"
119+
120+
121+
# 2. Copy the aar file and rename to destination:
122+
# Maven expects for version 3.2.2 of the aar file the following file
123+
# service.httpsurlconn-3.2.2.aar
124+
cp ${AAR_PATH} ${DESTINATION_DIR}/${FILE_PREFIX}.aar
125+
126+
# Check if the command was successful
127+
if [ $? -eq 0 ]; then
128+
echo "File successfully copied: ${DESTINATION_DIR}/${FILE_PREFIX}.aar"
129+
else
130+
echo "Failed to copy file as ${DESTINATION_DIR}/${FILE_PREFIX}.aar"
131+
exit 1
132+
fi
133+
134+
# Sign the android SDK aar file
135+
OUTPUT_SIGNATURE="${DESTINATION_DIR}/${FILE_PREFIX}.aar.asc"
136+
gpg --batch --yes --passphrase "$GPG_PASSWORD" --pinentry-mode loopback --output "$OUTPUT_SIGNATURE" --detach-sign --local-user "$PGP_KEY_ID" "${DESTINATION_DIR}/${FILE_PREFIX}.aar"
137+
138+
# Check if the command was successful
139+
if [ $? -eq 0 ]; then
140+
echo "File successfully signed: ${DESTINATION_DIR}/${FILE_PREFIX}.aar.asc"
141+
else
142+
echo "Failed to sign file as ${DESTINATION_DIR}/${FILE_PREFIX}.aar.asc"
143+
exit 1
144+
fi
145+
146+
# Compute hashes for the aar file
147+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}.aar.sha1"
148+
# Compute SHA-1 and extract only the hash
149+
shasum "${DESTINATION_DIR}/${FILE_PREFIX}.aar" | awk '{print $1}' > "$OUTPUT_FILE"
150+
# sha256
151+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}.aar.sha256"
152+
shasum -a 256 "${DESTINATION_DIR}/${FILE_PREFIX}.aar" | awk '{print $1}' > "$OUTPUT_FILE"
153+
# sha512
154+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}.aar.sha512"
155+
shasum -a 512 "${DESTINATION_DIR}/${FILE_PREFIX}.aar" | awk '{print $1}' > "$OUTPUT_FILE"
156+
# md5
157+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}.aar.md5"
158+
md5sum "${DESTINATION_DIR}/${FILE_PREFIX}.aar" | awk '{print $1}' > "$OUTPUT_FILE"
159+
160+
161+
# 3. Copy the pom file and rename to destination:
162+
# Maven expects for version 3.2.2 of the pom file the following file
163+
# service.httpsurlconn-3.2.2.pom
164+
cp ${POM_FILE_PATH} ${DESTINATION_DIR}/${FILE_PREFIX}.pom
165+
166+
# Check if the command was successful
167+
if [ $? -eq 0 ]; then
168+
echo "File successfully copied: ${DESTINATION_DIR}/${FILE_PREFIX}.pom"
169+
else
170+
echo "Failed to copy file as ${DESTINATION_DIR}/${FILE_PREFIX}.pom"
171+
exit 1
172+
fi
173+
174+
# Sign the pom file
175+
OUTPUT_SIGNATURE="${DESTINATION_DIR}/${FILE_PREFIX}.pom.asc"
176+
gpg --batch --yes --passphrase "$GPG_PASSWORD" --pinentry-mode loopback --output "$OUTPUT_SIGNATURE" --detach-sign --local-user "$PGP_KEY_ID" "${DESTINATION_DIR}/${FILE_PREFIX}.pom"
177+
178+
# Check if the command was successful
179+
if [ $? -eq 0 ]; then
180+
echo "File successfully signed: ${DESTINATION_DIR}/${FILE_PREFIX}.pom.asc"
181+
else
182+
echo "Failed to sign file as ${DESTINATION_DIR}/${FILE_PREFIX}.pom.asc"
183+
exit 1
184+
fi
185+
186+
# Compute hashes for the pom file
187+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}.pom.sha1"
188+
# Compute SHA-1 and extract only the hash
189+
shasum "${DESTINATION_DIR}/${FILE_PREFIX}.pom" | awk '{print $1}' > "$OUTPUT_FILE"
190+
# sha256
191+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}.pom.sha256"
192+
shasum -a 256 "${DESTINATION_DIR}/${FILE_PREFIX}.pom" | awk '{print $1}' > "$OUTPUT_FILE"
193+
# sha512
194+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}.pom.sha512"
195+
shasum -a 512 "${DESTINATION_DIR}/${FILE_PREFIX}.pom" | awk '{print $1}' > "$OUTPUT_FILE"
196+
# md5
197+
OUTPUT_FILE="${DESTINATION_DIR}/${FILE_PREFIX}.pom.md5"
198+
md5sum "${DESTINATION_DIR}/${FILE_PREFIX}.pom" | awk '{print $1}' > "$OUTPUT_FILE"
199+
200+
# Force remove recursively all the .DS_Store files that might have been copied
201+
find "io/" -name ".DS_Store" -type f -delete
202+
# Finally zip the io/ directory and save it in current directory as ${FILE_PREFIX}.zip
203+
zip -r ${FILE_PREFIX}.zip "io"
204+
205+
# Test if the zip file was created
206+
if [ -f "${FILE_PREFIX}.zip" ]; then
207+
echo "Zip file created successfully: ${FILE_PREFIX}.zip"
208+
else
209+
echo "Failed to create zip file: ${FILE_PREFIX}.zip"
210+
exit 1
211+
fi
212+
213+
# Copy the zip file to the destination directory to inspect
214+
cp ${FILE_PREFIX}.zip ../

.maven/maven-publish.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
## set variables/constants required by the script
4+
# The current tag of github's branch
5+
# Bail out if CURRENT_TAG is not set
6+
if [ -z "$CURRENT_TAG" ]; then
7+
echo "Error: CURRENT_TAG is not set. This script requires a tag to be set."
8+
exit 1
9+
fi
10+
11+
# Check the MAVEN_USERNAME and MAVEN_PASSWORD are set
12+
if [ -z "$MAVEN_USERNAME" ]; then
13+
echo "Error: MAVEN_USERNAME is not set. This script requires a username to be set."
14+
exit 1
15+
fi
16+
17+
if [ -z "$MAVEN_PASSWORD" ]; then
18+
echo "Error: MAVEN_PASSWORD is not set. This script requires a password to be set."
19+
exit 1
20+
fi
21+
22+
# The body artifact name
23+
BODY_ARTIFACT="service.httpsurlconn-${CURRENT_TAG}.zip"
24+
25+
# The username:password for the maven repository
26+
MAVEN_CREDENTIALS=$(printf "${MAVEN_USERNAME}:${MAVEN_PASSWORD}" | base64)
27+
# Publish the body artifact
28+
curl --request POST \
29+
--verbose \
30+
--header "Authorization: Bearer ${MAVEN_CREDENTIALS}" \
31+
--form "bundle=@${BODY_ARTIFACT}" \
32+
"https://central.sonatype.com/api/v1/publisher/upload?publishingType=USER_MANAGED&name=service.httpsurlconn"

approov-service/build.gradle

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ repositories {
77
mavenCentral()
88
google()
99
jcenter()
10-
maven { url "https://jitpack.io" }
1110
}
1211

1312
group = 'com.github.approov'
@@ -34,18 +33,6 @@ android {
3433

3534
dependencies {
3635
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
37-
implementation 'com.github.approov:approov-android-sdk:3.2.2'
36+
implementation 'io.approov:approov-android-sdk:3.3.0'
3837
}
3938

40-
afterEvaluate {
41-
publishing {
42-
publications {
43-
release(MavenPublication) {
44-
from components.release
45-
groupId = 'com.github.approov'
46-
artifactId = 'approov-service-httpsurlconn'
47-
version = '3.2.2'
48-
}
49-
}
50-
}
51-
}

approov-service/docs/javadoc.jar

657 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)