Skip to content

Commit 38893ee

Browse files
Introduce release process through GHA (openhab#497)
* Introduce release process through GHA Signed-off-by: Kai Kreuzer <kai@openhab.org> Co-authored-by: Holger Friedrich <mail@holger-friedrich.de>
1 parent 83d608e commit 38893ee

1 file changed

Lines changed: 259 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
# This workflow handles the complete release process for static-code-analysis
2+
# It converts snapshot to release version, deploys to Maven Central via OSSRH,
3+
# and then bumps to the next snapshot version
4+
5+
name: Release to Maven Central
6+
permissions:
7+
contents: write
8+
9+
on:
10+
workflow_dispatch:
11+
inputs:
12+
release_version:
13+
description: 'Release version (e.g., 0.18.0)'
14+
required: true
15+
type: string
16+
next_snapshot_version:
17+
description: 'Next snapshot version (e.g., 0.19.0-SNAPSHOT)'
18+
required: true
19+
type: string
20+
21+
jobs:
22+
release:
23+
name: Release to Maven Central
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v6
29+
with:
30+
token: ${{ secrets.GITHUB_TOKEN }}
31+
fetch-depth: 0
32+
33+
- name: Set up JDK 11
34+
uses: actions/setup-java@v5
35+
with:
36+
java-version: 11
37+
distribution: 'temurin'
38+
cache: maven
39+
server-id: ossrh
40+
server-username: OSSRH_USERNAME
41+
server-password: OSSRH_PASSWORD
42+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
43+
gpg-passphrase: GPG_PASSPHRASE
44+
45+
- name: Configure Git
46+
run: |
47+
git config --global user.name "github-actions[bot]"
48+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
49+
50+
- name: Update version to release version
51+
run: |
52+
mvn versions:set -DnewVersion=${{ github.event.inputs.release_version }}
53+
mvn versions:commit
54+
55+
- name: Update parent POM versions in modules
56+
run: |
57+
# Update parent version in all child POMs
58+
for pom in $(find . -name pom.xml -not -path "*/target/*" -not -path "*/src/test/resources/*"); do
59+
if [ -f "$pom" ]; then
60+
mvn versions:update-parent -DparentVersion=${{ github.event.inputs.release_version }} -f "$pom"
61+
mvn versions:commit -f "$pom"
62+
fi
63+
done
64+
65+
- name: Verify release version
66+
run: |
67+
echo "Updated version to:"
68+
mvn help:evaluate -Dexpression=project.version -q -DforceStdout
69+
70+
- name: Build without tests
71+
run: mvn clean compile -DskipTests=true -DskipChecks=true
72+
73+
- name: Deploy to Maven Central
74+
id: maven-deploy
75+
env:
76+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
77+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
78+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
79+
run: |
80+
# Fail fast: If this step fails, no git operations will occur
81+
mvn -DskipTests=true -DskipChecks=true -DperformRelease=true clean deploy
82+
83+
- name: Trigger Central Publisher Portal Upload
84+
env:
85+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
86+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
87+
CENTRAL_NAMESPACE: ${{ secrets.CENTRAL_NAMESPACE }}
88+
run: |
89+
echo "Triggering manual upload to Central Publisher Portal..."
90+
91+
# Create base64 encoded credentials for Basic Auth
92+
CREDENTIALS=$(echo -n "$OSSRH_USERNAME:$OSSRH_PASSWORD" | base64)
93+
94+
# Make POST request to trigger upload
95+
HTTP_STATUS=$(curl -s -o response.json -w "%{http_code}" \
96+
-X POST \
97+
-H "Authorization: Basic $CREDENTIALS" \
98+
-H "Content-Type: application/json" \
99+
"https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/$CENTRAL_NAMESPACE")
100+
101+
echo "HTTP Status: $HTTP_STATUS"
102+
echo "Response:"
103+
cat response.json
104+
105+
if [ $HTTP_STATUS -eq 200 ] || [ $HTTP_STATUS -eq 201 ]; then
106+
echo "✅ Successfully triggered upload to Central Publisher Portal"
107+
else
108+
echo "❌ Failed to trigger upload (HTTP $HTTP_STATUS)"
109+
echo "Response details:"
110+
cat response.json
111+
exit 1
112+
fi
113+
114+
- name: Collect all POM files for commit
115+
# This step only runs if Maven Central deployment succeeded (fail-fast behavior)
116+
if: success()
117+
run: |
118+
# Add all modified tracked POM files
119+
git add -u **/pom.xml
120+
121+
- name: Commit release version and push to main branch
122+
# This step only runs if Maven Central deployment succeeded (fail-fast behavior)
123+
if: success()
124+
run: |
125+
git commit -m "Release version ${{ github.event.inputs.release_version }}"
126+
git push origin
127+
128+
- name: Create and push release tag
129+
# This step only runs if Maven Central deployment and commit succeeded (fail-fast behavior)
130+
if: success()
131+
run: |
132+
git tag -a "v${{ github.event.inputs.release_version }}" -m "Release version ${{ github.event.inputs.release_version }}"
133+
git push origin "v${{ github.event.inputs.release_version }}"
134+
135+
- name: Update to next snapshot version
136+
# This step only runs after successful tag creation (fail-fast behavior)
137+
if: success()
138+
run: |
139+
mvn versions:set -DnewVersion=${{ github.event.inputs.next_snapshot_version }}
140+
mvn versions:commit
141+
142+
- name: Update parent POM versions in modules to snapshot
143+
# This step only runs after successful tag creation (fail-fast behavior)
144+
if: success()
145+
run: |
146+
# Update parent version in all child POMs
147+
# Find all pom.xml files except the root pom.xml
148+
for pom in $(find . -name pom.xml ! -path "./pom.xml"); do
149+
if [ -f "$pom" ]; then
150+
mvn versions:update-parent -DparentVersion=${{ github.event.inputs.next_snapshot_version }} -f "$pom"
151+
mvn versions:commit -f "$pom"
152+
fi
153+
done
154+
155+
- name: Verify snapshot version
156+
if: success()
157+
run: |
158+
echo "Updated version to:"
159+
mvn help:evaluate -Dexpression=project.version -q -DforceStdout
160+
161+
- name: Commit and push snapshot version
162+
# This step only runs after successful deployment and tag creation (fail-fast behavior)
163+
if: success()
164+
run: |
165+
# Add all modified POM files
166+
git add **/pom.xml
167+
git commit -m "Prepare for next development iteration: ${{ github.event.inputs.next_snapshot_version }}"
168+
git push origin
169+
170+
- name: Create GitHub Release
171+
# This step only runs after all previous steps succeeded (fail-fast behavior)
172+
if: success()
173+
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
174+
with:
175+
tag_name: "v${{ github.event.inputs.release_version }}"
176+
name: "Release ${{ github.event.inputs.release_version }}"
177+
body: |
178+
Release ${{ github.event.inputs.release_version }}
179+
180+
This release has been automatically deployed to Maven Central.
181+
182+
**Artifacts:**
183+
- `org.openhab.tools.sat:sat-plugin:${{ github.event.inputs.release_version }}`
184+
- `org.openhab.tools.sat:sat-extension:${{ github.event.inputs.release_version }}`
185+
- `org.openhab.tools:openhab-codestyle:${{ github.event.inputs.release_version }}`
186+
- `org.openhab.tools.sat.custom-checks:checkstyle-rules:${{ github.event.inputs.release_version }}`
187+
- `org.openhab.tools.sat.custom-checks:pmd-rules:${{ github.event.inputs.release_version }}`
188+
- `org.openhab.tools.sat.custom-checks:findbugs-rules:${{ github.event.inputs.release_version }}`
189+
190+
**Maven Central - SAT Plugin:**
191+
```xml
192+
<plugin>
193+
<groupId>org.openhab.tools.sat</groupId>
194+
<artifactId>sat-plugin</artifactId>
195+
<version>${{ github.event.inputs.release_version }}</version>
196+
</plugin>
197+
```
198+
199+
**Maven Central - SAT Extension:**
200+
```xml
201+
<extension>
202+
<groupId>org.openhab.tools.sat</groupId>
203+
<artifactId>sat-extension</artifactId>
204+
<version>${{ github.event.inputs.release_version }}</version>
205+
</extension>
206+
```
207+
208+
**Maven Central - Codestyle:**
209+
```xml
210+
<dependency>
211+
<groupId>org.openhab.tools</groupId>
212+
<artifactId>openhab-codestyle</artifactId>
213+
<version>${{ github.event.inputs.release_version }}</version>
214+
</dependency>
215+
```
216+
draft: false
217+
prerelease: false
218+
219+
check-central-deployment:
220+
name: Verify Maven Central Deployment
221+
needs: release
222+
runs-on: ubuntu-latest
223+
224+
steps:
225+
- name: Wait for Maven Central synchronization
226+
run: |
227+
echo "Waiting for artifacts to be synchronized to Maven Central..."
228+
sleep 300 # Wait 5 minutes for initial propagation
229+
230+
- name: Check Maven Central availability
231+
run: |
232+
RELEASE_VERSION="${{ github.event.inputs.release_version }}"
233+
MAX_ATTEMPTS=12
234+
ATTEMPT=1
235+
236+
while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
237+
echo "Attempt $ATTEMPT of $MAX_ATTEMPTS: Checking Maven Central for version $RELEASE_VERSION..."
238+
239+
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
240+
"https://repo1.maven.org/maven2/org/openhab/tools/sat/sat-plugin/$RELEASE_VERSION/sat-plugin-$RELEASE_VERSION.pom")
241+
242+
if [ $HTTP_STATUS -eq 200 ]; then
243+
echo "✅ Artifact successfully found on Maven Central!"
244+
echo "🔗 Maven Central URL: https://repo1.maven.org/maven2/org/openhab/tools/sat/sat-plugin/$RELEASE_VERSION/"
245+
echo "📦 Maven Central search: https://search.maven.org/artifact/org.openhab.tools.sat/sat-plugin/$RELEASE_VERSION/maven-plugin"
246+
break
247+
else
248+
echo "❌ Artifact not yet available (HTTP $HTTP_STATUS). Waiting..."
249+
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
250+
echo "⚠️ Maximum attempts reached. Deployment may still be in progress."
251+
echo "🕐 It can take up to 2 hours for artifacts to appear on Maven Central."
252+
echo "📋 Check manually at: https://search.maven.org/artifact/org.openhab.tools.sat/sat-plugin/$RELEASE_VERSION/maven-plugin"
253+
else
254+
sleep 300 # Wait 5 minutes between attempts
255+
fi
256+
fi
257+
258+
ATTEMPT=$((ATTEMPT + 1))
259+
done

0 commit comments

Comments
 (0)