Skip to content

Publish to Maven Central and tag #5

Publish to Maven Central and tag

Publish to Maven Central and tag #5

name: Publish to Maven Central and tag
on:
workflow_dispatch:
permissions:
contents: write # Grants permission to push tags
jobs:
publish:
runs-on: ubuntu-latest
env:
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVENCENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVENCENTRAL_PASSWORD }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Extract version from build.gradle
id: get_version
run: |
VERSION=$(./gradlew -q printVersion)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Fail if snapshot version
run: |
if [[ "$VERSION" == *"-SNAPSHOT" ]]; then
echo "Snapshot versions are not published to Maven Central"
exit 1
fi
- name: Run tests
run: ./gradlew test
# The goal publishToMavenCentral just publishes to a staging area.
# The published artifacts must be released manually in the Maven Central Portal.
# We could use publishAndReleaseToMavenCentral for full automation.
- name: Build and publish to Maven Central
run: ./gradlew clean publishToMavenCentral
- name: Tag the commit with version
if: success()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag $VERSION
git push origin $VERSION