-
Notifications
You must be signed in to change notification settings - Fork 0
192 lines (158 loc) · 6.62 KB
/
Copy pathmaven-central-deploy.yml
File metadata and controls
192 lines (158 loc) · 6.62 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: Deploy Java SDK to Maven Central
# Triggers on tags like java/v1.0.0, java/v2.1.3, etc.
# Uses Maven Central Portal API with token-based authentication
on:
push:
tags:
- 'java/v*.*.*'
# Allows manual workflow dispatch
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g., 1.2.3)'
required: true
type: string
permissions:
contents: write # Need write permission to commit version changes back
pull-requests: write # Required for creating PR after successful deployment
jobs:
maven-central-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Setup buf CLI (required for protobuf generation)
uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ github.token }}
- name: Generate Java code from protobuf
run: |
echo "☕ Generating Java code from protobuf definitions..."
./dev/tool.sh generate --targets=java
- name: Run Java linting (early validation)
run: |
echo "🔍 Running Java linting and code quality checks..."
cd java
mvn checkstyle:check
- name: Run Java tests (early validation)
run: |
echo "🧪 Running Java tests..."
cd java
mvn test
- name: Extract version from tag
id: version
run: |
# Extract version from java/v*.*.* tag (e.g., java/v1.2.3 -> 1.2.3)
if [[ "${{ github.event_name }}" == "push" ]]; then
VERSION=$(echo "${{ github.ref_name }}" | sed 's/^java\/v//')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
else
echo "Manual workflow dispatch - version must be set manually"
exit 1
fi
- name: Update POM version
run: |
VERSION="${{ steps.version.outputs.version }}"
echo "Setting Java SDK version to: $VERSION"
# Update java/pom.xml version using Maven versions plugin
cd java
mvn versions:set -DnewVersion="$VERSION" -DgenerateBackupPoms=false
echo "Updated java/pom.xml version:"
grep '<version>' pom.xml | head -1
- name: Setup GPG for signing
run: |
echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --batch --import --quiet
gpg --list-secret-keys --keyid-format LONG
- name: Create Maven settings with credentials
run: |
mkdir -p ~/.m2
cat > ~/.m2/settings.xml <<EOF
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>central</id>
<username>${{ secrets.SONATYPE_USERNAME }}</username>
<password>${{ secrets.SONATYPE_PASSWORD }}</password>
</server>
</servers>
</settings>
EOF
- name: Deploy to Maven Central
run: |
echo "📦 Deploying to Maven Central..."
cd java
mvn clean deploy -Prelease \
-Dgpg.passphrase="${{ secrets.GPG_PASSPHRASE }}" \
--batch-mode --no-transfer-progress
env:
GPG_TTY: $(tty)
- name: Success notification
run: |
VERSION="${{ steps.version.outputs.version }}"
echo ""
echo "############################################################"
echo "# #"
echo "# 🎉 Java SDK v$VERSION auto-published to Maven Central! ☕ #"
echo "# #"
echo "# Artifact: co.meshtrade.api:api:$VERSION #"
echo "# Registry: https://central.sonatype.com/ #"
echo "# #"
echo "############################################################"
- name: Create PR with version update
if: success()
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ steps.version.outputs.version }}"
BRANCH_NAME="chore/maven-version-update-$VERSION"
echo "📝 Creating PR to commit version $VERSION back to repository..."
# Configure git
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Create and checkout new branch
git checkout -b "$BRANCH_NAME"
# Add only the version change
git add java/pom.xml
# Commit the version change
COMMIT_MSG="chore: update Java SDK version to $VERSION
After successful deployment to Maven Central registry.
Tag: java/v$VERSION
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>"
git commit -m "$COMMIT_MSG"
# Push the branch
git push origin "$BRANCH_NAME"
# Create PR using GitHub CLI
PR_BODY="## Summary
Updates Java SDK version to $VERSION after successful Maven Central deployment.
## Details
- Package successfully published to Maven Central registry
- Version updated in \`java/pom.xml\`
- Triggered by tag: \`java/v$VERSION\`
## Checklist
- [x] Version updated to match published package
- [x] Package successfully deployed to Maven Central
- [ ] Merged to main branch
🤖 Generated with [Claude Code](https://claude.ai/code)"
gh pr create \
--title "chore: update Java SDK version to $VERSION" \
--body "$PR_BODY" \
--base master \
--head "$BRANCH_NAME"
echo "✅ PR created successfully!"