Skip to content

Commit 94df934

Browse files
committed
Add deployment workflow
1 parent 0029a44 commit 94df934

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

.github/workflows/deploy.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Deploy
2+
on: push
3+
4+
jobs:
5+
deploy:
6+
name: deploy
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
- name: Set up Java & Gradle
12+
uses: actions/setup-java@v4
13+
with:
14+
java-version: 21
15+
distribution: temurin
16+
cache: gradle
17+
- name: Compute version
18+
id: compute-version
19+
env:
20+
SNAPSHOT_VERSION_SUFFIX: -SNAPSHOT
21+
REF: ${{ github.ref_name == github.event.repository.default_branch && format('-{0}', github.ref_name) || '' }}
22+
run: |
23+
# Get current version of project
24+
version=$(gradle printVersion -q --console=plain)
25+
# Check if version ends with snapshot suffix
26+
if [ ${version:(-${#SNAPSHOT_VERSION_SUFFIX})} ]; then
27+
# Insert ref before snapshot suffix
28+
version=${version%$SNAPSHOT_VERSION_SUFFIX}$REF$SNAPSHOT_VERSION_SUFFIX
29+
else
30+
# Append ref to the version
31+
version=$version$REF
32+
fi
33+
# Save computed version
34+
echo "version=$version" >> "$GITHUB_OUTPUT"
35+
- name: Gradle build
36+
run: gradle -Pversion=${{ steps.compute-version.outputs.version }} build
37+
- name: Gradle publish
38+
env:
39+
PUBLISH_USERNAME: ${{ secrets.PUBLISH_USERNAME }}
40+
PUBLISH_PASSWORD: ${{ secrets.PUBLISH_PASSWORD }}
41+
run: gradle -Pversion=${{ steps.compute-version.outputs.version }} publish

build.gradle.kts

+18-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ plugins {
77
}
88

99
group = "dev.bazhard.library"
10-
version = "1.0.0-SNAPSHOT"
1110
description = "A 3D GUI library for Minecraft plugins"
1211

1312
java {
@@ -30,24 +29,24 @@ publishing {
3029
name = "snapshot"
3130
url = uri("https://repo.bazhard.dev/repository/maven-snapshots/")
3231
credentials {
33-
username = mavenCredentials?.first ?: ""
34-
password = mavenCredentials?.second ?: ""
32+
username = mavenCredentials?.first ?: System.getenv("PUBLISH_USERNAME") ?: ""
33+
password = mavenCredentials?.second ?: System.getenv("PUBLISH_PASSWORD") ?: ""
3534
}
3635
}
3736
maven {
3837
name = "release"
3938
url = uri("https://repo.bazhard.dev/repository/maven-releases/")
4039
credentials {
41-
username = mavenCredentials?.first ?: ""
42-
password = mavenCredentials?.second ?: ""
40+
username = mavenCredentials?.first ?: System.getenv("PUBLISH_USERNAME") ?: ""
41+
password = mavenCredentials?.second ?: System.getenv("PUBLISH_PASSWORD") ?: ""
4342
}
4443
}
4544
}
4645
}
4746

4847
repositories {
4948
mavenCentral()
50-
maven( "https://repo.dmulloy2.net/repository/public/") // Required for ProtocolLib
49+
maven("https://repo.dmulloy2.net/repository/public/") // Required for ProtocolLib
5150
maven("https://repo.papermc.io/repository/maven-public/")
5251
}
5352

@@ -72,6 +71,18 @@ tasks {
7271
}
7372
}
7473

74+
tasks.withType<PublishToMavenRepository>().configureEach {
75+
onlyIf("publishing snapshots to the snapshot repository and releases to the release repository") {
76+
repository == publishing.repositories[if (version.toString().endsWith("-SNAPSHOT")) "snapshot" else "release"]
77+
}
78+
}
79+
80+
tasks.register("printVersion") {
81+
doLast {
82+
println(project.version)
83+
}
84+
}
85+
7586
fun getMavenCredentials(serverId: String): Pair<String, String>? {
7687
val settingsFile = File(System.getProperty("user.home"), ".m2/settings.xml")
7788
if (!settingsFile.exists()) {
@@ -92,4 +103,4 @@ fun getMavenCredentials(serverId: String): Pair<String, String>? {
92103
}
93104
}
94105
return null
95-
}
106+
}

gradle.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Project version
2+
version=1.0.0-SNAPSHOT

0 commit comments

Comments
 (0)