Skip to content

Commit 301e51b

Browse files
committed
Refactor publish-maven workflow to enhance version handling and release preparation
1 parent 4f52b3d commit 301e51b

1 file changed

Lines changed: 57 additions & 22 deletions

File tree

.github/workflows/publish-maven.yml

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ env:
66
on:
77
workflow_dispatch:
88
inputs:
9-
version:
10-
description: "Version to publish (optional). If empty, uses version from pom.xml."
9+
releaseVersion:
10+
description: "Release version (e.g., 1.0.0). If empty, derives from pom.xml by removing -SNAPSHOT"
11+
required: false
1112
type: string
13+
developmentVersion:
14+
description: "Next development version (e.g., 1.0.1-SNAPSHOT). If empty, increments patch version"
1215
required: false
16+
type: string
1317
prerelease:
1418
description: "Is this a prerelease?"
1519
type: boolean
@@ -29,7 +33,7 @@ jobs:
2933
name: Publish Java SDK to Maven Central
3034
runs-on: ubuntu-latest
3135
outputs:
32-
version: ${{ steps.get-version.outputs.version }}
36+
version: ${{ steps.versions.outputs.release_version }}
3337
steps:
3438
- uses: actions/checkout@v6
3539
with:
@@ -54,24 +58,53 @@ jobs:
5458
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
5559
gpg-passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
5660

57-
- name: Set version in pom.xml
58-
if: ${{ github.event.inputs.version != '' }}
59-
run: mvn versions:set -DnewVersion=${{ github.event.inputs.version }} -DgenerateBackupPoms=false
60-
61-
- name: Get version
62-
id: get-version
61+
- name: Determine versions
62+
id: versions
6363
run: |
64-
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
65-
echo "version=$VERSION" >> $GITHUB_OUTPUT
66-
echo "Publishing version: $VERSION" >> $GITHUB_STEP_SUMMARY
64+
CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
65+
echo "Current pom.xml version: $CURRENT_VERSION"
66+
67+
# Determine release version
68+
if [ -n "${{ inputs.releaseVersion }}" ]; then
69+
RELEASE_VERSION="${{ inputs.releaseVersion }}"
70+
else
71+
# Remove -SNAPSHOT suffix if present
72+
RELEASE_VERSION="${CURRENT_VERSION%-SNAPSHOT}"
73+
fi
74+
echo "Release version: $RELEASE_VERSION"
75+
76+
# Determine next development version
77+
if [ -n "${{ inputs.developmentVersion }}" ]; then
78+
DEV_VERSION="${{ inputs.developmentVersion }}"
79+
else
80+
# Increment patch version and add -SNAPSHOT
81+
IFS='.' read -r MAJOR MINOR PATCH <<< "$RELEASE_VERSION"
82+
NEXT_PATCH=$((PATCH + 1))
83+
DEV_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}-SNAPSHOT"
84+
fi
85+
echo "Next development version: $DEV_VERSION"
86+
87+
echo "release_version=$RELEASE_VERSION" >> $GITHUB_OUTPUT
88+
echo "dev_version=$DEV_VERSION" >> $GITHUB_OUTPUT
89+
90+
echo "### Version Summary" >> $GITHUB_STEP_SUMMARY
91+
echo "- **Release version:** $RELEASE_VERSION" >> $GITHUB_STEP_SUMMARY
92+
echo "- **Next development version:** $DEV_VERSION" >> $GITHUB_STEP_SUMMARY
6793
68-
- name: Build and Deploy to Maven Central
69-
run: mvn verify deploy -DskipTests -Prelease
70-
env:
71-
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
72-
MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
73-
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
74-
MAVEN_GPG_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
94+
- name: Prepare Release
95+
run: |
96+
mvn -B release:prepare \
97+
-DreleaseVersion=${{ steps.versions.outputs.release_version }} \
98+
-DdevelopmentVersion=${{ steps.versions.outputs.dev_version }} \
99+
-DtagNameFormat=v@{project.version} \
100+
-DpushChanges=true \
101+
-Darguments="-DskipTests"
102+
103+
- name: Perform Release and Deploy to Maven Central
104+
run: |
105+
mvn -B release:perform \
106+
-Dgoals="deploy" \
107+
-Darguments="-DskipTests -Prelease"
75108
76109
github-release:
77110
name: Create GitHub Release
@@ -80,6 +113,8 @@ jobs:
80113
runs-on: ubuntu-latest
81114
steps:
82115
- uses: actions/checkout@v6
116+
with:
117+
fetch-depth: 0
83118
- name: Create GitHub Release
84119
run: |
85120
VERSION="${{ needs.publish-maven.outputs.version }}"
@@ -113,11 +148,11 @@ jobs:
113148
EOF
114149
)
115150
116-
gh release create "${VERSION}" \
117-
${{ github.event.inputs.prerelease == 'true' && '--prerelease' || '' }} \
151+
gh release create "v${VERSION}" \
152+
${{ inputs.prerelease == true && '--prerelease' || '' }} \
118153
--title "Java SDK v${VERSION}" \
119154
--notes "${RELEASE_NOTES}" \
120155
--generate-notes \
121-
--target ${{ github.sha }}
156+
--target "v${VERSION}"
122157
env:
123158
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)