Skip to content

Commit

Permalink
Add script to publish on mavenCentral
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g committed Aug 14, 2024
1 parent 4eed248 commit 8c536ed
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ dependencies {

}

def releaseGroupId = 'org.unifiedpush.android'
def releaseArtifactId = 'foss_embedded_fcm_distributor'
def releaseVersion = '1.0.0'

tasks.register('printArtifactId') {
group 'Artifact Info'
doLast {
println("artifact=$releaseGroupId:$releaseArtifactId")
}
}

tasks.register("printVersion") {
group 'Artifact Info'
doLast {
println("version=$releaseVersion")
}
}


// jitpack build
afterEvaluate {
publishing {
Expand All @@ -58,9 +77,9 @@ afterEvaluate {
from components.release

// You can then customize attributes of the publication as shown below.
groupId = 'org.unifiedpush.android'
artifactId = 'android-foss_embedded_fcm_distributor'
version = '1.0.0-beta5'
groupId = releaseGroupId
artifactId = releaseArtifactId
version = releaseVersion
}
}
}
Expand Down
70 changes: 70 additions & 0 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/sh

NORMAL=$'\e[0m'
GREEN=$(tput setaf 2)
RED=$(tput setaf 1)

## Read details

ARTIFACT_ID=$( ./gradlew printArtifactId | sed -n '/^artifact=/ s/.*=//p' )
RELEASE_VERSION=$( ./gradlew printVersion | sed -n '/^version=/ s/.*=//p' )
DIR="$( echo "${ARTIFACT_ID:?}" | sed 's-[.:]-/-g' )/${RELEASE_VERSION:?}"
TOKEN_GPG_FILE="$HOME/.password-store/mavenCentral/token.gpg"

## Confirm

echo "You are going to release ${GREEN}${ARTIFACT_ID:?}${NORMAL}:${RED}${RELEASE_VERSION:?}${NORMAL}"
echo "Type ${RED}${RELEASE_VERSION}${NORMAL} to confirm:"
read CONFIRMATION
if [ "${RELEASE_VERSION:?}" != "${CONFIRMATION}" ]; then
echo "Aborting."
exit 1
fi
echo "Confirmed."

## Get token

if [ ! -f $TOKEN_GPG_FILE ]; then
echo "[!] $TOKEN_GPG_FILE not found. Aborting."
exit 1
fi
TOKEN=$(gpg --decrypt $TOKEN_GPG_FILE)

if [ $? -ne 0 ]; then
echo "An error occured while decrypting the token. Aborting."
exit 1
fi

## Build

rm -rf ~/.m2/repository/${DIR:?}
./gradlew publishReleasePublicationToMavenLocal

## Sign

cd ~/.m2/repository/
for file in ${DIR:?}/*; do
echo "[+] Signing $file"
sha1sum $file > $file.sha1
md5sum $file > $file.md5
gpg -ab $file
done

## Zip

ZIP_FILE="${ARTIFACT_ID:?}:${RELEASE_VERSION:?}.zip "

zip -r ${ZIP_FILE:?} ${DIR:?}/

## Upload

echo "Do you want to upload ${ZIP_FILE} ? Type ${RED}yes${NORMAL}"

read CONFIRMATION

if [ "$CONFIRMATION" = "yes" ]; then
curl --request POST \
--header "Authorization: Bearer ${TOKEN:?}" \
--form bundle=@${ZIP_FILE:?} \
https://central.sonatype.com/api/v1/publisher/upload
fi

0 comments on commit 8c536ed

Please sign in to comment.