Skip to content

Release Java SDK

Release Java SDK #4

Workflow file for this run

# .github/workflows/main.yml (Java)
name: Release Java SDK
on:
push:
branches: [master]
paths:
- '.changelog/v*.md'
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
with:
fetch-depth: 0
- name: Setup JDK
uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9
with:
java-version: '8'
distribution: 'temurin'
server-id: central
server-username: MAVEN_CENTRAL_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: GPG_PASSPHRASE
- name: Debug GPG
run: |
echo "GPG version:"
gpg --version | head -n 1
echo "Secret keys in keyring:"
gpg --list-secret-keys --keyid-format=long || echo "No secret keys found"
- name: Extract Version
id: version
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$VERSION" >> $GITHUB_OUTPUT
- name: Build and Test
run: mvn clean verify -B
- name: Create Tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a ${{ steps.version.outputs.tag }} -m "Release ${{ steps.version.outputs.tag }}"
git push origin ${{ steps.version.outputs.tag }}
- name: Read Changelog
id: changelog
run: |
CHANGELOG_FILE=".changelog/v${{ steps.version.outputs.version }}.md"
if [ -f "$CHANGELOG_FILE" ]; then
delimiter="$(openssl rand -hex 8)"
echo "content<<$delimiter" >> $GITHUB_OUTPUT
cat "$CHANGELOG_FILE" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "$delimiter" >> $GITHUB_OUTPUT
else
echo "content=Release ${{ steps.version.outputs.tag }}" >> $GITHUB_OUTPUT
fi
- name: Create Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Release ${{ steps.version.outputs.tag }}
body: ${{ steps.changelog.outputs.content }}
- name: Check Maven Central Version
id: maven_check
run: |
VERSION="${{ steps.version.outputs.version }}"
GROUP_PATH="com/volcengine"
ARTIFACT_ID="volcengine-java-sdk"
POM_URL="https://repo.maven.apache.org/maven2/${GROUP_PATH}/${ARTIFACT_ID}/${VERSION}/${ARTIFACT_ID}-${VERSION}.pom"
CODE=$(curl -sS -o /dev/null -w "%{http_code}" "$POM_URL")
if [ "$CODE" = "200" ]; then
echo "publish_needed=false" >> $GITHUB_OUTPUT
echo "maven_version_exists=true" >> $GITHUB_OUTPUT
else
echo "publish_needed=true" >> $GITHUB_OUTPUT
echo "maven_version_exists=false" >> $GITHUB_OUTPUT
fi
- name: Publish to Maven Central
if: steps.maven_check.outputs.publish_needed == 'true'
run: |
mvn clean deploy -B -Ppublic -DskipTests \
-Dmaven.javadoc.failOnError=false \
-Dmaven.javadoc.quiet=true
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}