forked from Lambdua/openai4j
-
Notifications
You must be signed in to change notification settings - Fork 4
137 lines (116 loc) · 4.56 KB
/
maven-publish.yml
File metadata and controls
137 lines (116 loc) · 4.56 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
name: Auto Publish to Maven Central
on:
push:
branches: [ main ]
jobs:
check-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_SIGNING_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Get current version from pom.xml
id: current-version
run: |
CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Get latest tag version
id: latest-tag
run: |
# Get all tags starting with 'v' and sort them
LATEST_TAG=$(git tag -l 'v*' | sort -V | tail -n 1)
if [ -z "$LATEST_TAG" ]; then
LATEST_TAG_VERSION="0.0.0"
else
LATEST_TAG_VERSION=${LATEST_TAG#v}
fi
echo "tag-version=$LATEST_TAG_VERSION" >> $GITHUB_OUTPUT
echo "Latest tag version: $LATEST_TAG_VERSION"
- name: Compare versions and decide if publish
id: version-check
run: |
CURRENT_VERSION="${{ steps.current-version.outputs.version }}"
TAG_VERSION="${{ steps.latest-tag.outputs.tag-version }}"
# Function to compare versions
version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
}
if version_gt "$CURRENT_VERSION" "$TAG_VERSION"; then
echo "should-publish=true" >> $GITHUB_OUTPUT
echo "Current version $CURRENT_VERSION is greater than tag version $TAG_VERSION - will publish"
else
echo "should-publish=false" >> $GITHUB_OUTPUT
echo "Current version $CURRENT_VERSION is not greater than tag version $TAG_VERSION - skip publish"
fi
- name: Build project
if: steps.version-check.outputs.should-publish == 'true'
run: mvn clean compile
- name: Publish to Maven Central
if: steps.version-check.outputs.should-publish == 'true'
run: mvn -P release --batch-mode deploy -DskipTests
env:
MAVEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}
- name: Create tag and release
if: steps.version-check.outputs.should-publish == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.current-version.outputs.version }}"
TAG_NAME="v$VERSION"
# Get commits since last release
LATEST_TAG=$(git tag -l 'v*' | sort -V | tail -n 1)
if [ -z "$LATEST_TAG" ]; then
COMMITS=$(git log --oneline --pretty=format:"- %s (%h)")
else
COMMITS=$(git log --oneline ${LATEST_TAG}..HEAD --pretty=format:"- %s (%h)")
fi
# Create release notes with Maven dependencies
RELEASE_NOTES=$(cat <<EOF
# Release $VERSION
## Recent Changes
$COMMITS
## Maven Dependencies
\`\`\`xml
<!-- Main API -->
<dependency>
<groupId>top.bella</groupId>
<artifactId>openai-java-api</artifactId>
<version>$VERSION</version>
</dependency>
<!-- HTTP Client -->
<dependency>
<groupId>top.bella</groupId>
<artifactId>openai-java-client</artifactId>
<version>$VERSION</version>
</dependency>
<!-- Service Layer -->
<dependency>
<groupId>top.bella</groupId>
<artifactId>openai-java-service</artifactId>
<version>$VERSION</version>
</dependency>
\`\`\`
EOF
)
# Create tag
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
# Create release
gh release create "$TAG_NAME" \
--title "Release $VERSION" \
--notes "$RELEASE_NOTES" \
--latest