Skip to content

Commit cd66da3

Browse files
authored
Merge pull request #35 from simplecloudapp/feat/channel-based-publishing
Feat/channel based publishing
2 parents f8c50b7 + d338e50 commit cd66da3

File tree

5 files changed

+243
-44
lines changed

5 files changed

+243
-44
lines changed

.github/workflows/release.yml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Build and Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- develop # For snapshot builds
7+
- main # For release builds
8+
paths-ignore:
9+
- '**.md'
10+
- '.gitignore'
11+
- 'LICENSE'
12+
workflow_dispatch:
13+
inputs:
14+
channel:
15+
description: 'Release Channel'
16+
required: true
17+
default: 'snapshot'
18+
type: choice
19+
options:
20+
- snapshot
21+
- rc
22+
- release
23+
version:
24+
description: 'Version (only for release channel)'
25+
required: false
26+
type: string
27+
28+
jobs:
29+
build:
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: write
33+
steps:
34+
- name: Checkout Code
35+
uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 1
38+
39+
- name: Set up JDK 21
40+
uses: actions/setup-java@v4.7.0
41+
with:
42+
distribution: 'temurin'
43+
java-version: '21'
44+
cache: 'gradle'
45+
46+
- name: Set up Gradle
47+
uses: gradle/actions/setup-gradle@v4
48+
with:
49+
build-scan-publish: true
50+
build-scan-terms-of-use-url: 'https://gradle.com/help/legal-terms-of-use'
51+
build-scan-terms-of-use-agree: 'yes'
52+
53+
- name: Make Gradle Wrapper Executable
54+
run: chmod +x ./gradlew
55+
56+
- name: Determine Version and Channel
57+
id: version
58+
run: |
59+
# If triggered manually, use workflow input; otherwise, decide based on branch name
60+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
61+
CHANNEL="${{ github.event.inputs.channel }}"
62+
if [[ "$CHANNEL" == "release" && -n "${{ github.event.inputs.version }}" ]]; then
63+
VERSION="${{ github.event.inputs.version }}"
64+
fi
65+
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
66+
CHANNEL="release"
67+
else
68+
CHANNEL="snapshot"
69+
fi
70+
71+
# Get the commit hash (short version)
72+
COMMIT_HASH=$(git rev-parse --short HEAD)
73+
echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV
74+
75+
# Read the base version from gradle.properties
76+
BASE_VERSION=$(grep '^baseVersion=' gradle.properties | cut -d'=' -f2)
77+
if [ "$CHANNEL" == "release" ]; then
78+
FINAL_VERSION="$BASE_VERSION"
79+
elif [ "$CHANNEL" == "rc" ]; then
80+
FINAL_VERSION="${BASE_VERSION}-rc.${COMMIT_HASH}"
81+
else
82+
FINAL_VERSION="${BASE_VERSION}-SNAPSHOT.${COMMIT_HASH}"
83+
fi
84+
echo "Determined version: $FINAL_VERSION"
85+
86+
# Set outputs for later steps
87+
echo "CHANNEL=$CHANNEL" >> $GITHUB_OUTPUT
88+
echo "VERSION=$FINAL_VERSION" >> $GITHUB_OUTPUT
89+
90+
- name: Build with Gradle
91+
run: |
92+
./gradlew --parallel --build-cache clean build shadowJar \
93+
-PreleaseType=${{ steps.version.outputs.CHANNEL }} \
94+
-Pversion=${{ steps.version.outputs.VERSION }}
95+
env:
96+
COMMIT_HASH: ${{ env.COMMIT_HASH }}
97+
98+
- name: Publish to SimpleCloud Repository
99+
run: |
100+
if [[ "${{ steps.version.outputs.CHANNEL }}" == "release" ]]; then
101+
export GPG_TTY=$(tty)
102+
export GRADLE_OPTS="-Dorg.gradle.daemon=false"
103+
./gradlew --no-daemon --parallel --build-cache publishMavenJavaPublicationToSimplecloudRepository \
104+
-PreleaseType=${{ steps.version.outputs.CHANNEL }} \
105+
-Pversion=${{ steps.version.outputs.VERSION }} \
106+
-Psigning.gnupg.keyName="${{ secrets.GPG_PRIVATE_KEY }}" \
107+
-Psigning.gnupg.passphrase="${{ secrets.GPG_PASSPHRASE }}"
108+
else
109+
./gradlew --parallel --build-cache publishMavenJavaPublicationToSimplecloudRepository \
110+
-PreleaseType=${{ steps.version.outputs.CHANNEL }} \
111+
-Pversion=${{ steps.version.outputs.VERSION }}
112+
fi
113+
env:
114+
COMMIT_HASH: ${{ env.COMMIT_HASH }}
115+
SIMPLECLOUD_USERNAME: ${{ secrets.SIMPLECLOUD_USERNAME }}
116+
SIMPLECLOUD_PASSWORD: ${{ secrets.SIMPLECLOUD_PASSWORD }}
117+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_PRIVATE_KEY }}
118+
ORG_GRADLE_PROJECT_signingPassphrase: ${{ secrets.GPG_PASSPHRASE }}
119+
120+
- name: Prepare Artifacts
121+
run: |
122+
mkdir -p release-artifacts
123+
find . -type f -name "*.jar" -path "*/build/libs/*.jar" -not -path "./build/libs/*" \
124+
-not -name "*${{ steps.version.outputs.VERSION }}*" \
125+
-exec cp {} release-artifacts/ \;
126+
127+
- name: Update Channel Tag
128+
run: |
129+
git config user.name "GitHub Actions"
130+
git config user.email "actions@github.com"
131+
# Delete any existing channel tag locally and remotely
132+
git tag -d ${{ steps.version.outputs.CHANNEL }} || true
133+
git push origin :refs/tags/${{ steps.version.outputs.CHANNEL }} || true
134+
# Create a new tag at the current commit
135+
git tag -a ${{ steps.version.outputs.CHANNEL }} -m "Latest ${{ steps.version.outputs.CHANNEL }} build (v${{ steps.version.outputs.VERSION }})"
136+
git push origin ${{ steps.version.outputs.CHANNEL }} --force
137+
138+
- name: Create Channel Release
139+
uses: softprops/action-gh-release@v2
140+
with:
141+
name: "${{ steps.version.outputs.CHANNEL }} channel"
142+
tag_name: ${{ steps.version.outputs.CHANNEL }}
143+
body: |
144+
Latest build in the ${{ steps.version.outputs.CHANNEL }} channel.
145+
Version: ${{ steps.version.outputs.VERSION }}
146+
Commit: ${{ github.sha }}
147+
prerelease: ${{ steps.version.outputs.CHANNEL != 'release' }}
148+
files: release-artifacts/*.jar
149+
env:
150+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build.gradle.kts

Lines changed: 78 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23

34
plugins {
45
alias(libs.plugins.kotlin)
@@ -7,13 +8,9 @@ plugins {
78
`maven-publish`
89
}
910

10-
val baseVersion = "0.0.30"
11-
val commitHash = System.getenv("COMMIT_HASH")
12-
val snapshotversion = "${baseVersion}-dev.$commitHash"
13-
1411
allprojects {
1512
group = "app.simplecloud.controller"
16-
version = if (commitHash != null) snapshotversion else baseVersion
13+
version = determineVersion()
1714

1815
repositories {
1916
mavenCentral()
@@ -33,51 +30,35 @@ subprojects {
3330
implementation(rootProject.libs.kotlin.jvm)
3431
}
3532

36-
publishing {
37-
repositories {
38-
maven {
39-
name = "simplecloud"
40-
url = uri("https://repo.simplecloud.app/snapshots/")
41-
credentials {
42-
username = System.getenv("SIMPLECLOUD_USERNAME")?: (project.findProperty("simplecloudUsername") as? String)
43-
password = System.getenv("SIMPLECLOUD_PASSWORD")?: (project.findProperty("simplecloudPassword") as? String)
44-
}
45-
authentication {
46-
create<BasicAuthentication>("basic")
47-
}
48-
}
49-
}
50-
51-
publications {
52-
// Not publish controller-runtime
53-
if (project.name == "controller-runtime") {
54-
return@publications
55-
}
56-
57-
create<MavenPublication>("mavenJava") {
58-
from(components["java"])
59-
}
60-
}
61-
}
62-
6333
java {
6434
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
6535
}
6636

6737
kotlin {
6838
jvmToolchain(21)
39+
6940
compilerOptions {
41+
languageVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0)
7042
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0)
43+
jvmTarget.set(JvmTarget.JVM_21)
7144
}
7245
}
7346

74-
tasks.named("shadowJar", ShadowJar::class) {
75-
mergeServiceFiles()
76-
archiveFileName.set("${project.name}.jar")
77-
}
47+
tasks {
48+
withType<JavaCompile> {
49+
options.isFork = true
50+
options.isIncremental = true
51+
}
52+
53+
named("shadowJar", ShadowJar::class) {
54+
mergeServiceFiles()
7855

79-
tasks.test {
80-
useJUnitPlatform()
56+
archiveFileName.set("${project.name}.jar")
57+
}
58+
59+
test {
60+
useJUnitPlatform()
61+
}
8162
}
8263

8364
centralPortal {
@@ -89,7 +70,7 @@ subprojects {
8970
pom {
9071
name.set("SimpleCloud controller")
9172
description.set("The heart of SimpleCloud v3")
92-
url.set("https://github.com/theSimpleCloud/simplecloud-controller")
73+
url.set("https://github.com/simplecloudapp/simplecloud-controller")
9374

9475
developers {
9576
developer {
@@ -108,18 +89,72 @@ subprojects {
10889
}
10990
}
11091
scm {
111-
url.set("https://github.com/theSimpleCloud/simplecloud-controller.git")
112-
connection.set("git:git@github.com:theSimpleCloud/simplecloud-controller.git")
92+
url.set("https://github.com/simplecloudapp/simplecloud-controller.git")
93+
connection.set("git:git@github.com:simplecloudapp/simplecloud-controller.git")
94+
}
95+
}
96+
}
97+
98+
publishing {
99+
repositories {
100+
maven {
101+
name = "simplecloud"
102+
url = uri(determineRepositoryUrl())
103+
credentials {
104+
username = System.getenv("SIMPLECLOUD_USERNAME")
105+
?: (project.findProperty("simplecloudUsername") as? String)
106+
password = System.getenv("SIMPLECLOUD_PASSWORD")
107+
?: (project.findProperty("simplecloudPassword") as? String)
108+
}
109+
authentication {
110+
create<BasicAuthentication>("basic")
111+
}
112+
}
113+
}
114+
115+
publications {
116+
create<MavenPublication>("mavenJava") {
117+
from(components["java"])
113118
}
114119
}
115120
}
116121

117122
signing {
118-
if (commitHash != null) {
123+
val releaseType = project.findProperty("releaseType")?.toString() ?: "snapshot"
124+
if (releaseType != "release") {
119125
return@signing
120126
}
121127

128+
if (hasProperty("signingPassphrase")) {
129+
val signingKey: String? by project
130+
val signingPassphrase: String? by project
131+
useInMemoryPgpKeys(signingKey, signingPassphrase)
132+
} else {
133+
useGpgCmd()
134+
}
135+
122136
sign(publishing.publications)
123-
useGpgCmd()
137+
}
138+
}
139+
140+
fun determineVersion(): String {
141+
val baseVersion = project.findProperty("baseVersion")?.toString() ?: "0.0.0"
142+
val releaseType = project.findProperty("releaseType")?.toString() ?: "snapshot"
143+
val commitHash = System.getenv("COMMIT_HASH") ?: "local"
144+
145+
return when (releaseType) {
146+
"release" -> baseVersion
147+
"rc" -> "$baseVersion-rc.$commitHash"
148+
"snapshot" -> "$baseVersion-SNAPSHOT.$commitHash"
149+
else -> "$baseVersion-SNAPSHOT.local"
150+
}
151+
}
152+
153+
fun determineRepositoryUrl(): String {
154+
val baseUrl = "https://repo.simplecloud.app/"
155+
return when (project.findProperty("releaseType")?.toString() ?: "snapshot") {
156+
"release" -> "$baseUrl/releases"
157+
"rc" -> "$baseUrl/rc"
158+
else -> "$baseUrl/snapshots"
124159
}
125160
}

controller-api/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ dependencies {
66

77
tasks.named("shadowJar", ShadowJar::class) {
88
mergeServiceFiles()
9+
910
relocate("com", "app.simplecloud.external.com")
1011
relocate("google", "app.simplecloud.external.google")
1112
relocate("io", "app.simplecloud.external.io")
1213
relocate("org", "app.simplecloud.external.org")
1314
relocate("javax", "app.simplecloud.external.javax")
1415
relocate("android", "app.simplecloud.external.android")
1516
relocate("build.buf.gen.simplecloud", "app.simplecloud.buf")
17+
1618
archiveFileName.set("${project.name}.jar")
1719
}

controller-runtime/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ dependencies {
88
api(project(":controller-shared"))
99
api(libs.bundles.jooq)
1010
api(libs.sqlite.jdbc)
11-
jooqCodegen(libs.jooq.meta.extensions)
11+
1212
implementation(libs.simplecloud.metrics)
1313
implementation(libs.bundles.log4j)
1414
implementation(libs.clikt)
1515
implementation(libs.spring.crypto)
1616
implementation(libs.spotify.completablefutures)
1717
implementation(libs.envoy.controlplane)
18+
19+
jooqCodegen(libs.jooq.meta.extensions)
1820
}
1921

2022
application {

gradle.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
baseVersion=0.0.30
2+
org.gradle.parallel=true
3+
org.gradle.caching=true
4+
org.gradle.configureondemand=true
5+
org.gradle.daemon=true
6+
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError
7+
kotlin.incremental=true
8+
kotlin.incremental.js=true
9+
kotlin.caching.enabled=true
10+
kotlin.parallel.tasks.in.project=true

0 commit comments

Comments
 (0)