Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Build and Publish Release
on:
push:
tags:
- '*'
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: gradle
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
# build
- name: Build with Gradle Wrapper
run: ./gradlew assemble
env:
MVNDI_MVN_USER: ${{ secrets.MVNDI_MVN_USER }}
MVNDI_MVN_KEY: ${{ secrets.MVNDI_MVN_KEY }}
- name: Publish to Remote
run: ./gradlew publish
env:
MVNDI_MVN_USER: ${{ secrets.MVNDI_MVN_USER }}
MVNDI_MVN_KEY: ${{ secrets.MVNDI_MVN_KEY }}

- name: Get version & release name
id: version
run: |
echo "version=$(./gradlew -q echoVersion)" >> $GITHUB_OUTPUT
echo "releaseName=$(./gradlew -q echoReleaseName)" >> $GITHUB_OUTPUT

- name: Print version & release name
run: |
echo "Version: ${{ steps.version.outputs.version }}"
echo "Release Name: ${{ steps.version.outputs.releaseName }}"


- name: Create an empty CHANGELOG.md if missing
run: |
if [ ! -f CHANGELOG.md ]; then
touch CHANGELOG.md
fi

- name: Read the first lines of CHANGELOG.md from gradle
id: changelog
run: |
{
echo "changelog<<EOF"
./gradlew -q echoLatestVersionChangelog
echo "EOF"
} >> $GITHUB_OUTPUT


- name: Create Release
id: createRelease
uses: ncipollo/release-action@v1.14.0
with:
allowUpdates: true
updateOnlyUnreleased: true
artifacts: build/libs/${{ github.event.repository.name }}-${{ steps.version.outputs.version }}.jar
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.releaseName }}
body: ${{ steps.changelog.outputs.changelog }}
# prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }} #Always release for now
skipIfReleaseExists: true

# - name: Publish to hangar & modrinth
# env:
# # Make sure you have added the repository secrets in the repository's settings
# HANGAR_API_TOKEN: ${{ secrets.HANGAR_API_TOKEN }}
# MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
# run: ./gradlew assemble publishPluginPublicationToHangar modrinth
86 changes: 86 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ tasks.named<ShadowJar>("shadowJar") {
archiveClassifier = null;
}

publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
}

tasks {
assemble {
dependsOn(shadowJar)
Expand Down Expand Up @@ -78,3 +84,83 @@ java {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
}

tasks.register("echoVersion") {
group = "documentation"
description = "Displays the version."
doLast {
println("${project.version}")
}
}

tasks.register("echoReleaseName") {
group = "documentation"
description = "Displays the release name."
doLast {
println("${project.version} [${supportedMinecraftVersions}]")
}
}

val extractChangelog = tasks.register("extractChangelog") {
group = "documentation"
description = "Extracts the changelog for the current project version from CHANGELOG.md, including the version header."

val changelog: Property<String> = project.objects.property(String::class)
outputs.upToDateWhen { false }

doLast {
val version = project.version.toString()
val changelogFile = project.file("CHANGELOG.md")

if (!changelogFile.exists()) {
println("CHANGELOG.md not found.")
changelog.set("No changelog found.")
return@doLast
}

val lines = changelogFile.readLines()
val entries = mutableListOf<String>()
var foundVersion = false

for (line in lines) {
when {
// Include the version line itself
line.trim().equals("# $version", ignoreCase = true) -> {
foundVersion = true
entries.add(line)
}
// Stop collecting at the next version header
foundVersion && line.trim().startsWith("# ") -> break
// Collect lines after the version header
foundVersion -> entries.add(line)
}
}

val result = if (entries.isEmpty()) {
"Update to $version."
} else {
entries.joinToString("\n").trim()
}

// println("Changelog for version $version:\n$result")
changelog.set(result)
}

// Make changelog accessible from other tasks
extensions.add(Property::class.java, "changelog", changelog)
}

tasks.register("echoLatestVersionChangelog") {
group = "documentation"
description = "Displays the latest version change."

dependsOn(tasks.named("extractChangelog"))

doLast {
println((extractChangelog.get().extensions.findByType(Property::class.java) as Property<String>).get())
}
}


val versionString: String = version as String
val isRelease: Boolean = !versionString.contains("SNAPSHOT")
Loading