Repository navigation
153 lines (148 loc) · 6.28 KB
/
Copy pathrelease.yml
File metadata and controls
153 lines (148 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Release package to GitHub Releases
on:
workflow_dispatch:
inputs:
tag:
description: "Release tag (e.g. 2.0.6)"
required: true
push:
branches:
- main
permissions:
contents: write
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
# need previous commit to diff the pom version on push events
fetch-depth: 2
- name: setup java/maven
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: resolve version and decide release
id: decide
env:
INPUT_TAG: ${{ github.event.inputs.tag }}
EVENT_NAME: ${{ github.event_name }}
run: |
set -euo pipefail
CURRENT_VERSION=$(mvn -q help:evaluate -Dexpression=project.version -DforceStdout -pl webull-openapi-java-sdk)
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
# manual trigger: use the provided tag, always release
# tolerate an optional leading 'v' in the input for convenience
TAG_VERSION="${INPUT_TAG#v}"
if [ "$TAG_VERSION" != "$CURRENT_VERSION" ]; then
echo "::error::Input tag ($TAG_VERSION) does not match pom.xml version ($CURRENT_VERSION)"
exit 1
fi
echo "tag=${CURRENT_VERSION}" >> "$GITHUB_OUTPUT"
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "Manual release requested for ${CURRENT_VERSION}"
else
# push to main: only release when the pom version changed vs the previous commit
PREV_VERSION=$(git show HEAD~1:webull-openapi-java-sdk/pom.xml 2>/dev/null \
| grep -oE '<version>[^<]+</version>' | head -1 \
| sed -E 's/<\/?version>//g' || echo "")
echo "current=${CURRENT_VERSION} previous=${PREV_VERSION}"
if [ "$CURRENT_VERSION" != "$PREV_VERSION" ]; then
echo "tag=${CURRENT_VERSION}" >> "$GITHUB_OUTPUT"
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "Version changed ($PREV_VERSION -> $CURRENT_VERSION), will release"
else
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "Version unchanged ($CURRENT_VERSION), skipping release"
fi
fi
- name: create and push tag
if: steps.decide.outputs.should_release == 'true'
env:
TAG: ${{ steps.decide.outputs.tag }}
run: |
set -euo pipefail
if git rev-parse "$TAG" >/dev/null 2>&1 || git ls-remote --tags origin "$TAG" | grep -q "$TAG"; then
echo "Tag $TAG already exists, skip creating"
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
echo "Created and pushed tag $TAG"
fi
- name: package with sources and javadoc
if: steps.decide.outputs.should_release == 'true'
run: mvn --batch-mode clean -pl webull-openapi-java-sdk -am package source:jar javadoc:jar -DskipTests -Dmaven.javadoc.failOnError=false
- name: assemble dist
if: steps.decide.outputs.should_release == 'true'
env:
VERSION: ${{ steps.decide.outputs.tag }}
run: |
set -euo pipefail
POM_VERSION="${VERSION}" # tag equals the bare pom version (no 'v' prefix)
TARGET="webull-openapi-java-sdk/target"
mkdir -p dist
STAGE="dist/webull-openapi-java-sdk-${VERSION}"
mkdir -p "${STAGE}"
# copy only the three jars for this exact version; fail fast if any is missing
for suffix in "" "-sources" "-javadoc"; do
JAR="${TARGET}/webull-openapi-java-sdk-${POM_VERSION}${suffix}.jar"
if [ ! -f "${JAR}" ]; then
echo "::error::Expected artifact not found: ${JAR}"
exit 1
fi
cp "${JAR}" "${STAGE}/"
done
cp README.md LICENSE.txt NOTICE.txt "${STAGE}/" 2>/dev/null || true
cp -r licenses "${STAGE}/licenses"
pushd "${STAGE}" > /dev/null
zip -r "../webull-openapi-java-sdk-${VERSION}.zip" .
tar cfz "../webull-openapi-java-sdk-${VERSION}.tar.gz" .
popd > /dev/null
# checksums are computed over the archive files themselves
( cd dist && shasum -a 256 *.zip *.tar.gz > SHA256SUMS )
- name: list artifacts
if: steps.decide.outputs.should_release == 'true'
run: |
echo "=== Artifacts to be released ==="
ls -lh dist/
echo "=== Contents of archive ==="
unzip -l dist/webull-openapi-java-sdk-*.zip | head -30
- name: publish release
if: steps.decide.outputs.should_release == 'true'
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.decide.outputs.tag }}
run: |
set -euo pipefail
RELEASE_TITLE="webull openapi-java-sdk ${VERSION}"
# release notes use the latest commit message, with the [ISSUE-KEY] marker stripped
# e.g. "feat[API-1931]: auto-tag" -> "feat: auto-tag"
RELEASE_NOTES="$(git log -1 --pretty=%B | sed -E 's/^([a-z]+)\[[^]]*\]:/\1:/')"
if gh release view "${VERSION}" --repo "${GITHUB_REPOSITORY}" > /dev/null 2>&1; then
gh release edit "${VERSION}" \
--repo "${GITHUB_REPOSITORY}" \
--title "${RELEASE_TITLE}" \
--notes "${RELEASE_NOTES}"
gh release upload "${VERSION}" \
dist/webull-openapi-java-sdk-*.zip \
dist/webull-openapi-java-sdk-*.tar.gz \
dist/SHA256SUMS \
--repo "${GITHUB_REPOSITORY}" \
--clobber
else
gh release create "${VERSION}" \
dist/webull-openapi-java-sdk-*.zip \
dist/webull-openapi-java-sdk-*.tar.gz \
dist/SHA256SUMS \
--repo "${GITHUB_REPOSITORY}" \
--title "${RELEASE_TITLE}" \
--notes "${RELEASE_NOTES}"
fi