Publish to Maven Central #14
This file contains hidden or 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
| name: Publish to Maven Central | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| env: | |
| OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} | |
| OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} | |
| GPR_USER: ${{ secrets.GPR_USER }} | |
| GPR_TOKEN: ${{ secrets.GPR_TOKEN }} | |
| NDK_VERSION: 27.3.13750724 | |
| ANDROID_SDK_ROOT: /usr/local/lib/android/sdk | |
| ANDROID_HOME: /usr/local/lib/android/sdk | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Write gradle.properties | |
| run: | | |
| { | |
| echo "android.ndkVersion=${NDK_VERSION}" | |
| } >> gradle.properties | |
| - name: Set NDK environment | |
| run: | | |
| echo "ANDROID_NDK_ROOT=/usr/local/lib/android/sdk/ndk/${NDK_VERSION}" >> $GITHUB_ENV | |
| echo "NDK_VERSION=${NDK_VERSION}" >> $GITHUB_ENV | |
| - name: Set up Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: '17' | |
| cache: 'gradle' | |
| - name: Import GPG key | |
| run: | | |
| echo "${{ secrets.GPG_PRIVATE_KEY }}" | base64 --decode > "$HOME/secring.gpg" | |
| gpg --batch --import "$HOME/secring.gpg" | |
| - name: Install Android NDK $NDK_VERSION | |
| uses: android-actions/setup-android@v3 | |
| with: | |
| packages: "build-tools;36.0.0 ndk;${{ env.NDK_VERSION }} platform-tools platforms;android-35" | |
| - name: Fetch HERE SDK mock artifact | |
| run: | | |
| mkdir -p libs | |
| target_path="libs/heresdk-explore-mock-4.23.2.0.210004.jar" | |
| echo "Downloading HERE SDK mock artifact to $target_path" | |
| curl --fail --show-error --silent --location \ | |
| -u "$GPR_USER:$GPR_TOKEN" \ | |
| -o "$target_path" \ | |
| "https://raw.githubusercontent.com/MapConductor/here-sdk-mocks/main/heresdk-explore-mock-4.23.2.0.210004.jar" | |
| if [ ! -s "$target_path" ]; then | |
| echo "Failed to download HERE SDK mock artifact" | |
| exit 1 | |
| fi | |
| - name: Determine modules to publish and deploy to Maven Central | |
| env: | |
| ORG_GRADLE_PROJECT_ossrh_username: ${{ secrets.OSSRH_USERNAME }} | |
| ORG_GRADLE_PROJECT_ossrh_password: ${{ secrets.OSSRH_PASSWORD }} | |
| ORG_GRADLE_PROJECT_signing_keyId: ${{ secrets.GPG_KEY_ID }} | |
| ORG_GRADLE_PROJECT_signing_password: ${{ secrets.GPG_PASSPHRASE }} | |
| ORG_GRADLE_PROJECT_signing_secretKeyRingFile: ${{ format('{0}/secring.gpg', env.HOME) }} | |
| run: | | |
| # Disable -e from the default shell so we can handle failures explicitly. | |
| # Keep -u (undefined vars) and pipefail (pipeline errors). | |
| set +e | |
| set -uo pipefail | |
| PUBLISHABLE_MODULES=( | |
| mapconductor-icons | |
| mapconductor-marker-native-strategy | |
| mapconductor-marker-strategy | |
| mapconductor-bom | |
| mapconductor-core | |
| mapconductor-for-arcgis | |
| mapconductor-for-googlemaps | |
| mapconductor-for-here | |
| mapconductor-for-mapbox | |
| ) | |
| GROUP_ID="com.mapconductor" | |
| GROUP_PATH="${GROUP_ID//./\/}" | |
| publish_tasks=() | |
| for module in "${PUBLISHABLE_MODULES[@]}"; do | |
| props_file="$module/gradle.properties" | |
| if [[ ! -f "$props_file" ]]; then | |
| echo "Skipping $module: gradle.properties not found" | |
| continue | |
| fi | |
| local_version=$(grep '^libraryVersion=' "$props_file" | cut -d'=' -f2 | tr -d '\r') | |
| if [[ -z "$local_version" ]]; then | |
| echo "Skipping $module: libraryVersion not found" | |
| continue | |
| fi | |
| artifactId=$(grep -m1 'libraryArtifactId' "$module/build.gradle.kts" | sed -E 's/.*\"(.+)\".*/\1/' | tr -d '\r') | |
| if [[ -z "$artifactId" ]]; then | |
| echo "Skipping $module: libraryArtifactId not found" | |
| continue | |
| fi | |
| metadata_url="https://repo1.maven.org/maven2/${GROUP_PATH}/${artifactId}/maven-metadata.xml" | |
| echo "Checking ${GROUP_ID}:${artifactId} (local version ${local_version})" | |
| remote_version="" | |
| if curl -fsSL "$metadata_url" -o metadata.xml; then | |
| # Prefer <release>, fall back to last <version> | |
| remote_version=$(grep '<release>' metadata.xml | head -n1 | sed -E 's/.*<release>([^<]+)<\/release>.*/\1/' || true) | |
| if [[ -z "$remote_version" ]]; then | |
| remote_version=$(grep '<version>' metadata.xml | sed -E 's/.*<version>([^<]+)<\/version>.*/\1/' | tail -n1 || true) | |
| fi | |
| rm -f metadata.xml | |
| else | |
| echo " No metadata found on Maven Central (likely not published yet)." | |
| fi | |
| if [[ -n "$remote_version" && "$local_version" == "$remote_version" ]]; then | |
| echo " Already published (remote version ${remote_version}); skipping." | |
| else | |
| echo " Will publish local version ${local_version} (remote='${remote_version}')." | |
| publish_tasks+=(":${module}:publishReleasePublicationToCentralPortal") | |
| fi | |
| done | |
| # If no modules need publishing, exit successfully | |
| if [[ "${#publish_tasks[@]}" -eq 0 ]]; then | |
| echo "No modules require publishing." | |
| exit 0 | |
| fi | |
| echo "Publishing modules with tasks: ${publish_tasks[*]}" | |
| ./gradlew --no-daemon "${publish_tasks[@]}" | |
| gradle_exit=$? | |
| if [[ $gradle_exit -ne 0 ]]; then | |
| echo "Gradle publish failed with exit code $gradle_exit" | |
| exit $gradle_exit | |
| fi |