Skip to content

Commit 4512fbf

Browse files
committed
add release workflow file
1 parent 93cec2b commit 4512fbf

File tree

1 file changed

+210
-0
lines changed

1 file changed

+210
-0
lines changed

.github/workflows/release.yml

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
name: Release to Maven Central
2+
3+
on:
4+
# Manual trigger
5+
workflow_dispatch:
6+
inputs:
7+
release_version:
8+
description: 'Version to release (if empty, derive from project version)'
9+
required: false
10+
# Automatic trigger on pushing a version tag (e.g., "v1.2.3")
11+
push:
12+
tags:
13+
- 'v*'
14+
# For testing:
15+
pull_request:
16+
branches:
17+
- master
18+
19+
jobs:
20+
tests:
21+
name: Java ${{ matrix.java-version }} ${{ matrix.os }} ${{ matrix.dockcross-only }}
22+
runs-on: ${{ matrix.os }}
23+
24+
strategy:
25+
matrix:
26+
os: [ubuntu-latest]
27+
java-distribution: [adopt]
28+
java-version: [8]
29+
dockcross-only: ["android-arm", "android-arm64", "linux-arm64", "linux-armv5", "linux-armv7", "linux-s390x", "linux-ppc64le", "linux-x64", "linux-x86", "windows-static-x64", "windows-static-x86"]
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
submodules: recursive
35+
36+
- uses: actions/setup-java@v2
37+
with:
38+
distribution: "${{ matrix.java-distribution }}"
39+
java-version: "${{ matrix.java-version }}"
40+
41+
- uses: gradle/actions/setup-gradle@v3
42+
with:
43+
gradle-version: wrapper
44+
45+
- uses: actions/cache@v4
46+
id: gradle-cache
47+
with:
48+
path: |
49+
~/.gradle/caches
50+
~/.gradle/wrapper
51+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
52+
restore-keys: |
53+
${{ runner.os }}-gradle-
54+
55+
# - name: Format check
56+
# if: ${{ matrix.java-version != 8 }}
57+
# run: ./gradlew spotlessCheck
58+
59+
- name: Tests
60+
run: ./gradlew clean test -Ph3SystemPrune=true "-Ph3DockcrossOnly=${{ matrix.dockcross-only }}"
61+
env:
62+
OCI_EXE: docker
63+
64+
- name: Format check for C
65+
run: git diff --exit-code
66+
67+
- uses: actions/upload-artifact@v4
68+
name: Upload artifacts
69+
if: ${{ matrix.java-version == 8 }}
70+
with:
71+
name: docker-built-shared-objects-${{ matrix.dockcross-only }}
72+
path: |
73+
src/main/resources/*/*.so
74+
src/main/resources/*/*.dll
75+
if-no-files-found: error
76+
77+
tests-no-docker:
78+
name: Java (No Docker) ${{ matrix.java-version }} ${{ matrix.os }}
79+
runs-on: ${{ matrix.os }}
80+
81+
strategy:
82+
matrix:
83+
# TODO: Docker on macos-latest running is not working
84+
os: [macos-latest]
85+
java-distribution: [adopt]
86+
java-version: [8]
87+
88+
steps:
89+
- uses: actions/checkout@v4
90+
with:
91+
submodules: recursive
92+
93+
- uses: actions/setup-java@v2
94+
with:
95+
distribution: "${{ matrix.java-distribution }}"
96+
java-version: "${{ matrix.java-version }}"
97+
98+
- uses: gradle/actions/setup-gradle@v3
99+
with:
100+
gradle-version: wrapper
101+
102+
- uses: actions/cache@v4
103+
id: gradle-cache
104+
with:
105+
path: |
106+
~/.gradle/caches
107+
~/.gradle/wrapper
108+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
109+
restore-keys: |
110+
${{ runner.os }}-gradle-
111+
112+
- name: Tests
113+
run: ./gradlew clean test
114+
115+
- uses: actions/upload-artifact@v4
116+
name: Upload Mac OS Artifacts
117+
if: ${{ matrix.os == 'macos-latest' && matrix.java-version == 8 }}
118+
with:
119+
name: macos-built-shared-objects
120+
path: src/main/resources/*/*.dylib
121+
if-no-files-found: error
122+
123+
release:
124+
runs-on: ubuntu-latest
125+
permissions:
126+
contents: write # allow pushing commits/tags
127+
steps:
128+
- name: Check out code
129+
uses: actions/checkout@v3
130+
131+
- name: Set up JDK
132+
uses: actions/setup-java@v3
133+
with:
134+
distribution: 'temurin'
135+
java-version: '21'
136+
137+
- name: Determine release version
138+
id: vars
139+
run: |
140+
# Derive the release version (drop "-SNAPSHOT") from Gradle project or input
141+
VERSION_INPUT="${{ github.event.inputs.release_version || '' }}"
142+
if [ -n "$VERSION_INPUT" ]; then
143+
RELEASE_VERSION="$VERSION_INPUT"
144+
else
145+
# Read version from build.gradle.kts or gradle.properties
146+
RELEASE_VERSION=$(grep -E 'version\s*=' build.gradle.kts | sed -E 's/.*\"(.+)-SNAPSHOT\".*/\1/')
147+
fi
148+
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
149+
150+
- name: Remove -SNAPSHOT suffix (prepare release version)
151+
if: ${{ github.event_name == 'workflow_dispatch' }}
152+
run: |
153+
sed -i -E "s/${RELEASE_VERSION}-SNAPSHOT/$RELEASE_VERSION/" build.gradle.kts gradle.properties || true
154+
git config user.name "github-actions"
155+
git config user.email "[email protected]"
156+
git commit -am "chore: release $RELEASE_VERSION [skip ci]"
157+
158+
# - name: Create Git tag for release
159+
# if: ${{ github.event_name == 'workflow_dispatch' }}
160+
# run: |
161+
# git tag -a "v${RELEASE_VERSION}" -m "Release $RELEASE_VERSION"
162+
# git push origin HEAD:main --follow-tags
163+
164+
- name: Download Docker binaries
165+
uses: actions/[email protected]
166+
with:
167+
pattern: docker-built-shared-objects-*
168+
merge-multiple: true
169+
path: src/main/resources/
170+
171+
- name: Download Mac binaries
172+
uses: actions/[email protected]
173+
with:
174+
name: macos-built-shared-objects
175+
path: src/main/resources/
176+
177+
- name: Download and test
178+
run: |
179+
./gradlew clean test -Ph3GithubArtifactsUse=true -Ph3GithubArtifactsByRun=true
180+
181+
# - name: Publish to Sonatype OSSRH (Maven Central)
182+
# env:
183+
# ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
184+
# ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
185+
# ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.SIGNING_KEY_ID }}
186+
# OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
187+
# OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
188+
# OSSRH_STAGING_PROFILE_ID: ${{ secrets.OSSRH_STAGING_PROFILE_ID }}
189+
# run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
190+
191+
# - name: Create GitHub Release (with changelog notes)
192+
# # This uses an action to create a release on GitHub
193+
# uses: softprops/action-gh-release@v1
194+
# with:
195+
# tag_name: "v${{ env.RELEASE_VERSION }}"
196+
# release_name: "${{ env.RELEASE_VERSION }}"
197+
# body_path: CHANGELOG.md # assumes changelog contains latest release notes at top
198+
# env:
199+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
200+
201+
# - name: Bump to next snapshot version
202+
# run: |
203+
# # Bump minor version (for example) and append -SNAPSHOT for continued development
204+
# NEXT_VERSION=$(echo $RELEASE_VERSION | awk -F. '{$NF += 1; OFS="."; print $0}') # increment last segment
205+
# NEXT_VERSION="$NEXT_VERSION-SNAPSHOT"
206+
# sed -i -E "s/$RELEASE_VERSION/$NEXT_VERSION/" build.gradle.kts gradle.properties || true
207+
# git config user.name "github-actions"
208+
# git config user.email "[email protected]"
209+
# git commit -am "chore: start next development cycle $NEXT_VERSION [skip ci]"
210+
# git push origin HEAD:main

0 commit comments

Comments
 (0)