|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +publish_plugin_android () { |
| 4 | + PLUGIN_PATH=$1 |
| 5 | + if [ -d "$PLUGIN_PATH" ]; then |
| 6 | + # Android dir path |
| 7 | + ANDROID_PATH=$PLUGIN_PATH/android |
| 8 | + GRADLE_FILE=$ANDROID_PATH/build.gradle |
| 9 | + |
| 10 | + # Only try to publish if the directory contains a package.json and android package |
| 11 | + if test -f "$PLUGIN_PATH/package.json" && test -d "$ANDROID_PATH" && test -f "$GRADLE_FILE"; then |
| 12 | + PLUGIN_VERSION=$(grep '"version": ' "$PLUGIN_PATH"/package.json | awk '{print $2}' | tr -d '",') |
| 13 | + PLUGIN_NAME=$(grep '"name": ' "$PLUGIN_PATH"/package.json | awk '{print $2}' | tr -d '",') |
| 14 | + PLUGIN_NAME=${PLUGIN_NAME#@capacitor/} |
| 15 | + LOG_OUTPUT=./tmp/$PLUGIN_NAME.txt |
| 16 | + |
| 17 | + # Get latest plugin info from MavenCentral |
| 18 | + PLUGIN_PUBLISHED_URL="https://repo1.maven.org/maven2/com/capacitorjs/$PLUGIN_NAME/maven-metadata.xml" |
| 19 | + PLUGIN_PUBLISHED_DATA=$(curl -s $PLUGIN_PUBLISHED_URL) |
| 20 | + PLUGIN_PUBLISHED_VERSION="$(perl -ne 'print and last if s/.*<latest>(.*)<\/latest>.*/\1/;' <<< $PLUGIN_PUBLISHED_DATA)" |
| 21 | + |
| 22 | + if [[ $PLUGIN_VERSION == $PLUGIN_PUBLISHED_VERSION ]]; then |
| 23 | + printf %"s\n\n" "Duplicate: a published plugin $PLUGIN_NAME exists for version $PLUGIN_VERSION, skipping..." |
| 24 | + else |
| 25 | + # Make log dir if doesnt exist |
| 26 | + mkdir -p ./tmp |
| 27 | + |
| 28 | + printf %"s\n" "Attempting to build and publish plugin $PLUGIN_NAME for version $PLUGIN_VERSION to production..." |
| 29 | + |
| 30 | + # Export ENV variables used by Gradle for the plugin |
| 31 | + export PLUGIN_NAME |
| 32 | + export PLUGIN_VERSION |
| 33 | + export CAPACITOR_VERSION |
| 34 | + export CAP_PLUGIN_PUBLISH=true |
| 35 | + export PLUGIN_REPO="https://github.com/ionic-team/capacitor-keyboard" |
| 36 | + export PLUGIN_SCM="github.com:ionic-team/capacitor-keyboard" |
| 37 | + |
| 38 | + # Build and publish |
| 39 | + "$ANDROID_PATH"/gradlew clean build publishReleasePublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository --no-daemon --max-workers 1 -b "$ANDROID_PATH"/build.gradle -Pandroid.useAndroidX=true > $LOG_OUTPUT 2>&1 |
| 40 | + |
| 41 | + if grep --quiet "BUILD SUCCESSFUL" $LOG_OUTPUT; then |
| 42 | + printf %"s\n\n" "Success: $PLUGIN_NAME published to MavenCentral." |
| 43 | + else |
| 44 | + printf %"s\n\n" "Error publishing $PLUGIN_NAME, check $LOG_OUTPUT for more info! Manually review and release from the Central Portal may be necessary https://central.sonatype.com/publishing/deployments/" |
| 45 | + cat $LOG_OUTPUT |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | + fi |
| 49 | + else |
| 50 | + printf %"s\n\n" "$PLUGIN_PATH does not appear to be a plugin (has no package.json file or Android package), skipping..." |
| 51 | + fi |
| 52 | + fi |
| 53 | +} |
| 54 | + |
| 55 | +# Get latest com.capacitorjs:core XML version info |
| 56 | +CAPACITOR_PUBLISHED_URL="https://repo1.maven.org/maven2/com/capacitorjs/core/maven-metadata.xml" |
| 57 | +CAPACITOR_PUBLISHED_DATA=$(curl -s $CAPACITOR_PUBLISHED_URL) |
| 58 | +CAPACITOR_PUBLISHED_VERSION="$(perl -ne 'print and last if s/.*<latest>(.*)<\/latest>.*/\1/;' <<< $CAPACITOR_PUBLISHED_DATA)" |
| 59 | + |
| 60 | +printf %"s\n" "The latest published Android library version of Capacitor Core is $CAPACITOR_PUBLISHED_VERSION in MavenCentral." |
| 61 | + |
| 62 | +# Determine Capacitor Version to use as gradle dependency. |
| 63 | +STABLE_PART=$(echo "$CAPACITOR_PUBLISHED_VERSION" | cut -d'-' -f1) |
| 64 | +IFS='.' read -r MAJOR MINOR PATCH <<< "$STABLE_PART" |
| 65 | +if [[ "$CAPACITOR_PUBLISHED_VERSION" == *"-"* ]]; then |
| 66 | + # prerelease - go one major lower (latest stable major), but also allow next upcoming major |
| 67 | + PREV_MAJOR=$((MAJOR - 1)) |
| 68 | + NEXT_MAJOR=$((MAJOR + 1)) |
| 69 | + CAPACITOR_VERSION="[$PREV_MAJOR.0,$NEXT_MAJOR.0)" |
| 70 | +else |
| 71 | + # stable - current major range |
| 72 | + NEXT_MAJOR=$((MAJOR + 1)) |
| 73 | + CAPACITOR_VERSION="[$MAJOR.0,$NEXT_MAJOR.0)" |
| 74 | +fi |
| 75 | +printf %"s\n" "Publishing plugin with dependency on Capacitor version $CAPACITOR_VERSION" |
| 76 | + |
| 77 | +publish_plugin_android '.' |
0 commit comments