kotlin-sdk/.github/workflows/gradle-publish.yml
Konstantin Pavlov 60b7474d67
Update Gradle publish workflow: switch to published event, use `mac… (#259)
<!-- Provide a brief summary of your changes -->

## Motivation and Context

Align release workflow with the normal build workflow

## Changes

Update Gradle publish workflow: switch to `published` event, use
`mac…os-latest-xlarge`, and configure `JAVA_OPTS`.

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [x] CI update

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [ ] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [ ] My code follows the repository's style guidelines
- [ ] New and existing tests pass locally
- [ ] I have added appropriate error handling
- [ ] I have added or updated documentation as needed

## Additional context
<!-- Add any other context, implementation notes, or design decisions
-->
2025-09-12 13:36:57 +02:00

135 lines
4.9 KiB
YAML

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle
name: Release
on:
release:
types: [ published ]
jobs:
build:
runs-on: macos-latest-xlarge
environment: release
env:
JAVA_OPTS: "-Xmx8g -Dfile.encoding=UTF-8 -Djava.awt.headless=true -Dkotlin.daemon.jvm.options=-Xmx6g"
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v5
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Verify publication configuration
run: ./gradlew jreleaserConfig
env:
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.OSSRH_USERNAME }}
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Clean Build with Gradle
run: ./gradlew clean build
env:
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.OSSRH_USERNAME }}
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }}
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
SIGNING_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }}
- name: Publish to Maven Central Portal
id: publish
run: ./gradlew publish jreleaserFullRelease --info --stacktrace -Djreleaser.verbose=true
env:
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.OSSRH_USERNAME }}
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
SIGNING_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }}
- name: Query Central Portal for validation errors
if: failure()
shell: bash
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
run: |
set -euo pipefail
OUTPUT_PROPS="build/jreleaser/output.properties"
if [[ ! -f "$OUTPUT_PROPS" ]]; then
echo "::error title=File Missing::The file '$OUTPUT_PROPS' does not exist."
exit 1
fi
DEPLOY_ID=$(grep '^deploymentId=' "$OUTPUT_PROPS" | cut -d= -f2 || true)
if [[ -z "$DEPLOY_ID" ]]; then
echo "::error title=Missing Deployment ID::The 'deploymentId' key was not found in '$OUTPUT_PROPS'."
exit 1
fi
echo "Portal deploymentId: $DEPLOY_ID"
if [ -z "$OSSRH_USERNAME" ]; then
echo "::error title='OSSRH_USERNAME' is not set."
exit 1
fi
if [ -z "$OSSRH_TOKEN" ]; then
echo "::error title='OSSRH_TOKEN' is not set."
exit 1
fi
AUTH=$(printf "%s:%s" "$OSSRH_USERNAME" "$OSSRH_TOKEN" | base64)
echo "::add-mask::$AUTH"
STATUS_JSON=$(curl -sS \
-H "Authorization: Bearer $AUTH" \
-H "Content-Type: application/json" \
-X POST \
"https://central.sonatype.com/api/v1/publisher/status?id=$DEPLOY_ID")
echo "$STATUS_JSON" | jq .
echo "$STATUS_JSON" | jq -r '.errors[]?.message' |
while read -r MSG; do
echo "::error title=Sonatype validation::$MSG"
done
{
echo "### Sonatype Central Portal validation result"
echo
echo '```json'
echo "$STATUS_JSON"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload JReleaser artefacts
if: always()
uses: actions/upload-artifact@v4
with:
name: jreleaser-logs
path: |
build/jreleaser/trace.log
build/jreleaser/output.properties