Workflow file for this run
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: On release publish to maven central | |
| on: | |
| release: | |
| types: [published] | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| - uses: gradle/actions/setup-gradle@v4 | |
| - name: Extract Default Project Version from Gradle | |
| run: | | |
| echo "DEFAULT_PROJECT_VERSION=$(./gradlew properties -q | grep '^version:' | awk '{print $2}')" >> $GITHUB_ENV | |
| - name: Ensure the default project version matches the tag name (the workflow will fail if they don't match) | |
| env: | |
| RELEASE_TAG: ${{ github.event.release.tag_name }} | |
| run: | | |
| if [ "$RELEASE_TAG" != "$DEFAULT_PROJECT_VERSION" ]; then | |
| echo "Error: Tag name ($RELEASE_TAG) does not match the project version ($DEFAULT_PROJECT_VERSION)" | |
| exit 1 | |
| fi | |
| - name: If this is a prerelease, append -SNAPSHOT to the version | |
| run: | | |
| if ${{ github.event.release.prerelease }}; then | |
| VERSION="${DEFAULT_PROJECT_VERSION}-SNAPSHOT" | |
| else | |
| VERSION=$DEFAULT_PROJECT_VERSION | |
| fi | |
| echo "PROJECT_VERSION=$VERSION" >> $GITHUB_ENV | |
| - name: Build the artifact | |
| run: ./gradlew build | |
| - name: Publish to Maven Central (Snapshot or Release) | |
| run: | | |
| if [[ "${PROJECT_VERSION}" == *"-SNAPSHOT" ]]; then | |
| echo "Publishing SNAPSHOT version: ${PROJECT_VERSION}" | |
| ./gradlew publish --info --stacktrace | |
| else | |
| echo "Publishing RELEASE version: ${PROJECT_VERSION}" | |
| ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --info --stacktrace | |
| fi | |
| env: | |
| ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_SECRET_KEY }} | |
| ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_PASSPHRASE }} | |
| ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.OSSRH_USERNAME }} | |
| ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.OSSRH_PASSWORD }} | |
| - name: Publish to GitHub Packages | |
| run: ./gradlew publishMavenJavaPublicationToGitHubPackagesRepository | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |