Skip to content

Commit 9aa5a0d

Browse files
authored
Chore: Update Action workflows, bump deps, update README (#8)
Update Action workflows to include a flow for manual releasing and automated publishing Update Gradle dependencies to latest--Gradle wrapper, kotlin, plugins, spigot-api Update README to include some basic instructions for using the template repo and example plugins
1 parent cc93c53 commit 9aa5a0d

File tree

10 files changed

+158
-74
lines changed

10 files changed

+158
-74
lines changed

.github/workflows/build-workflow.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,23 @@ on:
99
jobs:
1010
build:
1111
name: Gradle Build
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-22.04
1313
outputs:
1414
version: ${{ steps.version.outputs.version }}
1515
steps:
1616
- uses: actions/checkout@v3
17-
- uses: actions/setup-java@v2
1817
with:
19-
java-version: 17
20-
distribution: temurin
18+
fetch-depth: 0
2119
- uses: gradle/gradle-build-action@v2
2220
- name: Gradle Build
2321
run: ./gradlew build
2422
- name: Get Version
2523
id: version
26-
run: echo ::set-output name=version::"$(./gradlew --console plain --quiet currentVersion -Prelease.quiet)"
24+
run: echo "version=$(./gradlew --console plain --quiet currentVersion -Prelease.quiet)" >> $GITHUB_OUTPUT
2725
- name: Upload build
2826
uses: actions/upload-artifact@v3
2927
with:
3028
name: build
3129
path: build/libs/*.jar
3230
retention-days: 7
31+
if-no-files-found: error
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Publish
2+
on:
3+
push:
4+
branches: ['master', 'main']
5+
tags:
6+
- "v[0-9]+.[0-9]+.[0-9]+"
7+
8+
jobs:
9+
build:
10+
uses: ./.github/workflows/build-workflow.yml
11+
release:
12+
needs: build
13+
name: Create Release
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
- uses: gradle/gradle-build-action@v2
20+
- name: Download build
21+
uses: actions/download-artifact@v3
22+
with:
23+
name: build
24+
path: build
25+
- name: Release
26+
uses: docker://antonyurchenko/git-release:v5
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
RELEASE_NAME: ${{ needs.build.outputs.version }}
30+
PRE_RELEASE: ${{ github.ref_type == 'branch' }}
31+
UNRELEASED: ${{ github.ref_type == 'branch' && 'update' || '' }}
32+
UNRELEASED_TAG: latest-snapshot
33+
ALLOW_EMPTY_CHANGELOG: ${{ github.ref_type == 'branch' && 'true' || 'false' }}
34+
with:
35+
args: |
36+
build/*.jar
Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
1-
name: Release
1+
name: Create Release
2+
23
on:
3-
push:
4-
branches: ['master', 'main'] # TODO: master/main
5-
tags:
6-
- "v[0-9]+.[0-9]+.[0-9]+"
4+
workflow_dispatch:
5+
inputs:
6+
versionIncrementer:
7+
type: choice
8+
description: Override the default version incrementer according to https://axion-release-plugin.readthedocs.io/en/latest/configuration/version/#incrementing
9+
default: default
10+
options:
11+
- default
12+
- incrementPatch
13+
- incrementMinor
14+
- incrementMajor
15+
- incrementPrerelease
716

817
jobs:
9-
build:
10-
uses: ./.github/workflows/build-workflow.yml
1118
release:
12-
needs: build
13-
name: Create Release
14-
runs-on: ubuntu-latest
19+
name: Gradle Release
20+
runs-on: ubuntu-22.04
21+
outputs:
22+
version: ${{ steps.version.outputs.version }}
1523
steps:
1624
- uses: actions/checkout@v3
17-
- name: Download build
18-
uses: actions/download-artifact@v3
1925
with:
20-
name: build
21-
path: build
22-
- name: Release
23-
uses: docker://antonyurchenko/git-release:v4
26+
token: "${{ secrets.PAT }}"
27+
fetch-depth: 0
28+
- uses: gradle/gradle-build-action@v2
29+
- name: Gradle Release
30+
if: ${{ inputs.versionIncrementer == 'default' }}
2431
env:
25-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26-
RELEASE_NAME: ${{ needs.build.outputs.version }}
27-
PRE_RELEASE: ${{ github.ref_type == 'branch' }}
28-
UNRELEASED: ${{ github.ref_type == 'branch' && 'update' || '' }}
29-
UNRELEASED_TAG: latest-snapshot
30-
with:
31-
args: |
32-
build/*.jar
32+
DEPLOY_KEY: ${{ secrets.COMMIT_KEY }}
33+
run: ./gradlew release
34+
- name: Gradle Release w/ Increment Override
35+
if: ${{ inputs.versionIncrementer != 'default' }}
36+
env:
37+
DEPLOY_KEY: ${{ secrets.COMMIT_KEY }}
38+
run: ./gradlew release -Prelease.versionIncrementer=${{ inputs.versionIncrementer }}

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,39 @@ Opinionated template/starter for creating Minecraft plugins in Kotlin using the
44
## Features
55

66
- Gradle axion-release-plugin for managing semver
7-
- automatic updating of `CHANGELOG.md` and `main/resources/plugin.yml` when a release is made
7+
- automatic updating of `CHANGELOG.md` and `main/resources/plugin.yml` when a release is made
88
- Github Actions to build PRs and automatically create Github releases when a release tag is pushed
9+
- Manual Create Release pipeline to increment semver tag and trigger publishing a new version
10+
- Requires a secret named `PAT` with a GitHub PAT with code read/write permission to the repository
911
- [`ktlint`](https://github.com/JLLeitschuh/ktlint-gradle) Gradle plugin
1012
- Gradle build generates a standard plugin jar which will download dependencies declared as
1113
[`libraries`](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/plugin/PluginDescriptionFile.html#getLibraries()) in
1214
`plugin.yml` and an "offline"/shadowed jar containing necessary dependencies
15+
16+
## Usage
17+
18+
1. Use the template to create a new repository: [Create a new repository](https://github.com/SimpleMC/mc-kotlin-plugin-template/generate)
19+
2. Change template repository references
20+
- `settings.gradle.kts` -> set `rootProject.name`
21+
- `gradle.properties` -> set `repoRef`
22+
- `build.gradle.kts` -> set `group`
23+
- `CHANGELOG.md` -> update links to `SimpleMC/mc-kotlin-plugin-template` to match `repoRef`
24+
- `src/main/resources/plugin.yml` -> set `name`, `main`, `website`, `author`
25+
- `src/main/kotlin/org/simplemc/plugintemplate/KotlinPluginTemplate.kt` -> Move packages/rename for your plugin
26+
- `README.md` -> Update
27+
3. To use the Create Release automation, add PAT secret
28+
1. Create a Personal Access Token: https://github.com/settings/personal-access-tokens/new
29+
- Repository Access: "Only select repositories" and pick the plugin template fork
30+
- Repository Permissions: Contents Read & write
31+
- This is so the automation can create release commits
32+
2. Add the PAT as an Actions secret to your new repository: `https://github.com/<repo slug>/settings/secrets/actions/new`
33+
- Name: `PAT`
34+
- Secret Contents: Paste the Personal Access Token you created in the previous step
35+
36+
## Examples
37+
38+
Several SimpleMC plugins are built off of this template or were the impetus for it:
39+
40+
- [SimpleNPCs](https://github.com/SimpleMC/SimpleNPCs) - Simple command-based NPC interactions
41+
- [SimpleHealthbars2](https://github.com/SimpleMC/SimpleHealthbars2) - Simple, easy-to-use healthbar plugin with optional player and mob healthbars
42+
- [SimpleAnnounce](https://github.com/SimpleMC/SimpleAnnounce) - SimpleAnnounce is a simple and easy to use, yet powerful automated announcement plugin for the Bukkit Minecraft API.

build.gradle.kts

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocatio
22
import org.yaml.snakeyaml.DumperOptions
33
import org.yaml.snakeyaml.Yaml
44
import pl.allegro.tech.build.axion.release.domain.hooks.HookContext
5-
import pl.allegro.tech.build.axion.release.domain.hooks.HooksConfig
65
import java.time.OffsetDateTime
76
import java.time.ZoneOffset
87
import java.time.format.DateTimeFormatter
@@ -12,15 +11,15 @@ buildscript {
1211
mavenCentral()
1312
}
1413
dependencies {
15-
classpath("org.yaml:snakeyaml:1.30")
14+
classpath("org.yaml:snakeyaml:2.0")
1615
}
1716
}
1817

1918
plugins {
2019
kotlin("jvm")
21-
id("com.github.johnrengelman.shadow") version "7.1.2"
22-
id("pl.allegro.tech.build.axion-release") version "1.13.7"
23-
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
20+
id("com.github.johnrengelman.shadow") version "8.0.0"
21+
id("pl.allegro.tech.build.axion-release") version "1.14.4"
22+
id("org.jlleitschuh.gradle.ktlint") version "11.2.0"
2423
}
2524

2625
group = "org.simplemc"
@@ -32,29 +31,29 @@ val repoRef: String by project
3231
scmVersion {
3332
versionIncrementer("incrementMinorIfNotOnRelease", mapOf("releaseBranchPattern" to "release/.+"))
3433

35-
hooks(
36-
closureOf<HooksConfig> {
37-
pre(
38-
"fileUpdate",
39-
mapOf(
40-
"file" to "CHANGELOG.md",
41-
"pattern" to KotlinClosure2<String, HookContext, String>({ v, _ ->
42-
"\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z"
43-
}),
44-
"replacement" to KotlinClosure2<String, HookContext, String>({ v, c ->
45-
"""
46-
\[Unreleased\]
47-
48-
## \[$v\] - ${currentDateString()}$1
49-
\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/v$v...HEAD
50-
\[$v\]: https:\/\/github\.com\/$repoRef\/${if (c.previousVersion == v) "releases/tag/v$v" else "compare/v${c.previousVersion}...v$v"}${'$'}2
51-
""".trimIndent()
52-
})
53-
)
34+
hooks {
35+
// FIXME - workaround for Kotlin DSL issue https://github.com/allegro/axion-release-plugin/issues/500
36+
pre(
37+
"fileUpdate",
38+
mapOf(
39+
"file" to "CHANGELOG.md",
40+
"pattern" to KotlinClosure2<String, HookContext, String>({ v, _ ->
41+
"\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z"
42+
}),
43+
"replacement" to KotlinClosure2<String, HookContext, String>({ v, c ->
44+
"""
45+
\[Unreleased\]
46+
47+
## \[$v\] - ${currentDateString()}$1
48+
\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/v$v...HEAD
49+
\[$v\]: https:\/\/github\.com\/$repoRef\/${if (c.previousVersion == v) "releases/tag/v$v" else "compare/v${c.previousVersion}...v$v"}${'$'}2
50+
""".trimIndent()
51+
})
5452
)
55-
pre("commit")
56-
}
57-
)
53+
)
54+
55+
pre("commit")
56+
}
5857
}
5958

6059
fun currentDateString() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE)
@@ -78,7 +77,7 @@ dependencies {
7877

7978
tasks {
8079
wrapper {
81-
gradleVersion = "7.4.1"
80+
gradleVersion = "8.0.1"
8281
distributionType = Wrapper.DistributionType.ALL
8382
}
8483

@@ -99,8 +98,8 @@ tasks {
9998
val yamlDumpOptions =
10099
// make it pretty for the people
101100
DumperOptions().also {
102-
it.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
103-
it.setPrettyFlow(true)
101+
it.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK
102+
it.isPrettyFlow = true
104103
}
105104
val yaml = Yaml(yamlDumpOptions)
106105
val pluginYml: Map<String, Any> = yaml.load(file("$resourcesDir/plugin.yml").inputStream())
@@ -123,7 +122,7 @@ tasks {
123122
// avoid classpath conflicts/pollution via relocation
124123
val configureShadowRelocation by registering(ConfigureShadowRelocation::class) {
125124
target = shadowJar.get()
126-
prefix = "${project.group}.${project.name.toLowerCase()}.libraries"
125+
prefix = "${project.group}.${project.name.lowercase()}.libraries"
127126
}
128127

129128
build {

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
kotlin.code.style=official
22

3-
kotlinVersion=1.6.21
4-
mcApiVersion=1.18
3+
kotlinVersion=1.8.10
4+
mcApiVersion=1.19
55
repoRef=SimpleMC/mc-kotlin-plugin-template

gradle/wrapper/gradle-wrapper.jar

1.75 KB
Binary file not shown.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip
4+
networkTimeout=10000
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists

gradlew

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# Darwin, MinGW, and NonStop.
5656
#
5757
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
58+
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5959
# within the Gradle project.
6060
#
6161
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,10 +80,10 @@ do
8080
esac
8181
done
8282

83-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84-
85-
APP_NAME="Gradle"
83+
# This is normally unused
84+
# shellcheck disable=SC2034
8685
APP_BASE_NAME=${0##*/}
86+
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
8787

8888
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
8989
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
@@ -143,12 +143,16 @@ fi
143143
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144144
case $MAX_FD in #(
145145
max*)
146+
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147+
# shellcheck disable=SC3045
146148
MAX_FD=$( ulimit -H -n ) ||
147149
warn "Could not query maximum file descriptor limit"
148150
esac
149151
case $MAX_FD in #(
150152
'' | soft) :;; #(
151153
*)
154+
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155+
# shellcheck disable=SC3045
152156
ulimit -n "$MAX_FD" ||
153157
warn "Could not set maximum file descriptor limit to $MAX_FD"
154158
esac
@@ -205,6 +209,12 @@ set -- \
205209
org.gradle.wrapper.GradleWrapperMain \
206210
"$@"
207211

212+
# Stop when "xargs" is not available.
213+
if ! command -v xargs >/dev/null 2>&1
214+
then
215+
die "xargs is not available"
216+
fi
217+
208218
# Use "xargs" to parse quoted args.
209219
#
210220
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

gradlew.bat

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@rem limitations under the License.
1515
@rem
1616

17-
@if "%DEBUG%" == "" @echo off
17+
@if "%DEBUG%"=="" @echo off
1818
@rem ##########################################################################
1919
@rem
2020
@rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
2525
if "%OS%"=="Windows_NT" setlocal
2626

2727
set DIRNAME=%~dp0
28-
if "%DIRNAME%" == "" set DIRNAME=.
28+
if "%DIRNAME%"=="" set DIRNAME=.
29+
@rem This is normally unused
2930
set APP_BASE_NAME=%~n0
3031
set APP_HOME=%DIRNAME%
3132

@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4041

4142
set JAVA_EXE=java.exe
4243
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto execute
44+
if %ERRORLEVEL% equ 0 goto execute
4445

4546
echo.
4647
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
7576

7677
:end
7778
@rem End local scope for the variables with windows NT shell
78-
if "%ERRORLEVEL%"=="0" goto mainEnd
79+
if %ERRORLEVEL% equ 0 goto mainEnd
7980

8081
:fail
8182
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
8283
rem the _cmd.exe /c_ return code!
83-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84-
exit /b 1
84+
set EXIT_CODE=%ERRORLEVEL%
85+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
86+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87+
exit /b %EXIT_CODE%
8588

8689
:mainEnd
8790
if "%OS%"=="Windows_NT" endlocal

0 commit comments

Comments
 (0)