Publish to Maven Central #1
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: | |
| inputs: | |
| version: | |
| description: "Version to publish (e.g. 0.1.0, without the 'v')" | |
| required: true | |
| type: string | |
| release: | |
| description: "Publish and release. Off = upload to the Portal and stop at VALIDATED for manual review." | |
| required: true | |
| type: boolean | |
| default: false | |
| jobs: | |
| guard: | |
| name: Require green main.yml for this commit | |
| runs-on: ubuntu-latest | |
| permissions: | |
| actions: read | |
| steps: | |
| - name: Check latest main.yml conclusion | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| conclusion=$(gh api \ | |
| "repos/${{ github.repository }}/actions/workflows/main.yml/runs?head_sha=${{ github.sha }}&status=completed" \ | |
| --jq '.workflow_runs[0].conclusion // "missing"') | |
| echo "main.yml conclusion for ${{ github.sha }}: $conclusion" | |
| if [ "$conclusion" != "success" ]; then | |
| echo "::error::main.yml is not green for ${{ github.sha }} (got: $conclusion). Run publish from a commit on main whose CI passed." | |
| exit 1 | |
| fi | |
| publish: | |
| name: Publish to Maven Central | |
| needs: guard | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: maven-central | |
| url: https://central.sonatype.com/artifact/app.marketdata/marketdata-sdk-java | |
| env: | |
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | |
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "17" | |
| - name: Set up Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| - name: Build and test | |
| run: ./gradlew clean build -PsdkVersion=${{ inputs.version }} | |
| - name: Upload to Portal (validate only) | |
| if: ${{ !inputs.release }} | |
| run: ./gradlew publishToMavenCentral -PsdkVersion=${{ inputs.version }} | |
| - name: Publish and release | |
| if: ${{ inputs.release }} | |
| run: ./gradlew publishAndReleaseToMavenCentral -PsdkVersion=${{ inputs.version }} |