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
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
charset = utf-8
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,kts}]
ktlint_code_style = intellij_idea

[*{.yml,yaml}]
indent_style = space
indent_size = 2
37 changes: 37 additions & 0 deletions .github/workflows/build-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build
on:
workflow_call:
outputs:
version:
description: Built version
value: ${{ jobs.build.outputs.version }}

jobs:
build:
name: Gradle Build
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Gradle Build
run: ./gradlew build shadowJar
- name: Get Version
id: version
run: echo "version=$(./gradlew --console plain --quiet currentVersion -Prelease.quiet)" >> $GITHUB_OUTPUT
- name: Upload build
uses: actions/upload-artifact@v4
with:
name: build
path: build/libs/*.jar
retention-days: 7
if-no-files-found: error
42 changes: 42 additions & 0 deletions .github/workflows/create-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Create Version

on:
workflow_dispatch:
inputs:
versionIncrementer:
type: choice
description: Override the default version incrementer according to https://axion-release-plugin.readthedocs.io/en/latest/configuration/version/#incrementing
default: default
options:
- default
- incrementPatch
- incrementMinor
- incrementMajor
- incrementPrerelease

jobs:
release:
name: Gradle Release
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
ssh-key: "${{ secrets.COMMIT_KEY }}"
fetch-depth: 0
- uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.COMMIT_KEY }}
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- uses: gradle/actions/setup-gradle@v4
- name: Gradle Release
if: ${{ inputs.versionIncrementer == 'default' }}
run: ./gradlew release
- name: Gradle Release w/ Increment Override
if: ${{ inputs.versionIncrementer != 'default' }}
run: ./gradlew release -Prelease.versionIncrementer=${{ inputs.versionIncrementer }}
12 changes: 1 addition & 11 deletions .github/workflows/pr-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,4 @@ on: pull_request

jobs:
build:
name: Gradle Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v2
with:
java-version: 17
distribution: temurin
- uses: gradle/gradle-build-action@v2
with:
arguments: build
uses: ./.github/workflows/build-workflow.yml
32 changes: 32 additions & 0 deletions .github/workflows/publish-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Publish
on:
push:
branches: ['master', 'main']
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
build:
uses: ./.github/workflows/build-workflow.yml
release:
needs: build
name: Create Release
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Download build
uses: actions/download-artifact@v4
with:
name: build
path: build
- name: Release
uses: docker://antonyurchenko/git-release:v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: ${{ needs.build.outputs.version }}
PRE_RELEASE: ${{ github.ref_type == 'branch' }}
UNRELEASED: ${{ github.ref_type == 'branch' && 'update' || '' }}
UNRELEASED_TAG: latest-snapshot
ALLOW_EMPTY_CHANGELOG: ${{ github.ref_type == 'branch' && 'true' || 'false' }}
with:
args: build/*.jar
37 changes: 0 additions & 37 deletions .github/workflows/release-workflow.yml

This file was deleted.

8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Changelog

## [Unreleased]

### Changed
- Update gradle to 7.4
- Update to Spigot/MC 1.18
- Update to Java 17
- Merged template SimpleMC/mc-kotlin-plugin-template
- MC 1.21, Kotlin 2.1, Gradle 8
- Release tag prefix changed from `release-` to `v`

## [0.1.0] - 2020-02-16

### Added
- Initial Release

Expand Down
157 changes: 71 additions & 86 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,127 +1,112 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
import pl.allegro.tech.build.axion.release.domain.hooks.HookContext
import pl.allegro.tech.build.axion.release.domain.hooks.HooksConfig
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter

plugins {
kotlin("jvm") version "1.6.10"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("pl.allegro.tech.build.axion-release") version "1.13.6"
id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
alias(libs.plugins.axionRelease)
alias(libs.plugins.kotlin)
alias(libs.plugins.ktlint)
alias(libs.plugins.shadow)
}

val repoRef = "SimpleMC\\/SimpleNPCs"
val mcApiVersion = "1.18"

group = "org.simplemc"
version = scmVersion.version

scmVersion {
versionIncrementer("incrementMinorIfNotOnRelease", mapOf("releaseBranchPattern" to "release/.+"))
unshallowRepoOnCI.set(true)

hooks {
// Automate moving `[Unreleased]` changelog entries into `[<version>]` on release
// FIXME - workaround for Kotlin DSL issue https://github.com/allegro/axion-release-plugin/issues/500
val changelogPattern =
"\\[Unreleased\\]([\\s\\S]+?)\\n" +
"(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/(\\S+\\/\\S+)\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z"
pre(
"fileUpdate",
mapOf(
"file" to "CHANGELOG.md",
"pattern" to KotlinClosure2<String, HookContext, String>({ _, _ -> changelogPattern }),
"replacement" to KotlinClosure2<String, HookContext, String>({ version, context ->
// github "diff" for previous version
val previousVersionDiffLink =
when (context.previousVersion == version) {
true -> "releases/tag/v$version" // no previous, just link to the version
false -> "compare/v${context.previousVersion}...v$version"
}
"""
\[Unreleased\]

## \[$version\] - $currentDateString$1
\[Unreleased\]: https:\/\/github\.com\/$2\/compare\/v$version...HEAD
\[$version\]: https:\/\/github\.com\/$2\/$previousVersionDiffLink$3
""".trimIndent()
}),
),
)

hooks(
closureOf<HooksConfig> {
// "normal" changelog update--changelog already contains a history
pre(
"fileUpdate",
mapOf(
"file" to "CHANGELOG.md",
"pattern" to KotlinClosure2<String, HookContext, String>({ v, _ ->
"\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/release-$v\\.\\.\\.HEAD\$([\\s\\S]*))?\\z"
}),
"replacement" to KotlinClosure2<String, HookContext, String>({ v, c ->
"""
\[Unreleased\]

## \[$v\] - ${currentDateString()}$1
\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/release-$v...HEAD
\[$v\]: https:\/\/github\.com\/$repoRef\/compare\/release-${c.previousVersion}...release-$v$2
""".trimIndent()
})
)
)
// first-time changelog update--changelog has only unreleased info
pre(
"fileUpdate",
mapOf(
"file" to "CHANGELOG.md",
"pattern" to KotlinClosure2<String, HookContext, String>({ _, _ ->
"Unreleased([\\s\\S]+?\\nand this project adheres to \\[Semantic Versioning\\]\\(https:\\/\\/semver\\.org\\/spec\\/v2\\.0\\.0\\.html\\).)\\s\\z"
}),
"replacement" to KotlinClosure2<String, HookContext, String>({ v, _ ->
"""
\[Unreleased\]

## \[$v\] - ${currentDateString()}$1

\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/release-$v...HEAD
\[$v\]: https:\/\/github\.com\/$repoRef\/releases\/tag\/release-$v
""".trimIndent()
})
)
)
pre("commit")
}
)
pre("commit")
}
}

fun currentDateString() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE)
group = "org.simplemc"
version = scmVersion.version

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
val currentDateString: String
get() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE)

repositories {
mavenCentral()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/repositories/snapshots")
kotlin {
jvmToolchain(21)
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
compileOnly(group = "org.spigotmc", name = "spigot-api", version = "$mcApiVersion+")
compileOnly(libs.spigot)
}

tasks {
wrapper {
gradleVersion = "7.4.1"
distributionType = Wrapper.DistributionType.ALL
}

processResources {
val placeholders = mapOf(
"version" to version,
"apiVersion" to mcApiVersion
"apiVersion" to libs.versions.mcApi.get(),
"kotlinVersion" to libs.versions.kotlin.get(),
)

filesMatching("plugin.yml") {
expand(placeholders)
}

// create an "offline" copy/variant of the plugin.yml with `libraries` omitted
doLast {
val resourcesDir = sourceSets.main.get().output.resourcesDir
val yamlDumpOptions =
// make it pretty for the people
DumperOptions().also {
it.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK
it.isPrettyFlow = true
}
val yaml = Yaml(yamlDumpOptions)
val pluginYml: Map<String, Any> = yaml.load(file("$resourcesDir/plugin.yml").inputStream())
yaml.dump(pluginYml.filterKeys { it != "libraries" }, file("$resourcesDir/offline-plugin.yml").writer())
}
}

// standard jar should be ready to go with all dependencies
shadowJar {
minimize()
archiveClassifier.set("")
jar {
exclude("offline-plugin.yml")
}

// nokt jar without the kotlin runtime
register<ShadowJar>("nokt") {
// offline jar should be ready to go with all dependencies
shadowJar {
minimize()
archiveClassifier.set("nokt")
from(sourceSets.main.get().output)
configurations = listOf(project.configurations.runtimeClasspath.get())

dependencies {
exclude(dependency("org.jetbrains.*:"))
}
}
archiveClassifier.set("offline")
exclude("plugin.yml")
rename("offline-plugin.yml", "plugin.yml")

build {
dependsOn(":shadowJar", ":nokt")
// avoid classpath conflicts/pollution via relocation
isEnableRelocation = true
relocationPrefix = "${project.group}.${project.name.lowercase()}.libraries"
}
}
Loading