Skip to content

KMP RUN Publish Android #58

KMP RUN Publish Android

KMP RUN Publish Android #58

name: KMP RUN Publish Android
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
type: choice
options: [rc, prod]
env:
JAVA_VERSION: "17"
permissions:
contents: write
packages: write
concurrency:
group: kmp-android-publish-${{ github.ref }}-${{ github.event.inputs.environment }}
cancel-in-progress: true
jobs:
release-android-sdk:
runs-on: macos-15
steps:
- name: 🧾 Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: ☕ Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
- name: 🛠️ Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Print tool versions
run: |
java -version
./gradlew --version
- name: 📝 Get version from gradle.properties
shell: bash
run: |
set -euo pipefail
VERSION=$(grep '^PUBLISH_VERSION=' gradle.properties | cut -d'=' -f2 | tr -d '[:space:]')
if [ -z "$VERSION" ]; then echo "PUBLISH_VERSION missing in gradle.properties"; exit 1; fi
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
echo "Found version: $VERSION"
- name: 🔧 Set publication name and POM file name
shell: bash
run: |
set -euo pipefail
if [ "${{ github.event.inputs.environment }}" = "rc" ]; then
PUB_NAME="rc"; EFFECTIVE="${RELEASE_VERSION}-rc"
else
PUB_NAME="release"; EFFECTIVE="${RELEASE_VERSION}"
fi
echo "PUBLICATION_NAME=${PUB_NAME}" >> "$GITHUB_ENV"
echo "EFFECTIVE_VERSION=${EFFECTIVE}" >> "$GITHUB_ENV"
echo "POM_FILE_NAME=velocityexchangeverifiers-${EFFECTIVE}.pom" >> "$GITHUB_ENV"
echo "Publication: ${PUB_NAME}"
echo "Effective version: ${EFFECTIVE}"
echo "POM file: velocityexchangeverifiers-${EFFECTIVE}.pom"
- name: 🧪 Build AAR + Sources + Javadoc
shell: bash
run: |
set -euo pipefail
./gradlew --no-daemon --warning-mode=all \
:velocityexchangeverifiers:clean \
:velocityexchangeverifiers:assembleAndroid \
-PprojectVersion=${RELEASE_VERSION} \
-Pprerelease=${{ github.event.inputs.environment == 'rc' }} \
--stacktrace
- name: ✅ Verify expected artifacts exist
run: |
./gradlew --no-daemon :velocityexchangeverifiers:verifyExpectedArtifactsExist \
-PprojectVersion=${RELEASE_VERSION} \
-Pprerelease=${{ github.event.inputs.environment == 'rc' }}
- name: 🧹 Clean staging root
shell: bash
working-directory: velocityexchangeverifiers
run: |
set -euo pipefail
rm -rf target/staging-deploy/io/velocitycareerlabs/velocityexchangeverifiers
mkdir -p target/staging-deploy/io/velocitycareerlabs/velocityexchangeverifiers
- name: 📦 Stage Artifacts
run: |
./gradlew --no-daemon :velocityexchangeverifiers:stageArtifacts \
-PprojectVersion=${RELEASE_VERSION} \
-Pprerelease=${{ github.event.inputs.environment == 'rc' }}
- name: 🧪 Generate POM File
shell: bash
run: |
set -euo pipefail
./gradlew --no-daemon :velocityexchangeverifiers:generatePomFileFor${{ env.PUBLICATION_NAME }}Publication \
-PprojectVersion=${RELEASE_VERSION} -Pprerelease=${{ github.event.inputs.environment == 'rc' }}
mkdir -p velocityexchangeverifiers/target/staging-deploy/io/velocitycareerlabs/velocityexchangeverifiers/${{ env.EFFECTIVE_VERSION }}
cp velocityexchangeverifiers/build/publications/${{ env.PUBLICATION_NAME }}/pom-default.xml \
velocityexchangeverifiers/target/staging-deploy/io/velocitycareerlabs/velocityexchangeverifiers/${{ env.EFFECTIVE_VERSION }}/${{ env.POM_FILE_NAME }}
- name: 📂 List staged artifacts
working-directory: velocityexchangeverifiers
run: ls -R target/staging-deploy
- name: 🔒 Guard staged contents
shell: bash
working-directory: velocityexchangeverifiers
run: |
set -euo pipefail
BASE=target/staging-deploy/io/velocitycareerlabs/velocityexchangeverifiers
echo "Contents of $BASE:"; ls -1 "$BASE" || true
for d in "$BASE"/*; do
[ -d "$d" ] || continue
bn=$(basename "$d")
if [ "$bn" != "${EFFECTIVE_VERSION}" ]; then
echo "Unexpected version dir present: $bn"; exit 1
fi
done
ls -1 "$BASE/${EFFECTIVE_VERSION}"
- name: 🔎 Verify POM version matches EFFECTIVE_VERSION
shell: bash
working-directory: velocityexchangeverifiers
run: |
set -euo pipefail
POM=target/staging-deploy/io/velocitycareerlabs/velocityexchangeverifiers/${EFFECTIVE_VERSION}/velocityexchangeverifiers-${EFFECTIVE_VERSION}.pom
grep -q "<version>${EFFECTIVE_VERSION}</version>" "$POM" || { echo "POM version mismatch"; exit 1; }
- name: 📜 Show staged file names
shell: bash
working-directory: velocityexchangeverifiers
run: |
set -euo pipefail
dir=target/staging-deploy/io/velocitycareerlabs/velocityexchangeverifiers/${EFFECTIVE_VERSION}
ls -l "$dir"
- name: ⬆️ Upload staged bundle (debug)
if: always()
uses: actions/upload-artifact@v4
with:
name: staged-${{ env.EFFECTIVE_VERSION }}
path: velocityexchangeverifiers/target/staging-deploy
- name: Validate staged files
shell: bash
working-directory: velocityexchangeverifiers
run: |
set -euo pipefail
dir=target/staging-deploy/io/velocitycareerlabs/velocityexchangeverifiers/${EFFECTIVE_VERSION}
echo "📂 Validating contents of: $dir"
ls -l "$dir" || true
missing=0
check() {
local f="$1"
if [[ -f "$dir/$f" ]]; then
echo "✅ Found $f"
else
echo "❌ Missing $f"
missing=1
fi
}
check "velocityexchangeverifiers-${EFFECTIVE_VERSION}.pom"
check "velocityexchangeverifiers-${EFFECTIVE_VERSION}.aar"
check "velocityexchangeverifiers-${EFFECTIVE_VERSION}-sources.jar"
check "velocityexchangeverifiers-${EFFECTIVE_VERSION}-javadoc.jar"
# Print a quick hint if jars are missing
if [[ $missing -ne 0 ]]; then
echo "🔎 Debugging hints:"
echo "→ Check Gradle outputs:"
echo " • build/libs:"
ls -l build/libs || true
echo " • build/outputs/aar:"
ls -l build/outputs/aar || true
exit 1
fi
- name: 🚀 Run JReleaser deploy
uses: jreleaser/release-action@v2
with:
version: 1.19.0
arguments: >
deploy
--config-file=velocityexchangeverifiers/jreleaser.template.yml
--debug
env:
JRELEASER_PROJECT_JAVA_ARTIFACT_ID: velocityexchangeverifiers
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_TOKEN_USERNAME }}
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_TOKEN_PASSWORD }}
JRELEASER_MAVENCENTRAL_STAGE: ${{ secrets.MAVEN_CENTRAL_STAGING_PROFILE_ID }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_PROJECT_VERSION: ${{ env.EFFECTIVE_VERSION }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_PRIVATE_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.MAVEN_CENTRAL_SIGNING_PASSWORD }}
JRELEASER_TAG_NAME: ${{ env.EFFECTIVE_VERSION }}
JRELEASER_RELEASE_NAME: ${{ github.event.inputs.environment == 'rc' && 'Release Candidate ' || '' }}${{ env.EFFECTIVE_VERSION }}
JRELEASER_PRERELEASE_PATTERN: ${{ github.event.inputs.environment == 'rc' && env.EFFECTIVE_VERSION || 'OFF' }}