Skip to content

Commit 9055a89

Browse files
author
方佳
committed
Merge branch 'main_merge_261019' into 'main'
feat: auto-tag and release on main See merge request webull/webull-openapi-java-sdk!54
2 parents 1f93946 + 39c60e7 commit 9055a89

6 files changed

Lines changed: 74 additions & 24 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ on:
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
1111
permissions:
1212
contents: write
1313
concurrency:
@@ -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

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ hs_err_pid*
88
# Build targets
99
**/target/**
1010

11+
# Release distribution artifacts (generated by release workflow)
12+
dist/
13+
1114
# Operating system file
1215
*.DS_Store
1316

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<groupId>com.webull.openapi</groupId>
2222
<artifactId>webull-openapi-java-sdk-parent</artifactId>
2323
<packaging>pom</packaging>
24-
<version>2.0.5</version>
24+
<version>2.0.6</version>
2525

2626
<name>webull-openapi-java-sdk-parent</name>
2727
<url>https://github.com/webull-inc/webull-openapi-java-sdk/</url>

‎webull-openapi-java-sdk-samples/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>com.webull.openapi</groupId>
2121
<artifactId>webull-openapi-java-sdk-parent</artifactId>
22-
<version>2.0.5</version>
22+
<version>2.0.6</version>
2323
</parent>
2424
<modelVersion>4.0.0</modelVersion>
2525

‎webull-openapi-java-sdk/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.webull.openapi</groupId>
99
<artifactId>webull-openapi-java-sdk-parent</artifactId>
10-
<version>2.0.5</version>
10+
<version>2.0.6</version>
1111
</parent>
1212

1313
<artifactId>webull-openapi-java-sdk</artifactId>

‎webull-openapi-java-sdk/src/main/java/com/webull/openapi/core/config/ProjectReaderHelper.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private ProjectReaderHelper() {
2424

2525
private static final String APPLICATION_VERSION = "application.version";
2626

27-
private static final String DEFAULT_APPLICATION_VERSION = "2.0.5";
27+
private static final String DEFAULT_APPLICATION_VERSION = "2.0.6";
2828

2929
private static final String APPLICATION_NAME = "application.name";
3030

0 commit comments

Comments
 (0)