|
| 1 | +name: Publish to Maven Central |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + version: |
| 9 | + description: "Version to publish (e.g., 1.0.0)" |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +env: |
| 14 | + GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx4g -XX:+UseParallelGC" |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + publish: |
| 21 | + runs-on: macos-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Set up JDK 17 |
| 27 | + uses: actions/setup-java@v4 |
| 28 | + with: |
| 29 | + java-version: "17" |
| 30 | + distribution: "temurin" |
| 31 | + |
| 32 | + - name: Setup Gradle |
| 33 | + uses: gradle/gradle-build-action@v2 |
| 34 | + |
| 35 | + - name: Grant execute permission for gradlew |
| 36 | + run: chmod +x gradlew |
| 37 | + |
| 38 | + - name: Set version |
| 39 | + id: set_version |
| 40 | + run: | |
| 41 | + if [ "${{ github.event_name }}" = "release" ]; then |
| 42 | + VERSION="${{ github.event.release.tag_name }}" |
| 43 | + else |
| 44 | + VERSION="${{ github.event.inputs.version }}" |
| 45 | + fi |
| 46 | + # Trim leading 'v' if present (e.g., v1.2.3 -> 1.2.3) |
| 47 | + VERSION="${VERSION#v}" |
| 48 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 49 | + echo "ORG_GRADLE_PROJECT_openIapVersion=$VERSION" >> $GITHUB_ENV |
| 50 | +
|
| 51 | + - name: Build and test |
| 52 | + run: | |
| 53 | + ./gradlew :openiap:build --no-daemon --stacktrace |
| 54 | + ./gradlew :openiap:test --no-daemon --stacktrace |
| 55 | +
|
| 56 | + - name: Publish to Maven Central |
| 57 | + env: |
| 58 | + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} |
| 59 | + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} |
| 60 | + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }} |
| 61 | + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }} |
| 62 | + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} |
| 63 | + run: | |
| 64 | + ./gradlew :openiap:publishAndReleaseToMavenCentral --no-daemon --no-parallel --stacktrace |
| 65 | +
|
| 66 | + - name: Create GitHub Release (workflow_dispatch) |
| 67 | + if: github.event_name == 'workflow_dispatch' |
| 68 | + uses: softprops/action-gh-release@v1 |
| 69 | + with: |
| 70 | + tag_name: ${{ env.VERSION }} |
| 71 | + name: ${{ env.VERSION }} |
| 72 | + draft: false |
| 73 | + prerelease: false |
| 74 | + generate_release_notes: true |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + |
| 78 | + - name: Create release artifacts (workflow_dispatch) |
| 79 | + if: github.event_name == 'workflow_dispatch' |
| 80 | + run: | |
| 81 | + mkdir -p release-artifacts |
| 82 | + cp openiap/build/outputs/aar/*.aar release-artifacts/ || true |
| 83 | + cp openiap/build/libs/*.jar release-artifacts/ || true |
| 84 | + (cd release-artifacts && sha256sum * || shasum -a 256 *) > checksums.txt || true |
| 85 | + zip -r release-artifacts.zip release-artifacts/ |
| 86 | +
|
| 87 | + - name: Upload release artifacts (workflow_dispatch) |
| 88 | + if: github.event_name == 'workflow_dispatch' |
| 89 | + uses: softprops/action-gh-release@v1 |
| 90 | + with: |
| 91 | + files: ./release-artifacts.zip |
| 92 | + name: ${{ env.VERSION }} |
| 93 | + tag_name: ${{ env.VERSION }} |
| 94 | + env: |
| 95 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments