33 workflow_dispatch :
44 inputs :
55 tag :
6- description : " Release tag (e.g. v2.0.3 )"
6+ description : " Release tag (e.g. v2.0.6 )"
77 required : true
88 push :
9- tags :
10- - " v* "
9+ branches :
10+ - main
1111permissions :
1212 contents : write
1313concurrency :
@@ -19,44 +19,89 @@ jobs:
1919 steps :
2020 - name : checkout
2121 uses : actions/checkout@v4
22+ with :
23+ # need previous commit to diff the pom version on push events
24+ fetch-depth : 2
2225 - name : setup java/maven
2326 uses : actions/setup-java@v4
2427 with :
2528 java-version : ' 8'
2629 distribution : ' temurin'
2730 cache : maven
28- - name : resolve tag
29- id : tag
31+ - name : resolve version and decide release
32+ id : decide
33+ env :
34+ INPUT_TAG : ${{ github.event.inputs.tag }}
35+ EVENT_NAME : ${{ github.event_name }}
3036 run : |
3137 set -euo pipefail
32- if [ -n "${{ github.event.inputs.tag }}" ]; then
33- echo "tag=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
38+ CURRENT_VERSION=$(mvn -q help:evaluate -Dexpression=project.version -DforceStdout -pl webull-openapi-java-sdk)
39+
40+ if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
41+ # manual trigger: use the provided tag, always release
42+ TAG_VERSION="${INPUT_TAG#v}"
43+ if [ "$TAG_VERSION" != "$CURRENT_VERSION" ]; then
44+ echo "::error::Input tag ($TAG_VERSION) does not match pom.xml version ($CURRENT_VERSION)"
45+ exit 1
46+ fi
47+ echo "tag=v${CURRENT_VERSION}" >> "$GITHUB_OUTPUT"
48+ echo "should_release=true" >> "$GITHUB_OUTPUT"
49+ echo "Manual release requested for v${CURRENT_VERSION}"
3450 else
35- echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
51+ # push to main: only release when the pom version changed vs the previous commit
52+ PREV_VERSION=$(git show HEAD~1:webull-openapi-java-sdk/pom.xml 2>/dev/null \
53+ | grep -oE '<version>[^<]+</version>' | head -1 \
54+ | sed -E 's/<\/?version>//g' || echo "")
55+ echo "current=${CURRENT_VERSION} previous=${PREV_VERSION}"
56+ if [ "$CURRENT_VERSION" != "$PREV_VERSION" ]; then
57+ echo "tag=v${CURRENT_VERSION}" >> "$GITHUB_OUTPUT"
58+ echo "should_release=true" >> "$GITHUB_OUTPUT"
59+ echo "Version changed ($PREV_VERSION -> $CURRENT_VERSION), will release"
60+ else
61+ echo "should_release=false" >> "$GITHUB_OUTPUT"
62+ echo "Version unchanged ($CURRENT_VERSION), skipping release"
63+ fi
3664 fi
37- - name : verify version consistency
65+ - name : create and push tag
66+ if : steps.decide.outputs.should_release == 'true'
3867 env :
39- VERSION : ${{ steps.tag .outputs.tag }}
68+ TAG : ${{ steps.decide .outputs.tag }}
4069 run : |
4170 set -euo pipefail
42- POM_VERSION=$(mvn -q help:evaluate -Dexpression=project.version -DforceStdout -pl webull-openapi-java-sdk)
43- TAG_VERSION="${VERSION#v}" # strip leading 'v'
44- if [ "$POM_VERSION" != "$TAG_VERSION" ]; then
45- echo "::error::Tag version ($TAG_VERSION) does not match pom.xml version ($POM_VERSION)"
46- exit 1
71+ if git rev-parse "$TAG" >/dev/null 2>&1 || git ls-remote --tags origin "$TAG" | grep -q "$TAG"; then
72+ echo "Tag $TAG already exists, skip creating"
73+ else
74+ git config user.name "github-actions[bot]"
75+ git config user.email "github-actions[bot]@users.noreply.github.com"
76+ git tag -a "$TAG" -m "Release $TAG"
77+ git push origin "$TAG"
78+ echo "Created and pushed tag $TAG"
4779 fi
48- echo "Version verified: $POM_VERSION"
4980 - name : package with sources and javadoc
50- run : mvn --batch-mode -pl webull-openapi-java-sdk -am package source:jar javadoc:jar -DskipTests -Dmaven.javadoc.failOnError=false
81+ if : steps.decide.outputs.should_release == 'true'
82+ run : mvn --batch-mode clean -pl webull-openapi-java-sdk -am package source:jar javadoc:jar -DskipTests -Dmaven.javadoc.failOnError=false
5183 - name : assemble dist
84+ if : steps.decide.outputs.should_release == 'true'
5285 env :
53- VERSION : ${{ steps.tag .outputs.tag }}
86+ VERSION : ${{ steps.decide .outputs.tag }}
5487 run : |
5588 set -euo pipefail
89+ POM_VERSION="${VERSION#v}" # jar file names use the bare version, tag has a 'v' prefix
90+ TARGET="webull-openapi-java-sdk/target"
5691 mkdir -p dist
5792 STAGE="dist/webull-openapi-java-sdk-${VERSION}"
5893 mkdir -p "${STAGE}"
59- cp webull-openapi-java-sdk/target/webull-openapi-java-sdk-*.jar "${STAGE}/"
94+
95+ # copy only the three jars for this exact version; fail fast if any is missing
96+ for suffix in "" "-sources" "-javadoc"; do
97+ JAR="${TARGET}/webull-openapi-java-sdk-${POM_VERSION}${suffix}.jar"
98+ if [ ! -f "${JAR}" ]; then
99+ echo "::error::Expected artifact not found: ${JAR}"
100+ exit 1
101+ fi
102+ cp "${JAR}" "${STAGE}/"
103+ done
104+
60105 cp README.md LICENSE.txt NOTICE.txt "${STAGE}/" 2>/dev/null || true
61106 cp -r licenses "${STAGE}/licenses"
62107
@@ -68,15 +113,17 @@ jobs:
68113 # checksums are computed over the archive files themselves
69114 ( cd dist && shasum -a 256 *.zip *.tar.gz > SHA256SUMS )
70115 - name : list artifacts
116+ if : steps.decide.outputs.should_release == 'true'
71117 run : |
72118 echo "=== Artifacts to be released ==="
73119 ls -lh dist/
74120 echo "=== Contents of archive ==="
75121 unzip -l dist/webull-openapi-java-sdk-*.zip | head -30
76122 - name : publish release
123+ if : steps.decide.outputs.should_release == 'true'
77124 env :
78125 GH_TOKEN : ${{ github.token }}
79- VERSION : ${{ steps.tag .outputs.tag }}
126+ VERSION : ${{ steps.decide .outputs.tag }}
80127 run : |
81128 set -euo pipefail
82129 if gh release view "${VERSION}" --repo "${GITHUB_REPOSITORY}" > /dev/null 2>&1; then
0 commit comments