diff --git a/.github/workflows/build-workflow.yml b/.github/workflows/build-workflow.yml index 615931e..34003af 100644 --- a/.github/workflows/build-workflow.yml +++ b/.github/workflows/build-workflow.yml @@ -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 diff --git a/.github/workflows/publish-workflow.yml b/.github/workflows/publish-workflow.yml new file mode 100644 index 0000000..7232470 --- /dev/null +++ b/.github/workflows/publish-workflow.yml @@ -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 diff --git a/.github/workflows/release-workflow.yml b/.github/workflows/release-workflow.yml index 837f7c4..f9ea281 100644 --- a/.github/workflows/release-workflow.yml +++ b/.github/workflows/release-workflow.yml @@ -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 }} diff --git a/README.md b/README.md index 55ba7b3..2c361e5 100644 --- a/README.md +++ b/README.md @@ -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//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. \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 0eb0530..6da362d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 @@ -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" @@ -32,29 +31,29 @@ val repoRef: String by project scmVersion { versionIncrementer("incrementMinorIfNotOnRelease", mapOf("releaseBranchPattern" to "release/.+")) - hooks( - closureOf { - pre( - "fileUpdate", - mapOf( - "file" to "CHANGELOG.md", - "pattern" to KotlinClosure2({ v, _ -> - "\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z" - }), - "replacement" to KotlinClosure2({ 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({ v, _ -> + "\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z" + }), + "replacement" to KotlinClosure2({ 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) @@ -78,7 +77,7 @@ dependencies { tasks { wrapper { - gradleVersion = "7.4.1" + gradleVersion = "8.0.1" distributionType = Wrapper.DistributionType.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 = yaml.load(file("$resourcesDir/plugin.yml").inputStream()) @@ -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 { diff --git a/gradle.properties b/gradle.properties index 4a77d08..e97d4f4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927..ccebba7 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d7e66b5..6ec1567 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/gradlew b/gradlew index 1b6c787..79a61d4 100755 --- a/gradlew +++ b/gradlew @@ -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/. @@ -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"' @@ -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 @@ -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. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..6689b85 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -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 @@ -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% @@ -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. @@ -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