[Android] Create a script to deploy the artifacts to Maven Central

Nicolas Pomepuy git at videolan.org
Tue Apr 13 07:27:03 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Apr 12 09:54:22 2021 +0200| [8815b79668fb1c4301d073f708ef41338e1b1e4a] | committer: Nicolas Pomepuy

Create a script to deploy the artifacts to Maven Central

Fixes #1640

> https://code.videolan.org/videolan/vlc-android/commit/8815b79668fb1c4301d073f708ef41338e1b1e4a
---

 buildsystem/maven/README.md                 |  61 ++++++++++++++
 buildsystem/maven/deploy-to-mavencentral.sh | 126 ++++++++++++++++++++++++++++
 buildsystem/maven/images/nexus.png          | Bin 0 -> 107570 bytes
 3 files changed, 187 insertions(+)

diff --git a/buildsystem/maven/README.md b/buildsystem/maven/README.md
new file mode 100644
index 000000000..09ee80f2e
--- /dev/null
+++ b/buildsystem/maven/README.md
@@ -0,0 +1,61 @@
+# Deploy artifacts
+
+## Prerequisites
+
+### Signing
+
+Use [this guide](https://github.com/drduh/YubiKey-Guide#configure-smartcard) to setup a yubikey with the VideoLAN maven signing key. The key id is `e8f8f982a0cd726f020ced90f4b3cd9a1faeefe8` 
+
+### Utilities
+
+Apache Maven is needed.
+
+`sudo apt install maven`
+
+### Sonatype
+
+You have to get Sonatype credentials. To ask for it, you will have to create a JIRA account and ask to be added [here](https://issues.sonatype.org/browse/OSSRH-65611)
+
+## Generate the artifacts
+
+Create a git tag named `libvlc-[libvlc-version]`. The CI will generate the libvlc and medialibrary artifacts and the debug symbols. All of these files will be available to download in a zip file named `dbg.zip` attached to the pipeline.
+
+Copy the file to this directory (`buildsystem/maven`)
+
+## Usage
+
+You just have to plug your yubikey and run the script
+
+`./deploy-to-mavencentral.sh`
+
+The script will do the following actions:
+
+- check if the zip exists
+- unzip it
+- look for the artifact versions
+- let you confirm if it's all good
+- let you enter your Sonatype credentials
+- create a new `settings.xml` file in the current directory. /!\ If the script fails after this point, make sure you delete this file to avoid having your credentials exposed /!\
+- sign and deploy the artifacts with Apache Maven
+- delete the `settings.xml` file
+
+### Release artifacts
+
+Once the artifacts have been deployed, you still need to release the repository.
+
+- Go to the [Nexus Repository Manager](https://s01.oss.sonatype.org/)
+- Login with your credentials
+- Navigate to `Build Promotion` / `Staging Repositories`
+- Select the `org.videolan` repository
+
+![Nexus Repository Manager interface](images/nexus.png)
+
+- Close it
+- Wait for it to be closed
+- Release it
+
+When it's done, the artifacts should be available in Maven Central within a few minutes. To verify, you can navigate to:
+- [libvlc](https://repo1.maven.org/maven2/org/videolan/android/libvlc-all/)
+- [medialibrary](https://repo1.maven.org/maven2/org/videolan/android/medialibrary-all/)
+
+After a few hours, they should also be available in the [Maven Search Engine](https://search.maven.org/search?q=g:org.videolan.android)
\ No newline at end of file
diff --git a/buildsystem/maven/deploy-to-mavencentral.sh b/buildsystem/maven/deploy-to-mavencentral.sh
new file mode 100755
index 000000000..cbd4e71e1
--- /dev/null
+++ b/buildsystem/maven/deploy-to-mavencentral.sh
@@ -0,0 +1,126 @@
+#!/bin/bash
+
+set -euo pipefail
+
+# Constants
+OUTPUT_DIR="artifacts"
+MEDIALIB_VERSION=""
+LIBVLC_VERSION=""
+
+# Utilities
+function escape_pom() {
+  echo "$1" | sed 's#/#\\/#g' | tr '\n' '@'
+}
+
+function xml_encode() {
+  echo $1 | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g'
+}
+
+function blue() {
+  echo -e "\033[1;34m===================\n$1\n===================\033[0m"
+}
+
+function purple() {
+  echo -e "\033[1;35m$1\033[0m"
+}
+
+function red() {
+  echo -e "\033[1;31m===================\n$1\n===================\033[0m"
+}
+
+#START
+
+rm -rf $OUTPUT_DIR
+mkdir -p $OUTPUT_DIR
+
+blue "File management"
+#check files
+if test -f "dbg.zip"; then
+  blue "File exists. Unzipping"
+  unzip "dbg.zip" -d $OUTPUT_DIR
+else
+  red "Cannot find the dbg.zip file."
+  exit 1
+fi
+
+blue "Files extracted"
+
+blue "Looking for artifacts and versions"
+
+if test -d "$OUTPUT_DIR/aars/repository/org/videolan/android/medialibrary-all"; then
+  MEDIALIB_VERSION=$(ls -tUd "$OUTPUT_DIR/aars/repository/org/videolan/android/medialibrary-all/"*/ | xargs basename)
+else
+  red "Cannot find the medialibrary directory"
+fi
+if test -d "$OUTPUT_DIR/aars/repository/org/videolan/android/libvlc-all"; then
+  LIBVLC_VERSION=$(ls -tUd "$OUTPUT_DIR/aars/repository/org/videolan/android/libvlc-all/"*/ | xargs basename)
+else
+  red "Cannot find the libvlc directory"
+fi
+
+purple "The following versions have been found.\nlibvlc: $LIBVLC_VERSION\nmedialibrary: $MEDIALIB_VERSION."
+read -sp "Continue: y/N" -n 1 -r
+echo
+
+if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+  [[ "$0" == "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
+fi
+
+blue "Ready to deploy"
+
+read -p 'Enter your sonatype username: ' username
+echo
+SONATYPE_USERNAME=$(xml_encode $username)
+read -sp 'Enter your sonatype password: ' pass
+echo
+SONATYPE_PASSWORD=$(xml_encode $pass)
+
+blue "Setup Maven credentials"
+echo "<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
+  xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd\">
+  <servers>
+    <server>
+      <id>ossrh</id>
+      <username>$SONATYPE_USERNAME</username>
+      <password>$SONATYPE_PASSWORD</password>
+    </server>
+  </servers>
+</settings>" >settings.xml
+
+if [ -z "$LIBVLC_VERSION" ]; then
+  purple "No version for libvlc. Skipping"
+else
+  BASE_DIR="$OUTPUT_DIR/aars/repository/org/videolan/android/libvlc-all/$LIBVLC_VERSION"
+  blue "Deploying $BASE_DIR"
+
+  mvn gpg:sign-and-deploy-file \
+    --settings settings.xml \
+    -DpomFile=$BASE_DIR/libvlc-all-$LIBVLC_VERSION.pom \
+    -Dfile=$BASE_DIR/libvlc-all-$LIBVLC_VERSION.aar \
+    -Dsources=$BASE_DIR/libvlc-all-$LIBVLC_VERSION-sources.jar \
+    -Djavadoc=$BASE_DIR/libvlc-all-$LIBVLC_VERSION-javadoc.jar \
+    -Durl="https://s01.oss.sonatype.org/service/local/staging/deploy/maven2" \
+    -DgroupId=org.videolan.android \
+    -Dgpg.keyname=e8f8f982a0cd726f020ced90f4b3cd9a1faeefe8 \
+    -DrepositoryId=ossrh
+fi
+
+if [ -z "$MEDIALIB_VERSION" ]; then
+  purple "No version for medialibrary Skipping"
+else
+  BASE_DIR="$OUTPUT_DIR/aars/repository/org/videolan/android/medialibrary-all/$MEDIALIB_VERSION"
+  blue "Deploying $BASE_DIR"
+
+  mvn gpg:sign-and-deploy-file \
+    --settings settings.xml \
+    -DpomFile=$BASE_DIR/medialibrary-all-$MEDIALIB_VERSION.pom \
+    -Dfile=$BASE_DIR/medialibrary-all-$MEDIALIB_VERSION.aar \
+    -Dsources=$BASE_DIR/medialibrary-all-$MEDIALIB_VERSION-sources.jar \
+    -Djavadoc=$BASE_DIR/medialibrary-all-$MEDIALIB_VERSION-javadoc.jar \
+    -Durl="https://s01.oss.sonatype.org/service/local/staging/deploy/maven2" \
+    -DgroupId=org.videolan.android \
+    -Dgpg.keyname=e8f8f982a0cd726f020ced90f4b3cd9a1faeefe8 \
+    -DrepositoryId=ossrh
+fi
+
+rm settings.xml
diff --git a/buildsystem/maven/images/nexus.png b/buildsystem/maven/images/nexus.png
new file mode 100644
index 000000000..773a22fdf
Binary files /dev/null and b/buildsystem/maven/images/nexus.png differ



More information about the Android mailing list