Skip to content

Commit 34d054c

Browse files
committed
Add CI/CD workflow with GitHub Actions: build, test, publish to Central Sonatype
1 parent 3261ebb commit 34d054c

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request: {}
8+
9+
jobs:
10+
build-test-and-publish:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-java@v4
16+
with:
17+
distribution: 'temurin'
18+
java-version: '24'
19+
20+
- name: Configure Maven settings
21+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
22+
uses: s4u/maven-settings-action@v3.0.0
23+
with:
24+
servers: |
25+
[{
26+
"id": "central",
27+
"username": "${{ secrets.CENTRAL_SONATYPE_USERNAME }}",
28+
"password": "${{ secrets.CENTRAL_SONATYPE_PASSWORD }}"
29+
}]
30+
31+
- name: Import GPG key
32+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
33+
uses: crazy-max/ghaction-import-gpg@v6
34+
with:
35+
gpg_private_key: ${{ secrets.GPG_TEST_PRIV_KEY }}
36+
passphrase: ${{ secrets.GPG_TEST_PASSPHRASE }}
37+
38+
- name: Build, test
39+
run: |
40+
echo "Current version: $(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)"
41+
mvn clean compile test
42+
43+
- name: Build, test, and conditionally publish
44+
run: |
45+
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/master" ]]; then
46+
echo "Publishing SNAPSHOT to Central..."
47+
mvn deploy
48+
else
49+
echo "Building artifacts without publishing..."
50+
mvn package -Dmaven.test.skip=true -Dgpg.skip=true
51+
fi
52+
53+
- name: Upload build artifacts
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: java-runtime-${{ github.event_name }}-${{ github.event.number || github.sha }}
57+
path: target/*.jar
58+
retention-days: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && 30 || 7 }}
59+
60+
- name: Upload test results
61+
uses: actions/upload-artifact@v4
62+
if: always()
63+
with:
64+
name: test-results-${{ github.event_name }}-${{ github.event.number || github.sha }}
65+
path: target/surefire-reports/
66+
retention-days: 7

0 commit comments

Comments
 (0)