Created
April 15, 2021 11:57
-
-
Save caiofaustino/314075ee3d3bef5da16c69dd3257f954 to your computer and use it in GitHub Desktop.
Script to upload artifacts to Maven
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Starting upload script" | |
sonatype_user="<your_user>" | |
sonatype_password="<your_password>" | |
# Path where the files are located | |
path=$1 | |
# Path inside the repo if not root path, (com/package/group) | |
repo_path_base=$2 | |
echo "path: $path" | |
echo "repo_path_base: $repo_path_base" | |
if [ -d "$path" ]; then | |
# Take action if $DIR exists. # | |
echo "Path exists!" | |
# Your URL could be different if you have a new account | |
MAVEN_CENTRAL_STAGINGURL="https://oss.sonatype.org/service/local/staging/deploy/maven2" | |
MAVEN_CENTRAL_REPOID="ossrh" | |
for file_path in $path/*; do | |
#If is a file (with extension) | |
if [[ $file_path == *"."[a-z][a-z][a-z] ]]; then | |
if [[ $file_path == *".pom" ]]; then | |
echo "Is POM fille" | |
# Find POM file path | |
pom_file=$file_path | |
# Loop files again | |
for file in $path/*; do | |
if [[ $file == *".pom" ]]; then | |
echo "Ignoring POM file again" | |
elif [[ $file == *".aar" ]]; then | |
echo "Uploading AAR file." | |
(cd $path && mvn gpg:sign-and-deploy-file \ | |
-Durl=$MAVEN_CENTRAL_STAGINGURL \ | |
-DrepositoryId=$MAVEN_CENTRAL_REPOID \ | |
-DpomFile=$pom_file \ | |
-Dfile=$file) | |
echo "" | |
elif [[ $file == *"-javadoc.jar" ]]; then | |
echo "Uploading Javadoc file." | |
(cd $path && mvn gpg:sign-and-deploy-file \ | |
-Durl=$MAVEN_CENTRAL_STAGINGURL \ | |
-DrepositoryId=$MAVEN_CENTRAL_REPOID \ | |
-DpomFile=$pom_file \ | |
-Dfile=$file \ | |
-Dclassifier=javadoc) | |
echo "" | |
elif [[ $file == *"-sources.jar" ]]; then | |
echo "Uploading Sources file." | |
(cd $path && mvn gpg:sign-and-deploy-file \ | |
-Durl=$MAVEN_CENTRAL_STAGINGURL \ | |
-DrepositoryId=$MAVEN_CENTRAL_REPOID \ | |
-DpomFile=$pom_file \ | |
-Dfile=$file \ | |
-Dclassifier=sources) | |
echo "" | |
else | |
echo "UNEXPECTED FILE - $file" | |
echo "" | |
fi | |
done | |
fi | |
else | |
# If is a folder, call recursively | |
dir=$file_path | |
dir="$(basename $dir)" | |
echo "Starting script again with: $file_path" | |
echo $file_path | |
new_base="$repo_path_base/$dir" | |
echo $new_base | |
# CHANGE SCRIPT PATH HERE | |
/path/to/script/upload_artifacts.sh $file_path $new_base | |
fi | |
echo "" | |
done | |
else | |
echo "Path not found, please provide valid path as argument!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment