Skip to content

Commit

Permalink
Chore: Update Action workflows, bump deps, update README (#8)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tajobe authored Mar 4, 2023
1 parent cc93c53 commit 9aa5a0d
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 74 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@ on:
jobs:
build:
name: Gradle Build
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v2
with:
java-version: 17
distribution: temurin
fetch-depth: 0
- uses: gradle/gradle-build-action@v2
- name: Gradle Build
run: ./gradlew build
- name: Get Version
id: version
run: echo ::set-output name=version::"$(./gradlew --console plain --quiet currentVersion -Prelease.quiet)"
run: echo "version=$(./gradlew --console plain --quiet currentVersion -Prelease.quiet)" >> $GITHUB_OUTPUT
- name: Upload build
uses: actions/upload-artifact@v3
with:
name: build
path: build/libs/*.jar
retention-days: 7
if-no-files-found: error
36 changes: 36 additions & 0 deletions .github/workflows/publish-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gradle/gradle-build-action@v2
- name: Download build
uses: actions/download-artifact@v3
with:
name: build
path: build
- name: Release
uses: docker://antonyurchenko/git-release:v5
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
54 changes: 30 additions & 24 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
name: Release
name: Create Release

on:
push:
branches: ['master', 'main'] # TODO: master/main
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
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:
build:
uses: ./.github/workflows/build-workflow.yml
release:
needs: build
name: Create Release
runs-on: ubuntu-latest
name: Gradle Release
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
- name: Download build
uses: actions/download-artifact@v3
with:
name: build
path: build
- name: Release
uses: docker://antonyurchenko/git-release:v4
token: "${{ secrets.PAT }}"
fetch-depth: 0
- uses: gradle/gradle-build-action@v2
- name: Gradle Release
if: ${{ inputs.versionIncrementer == 'default' }}
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
with:
args: |
build/*.jar
DEPLOY_KEY: ${{ secrets.COMMIT_KEY }}
run: ./gradlew release
- name: Gradle Release w/ Increment Override
if: ${{ inputs.versionIncrementer != 'default' }}
env:
DEPLOY_KEY: ${{ secrets.COMMIT_KEY }}
run: ./gradlew release -Prelease.versionIncrementer=${{ inputs.versionIncrementer }}
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,39 @@ Opinionated template/starter for creating Minecraft plugins in Kotlin using the
## Features

- Gradle axion-release-plugin for managing semver
- automatic updating of `CHANGELOG.md` and `main/resources/plugin.yml` when a release is made
- automatic updating of `CHANGELOG.md` and `main/resources/plugin.yml` when a release is made
- Github Actions to build PRs and automatically create Github releases when a release tag is pushed
- Manual Create Release pipeline to increment semver tag and trigger publishing a new version
- Requires a secret named `PAT` with a GitHub PAT with code read/write permission to the repository
- [`ktlint`](https://github.com/JLLeitschuh/ktlint-gradle) Gradle plugin
- Gradle build generates a standard plugin jar which will download dependencies declared as
[`libraries`](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/plugin/PluginDescriptionFile.html#getLibraries()) in
`plugin.yml` and an "offline"/shadowed jar containing necessary dependencies

## Usage

1. Use the template to create a new repository: [Create a new repository](https://github.com/SimpleMC/mc-kotlin-plugin-template/generate)
2. Change template repository references
- `settings.gradle.kts` -> set `rootProject.name`
- `gradle.properties` -> set `repoRef`
- `build.gradle.kts` -> set `group`
- `CHANGELOG.md` -> update links to `SimpleMC/mc-kotlin-plugin-template` to match `repoRef`
- `src/main/resources/plugin.yml` -> set `name`, `main`, `website`, `author`
- `src/main/kotlin/org/simplemc/plugintemplate/KotlinPluginTemplate.kt` -> Move packages/rename for your plugin
- `README.md` -> Update
3. To use the Create Release automation, add PAT secret
1. Create a Personal Access Token: https://github.com/settings/personal-access-tokens/new
- Repository Access: "Only select repositories" and pick the plugin template fork
- Repository Permissions: Contents Read & write
- This is so the automation can create release commits
2. Add the PAT as an Actions secret to your new repository: `https://github.com/<repo slug>/settings/secrets/actions/new`
- Name: `PAT`
- Secret Contents: Paste the Personal Access Token you created in the previous step

## Examples

Several SimpleMC plugins are built off of this template or were the impetus for it:

- [SimpleNPCs](https://github.com/SimpleMC/SimpleNPCs) - Simple command-based NPC interactions
- [SimpleHealthbars2](https://github.com/SimpleMC/SimpleHealthbars2) - Simple, easy-to-use healthbar plugin with optional player and mob healthbars
- [SimpleAnnounce](https://github.com/SimpleMC/SimpleAnnounce) - SimpleAnnounce is a simple and easy to use, yet powerful automated announcement plugin for the Bukkit Minecraft API.
61 changes: 30 additions & 31 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocatio
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
Expand All @@ -12,15 +11,15 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.yaml:snakeyaml:1.30")
classpath("org.yaml:snakeyaml:2.0")
}
}

plugins {
kotlin("jvm")
id("com.github.johnrengelman.shadow") version "7.1.2"
id("pl.allegro.tech.build.axion-release") version "1.13.7"
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
id("com.github.johnrengelman.shadow") version "8.0.0"
id("pl.allegro.tech.build.axion-release") version "1.14.4"
id("org.jlleitschuh.gradle.ktlint") version "11.2.0"
}

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

hooks(
closureOf<HooksConfig> {
pre(
"fileUpdate",
mapOf(
"file" to "CHANGELOG.md",
"pattern" to KotlinClosure2<String, HookContext, String>({ v, _ ->
"\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z"
}),
"replacement" to KotlinClosure2<String, HookContext, String>({ v, c ->
"""
\[Unreleased\]
## \[$v\] - ${currentDateString()}$1
\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/v$v...HEAD
\[$v\]: https:\/\/github\.com\/$repoRef\/${if (c.previousVersion == v) "releases/tag/v$v" else "compare/v${c.previousVersion}...v$v"}${'$'}2
""".trimIndent()
})
)
hooks {
// FIXME - workaround for Kotlin DSL issue https://github.com/allegro/axion-release-plugin/issues/500
pre(
"fileUpdate",
mapOf(
"file" to "CHANGELOG.md",
"pattern" to KotlinClosure2<String, HookContext, String>({ v, _ ->
"\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z"
}),
"replacement" to KotlinClosure2<String, HookContext, String>({ v, c ->
"""
\[Unreleased\]
## \[$v\] - ${currentDateString()}$1
\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/v$v...HEAD
\[$v\]: https:\/\/github\.com\/$repoRef\/${if (c.previousVersion == v) "releases/tag/v$v" else "compare/v${c.previousVersion}...v$v"}${'$'}2
""".trimIndent()
})
)
pre("commit")
}
)
)

pre("commit")
}
}

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

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

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

build {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kotlin.code.style=official

kotlinVersion=1.6.21
mcApiVersion=1.18
kotlinVersion=1.8.10
mcApiVersion=1.19
repoRef=SimpleMC/mc-kotlin-plugin-template
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 14 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,10 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

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

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
Expand Down Expand Up @@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -205,6 +209,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

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

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

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

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down

0 comments on commit 9aa5a0d

Please sign in to comment.