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