diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..304fae7 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,34 @@ +# Publish to Maven Central on release + +name: Publish +on: + release: + types: [released, prereleased] +jobs: + publish: + name: Release build and publish + runs-on: macOS-latest + permissions: + contents: read + packages: write + steps: + - name: Check out code + uses: actions/checkout@v6 + - name: Set up JDK + uses: actions/setup-java@v5 + with: + distribution: 'zulu' + java-version: 24 + - name: Publish to Maven Central + run: ./gradlew publishToMavenCentral --no-configuration-cache + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }} + - name: Publish to GitHub Packages + run: ./gradlew publishAllPublicationsToGitHubPackagesRepository --no-configuration-cache + env: + GH_PACKAGES_USER: ${{ secrets.GH_PACKAGES_USER }} + GH_PACKAGES_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/runTests.yaml b/.github/workflows/runTests.yaml index e178985..533cebc 100644 --- a/.github/workflows/runTests.yaml +++ b/.github/workflows/runTests.yaml @@ -1,4 +1,4 @@ -#Run tests on every PR and push +# Run tests on every PR and push name: Run Tests @@ -18,4 +18,4 @@ jobs: - name: Validate Gradle wrapper uses: gradle/wrapper-validation-action@v1 - name: Test with Gradle - run: ./gradlew test \ No newline at end of file + run: ./gradlew jvmTest \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 4d662e7..b771688 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,27 +4,22 @@ * Gradle build file for Keval */ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -group = "com.notkamui.libs" -version = "1.1.1" - plugins { - kotlin("multiplatform") version "1.9.22" - java - `maven-publish` - signing + id("org.jetbrains.kotlin.multiplatform") version "2.3.21" + id("maven-publish") + id("com.vanniktech.maven.publish") version "0.36.0" } +group = "com.notkamui.libs" +version = "1.1.1" + repositories { mavenCentral() } -java { - withJavadocJar() - withSourcesJar() -} - kotlin { jvm() js(IR) { @@ -34,50 +29,30 @@ kotlin { linuxX64() mingwX64() - macosX64() macosArm64() iosSimulatorArm64() iosX64() iosArm64() watchosSimulatorArm64() - watchosX64() watchosArm32() watchosArm64() tvosSimulatorArm64() - tvosX64() tvosArm64() sourceSets { - val commonMain by getting { - } val commonTest by getting { dependencies { - implementation("org.jetbrains.kotlin:kotlin-test") - implementation("org.jetbrains.kotlin:kotlin-test-junit") + implementation(kotlin("test")) } } } } tasks { - jar { - manifest { - attributes( - mapOf( - "Implementation-Title" to project.name, - "Implementation-Version" to project.version - ) - ) - } - } - withType { - kotlinOptions.jvmTarget = "1.8" - } - - withType { - sourceCompatibility = "1.8" - targetCompatibility = "1.8" + compilerOptions { + jvmTarget.set(JvmTarget.JVM_1_8) + } } withType { @@ -85,66 +60,51 @@ tasks { } } -val isSnapshot = version.toString().endsWith("-SNAPSHOT") +mavenPublishing { + coordinates(group.toString(), "keval", version.toString()) -val repositoryUrl = if (isSnapshot) - "https://oss.sonatype.org/content/repositories/snapshots/" -else - "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + publishToMavenCentral() -publishing { - publications { - withType { - artifactId = artifactId.toLowerCase() - - artifact(tasks.getByName("javadocJar")) - - pom { - name.set("Keval") - description.set("A Kotlin mini library for mathematical expression string evaluation") - url.set("https://github.com/notKamui/Keval") - licenses { - license { - name.set("MIT License") - url.set("https://mit-license.org/") - } - } - developers { - developer { - id.set("notKamui") - name.set("Jimmy Teillard") - email.set("jimmy.teillard@notkamui.com") - } - } - scm { - connection.set("scm:git:git://github.com/notKamui/Keval.git") - developerConnection.set("scm:git:ssh://github.com/notKamui/Keval.git") - url.set("https://github.com/notKamui/Keval.git") - } + if (project.hasProperty("signingInMemoryKey")) { + signAllPublications() + } + + pom { + name.set("Keval") + description.set("A Kotlin mini library for mathematical expression string evaluation") + url.set("https://github.com/notKamui/Keval") + licenses { + license { + name.set("MIT License") + url.set("https://mit-license.org/") + } + } + developers { + developer { + id.set("notKamui") + name.set("Jimmy Teillard") + email.set("jimmy.teillard@notkamui.com") } } + scm { + connection.set("scm:git:git://github.com/notKamui/Keval.git") + developerConnection.set("scm:git:ssh://github.com/notKamui/Keval.git") + url.set("https://github.com/notKamui/Keval.git") + } } +} + +publishing { repositories { maven { - setUrl(repositoryUrl) + name = "GitHubPackages" + + url = uri("https://maven.pkg.github.com/notKamui/${rootProject.name}") + credentials { - username = project.properties["ossrhUsername"] as String? ?: "Unknown user" - password = project.properties["ossrhPassword"] as String? ?: "Unknown user" - } - } - if (!isSnapshot) { - maven { - name = "GitHubPackages" - setUrl("https://maven.pkg.github.com/notKamui/${project.name}") - credentials { - username = project.properties["githubUsername"] as String? ?: "Unknown user" - password = project.properties["githubPassword"] as String? ?: "Unknown user" - } + username = project.findProperty("githubPackagesUser") as String? ?: System.getenv("GH_PACKAGES_USER") + password = project.findProperty("githubPackagesToken") as String? ?: System.getenv("GH_PACKAGES_TOKEN") } } } } - -signing { - sign(publishing.publications) -} diff --git a/gradle.properties.template b/gradle.properties.template index 7c3bac4..3083a82 100644 --- a/gradle.properties.template +++ b/gradle.properties.template @@ -1,9 +1,9 @@ +mavenCentralUsername= +mavenCentralPassword= + signing.keyId= signing.password= signing.secretKeyRingFile= -ossrhUsername= -ossrhPassword= - -githubUsername= -githubPassword= \ No newline at end of file +githubPackagesUser= +githubPackagesToken= \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 943f0cb..b1b8ef5 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 2b22d05..e74c870 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,9 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-all.zip networkTimeout=10000 +retries=0 +retryBackOffMs=500 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 65dcd68..b9bb139 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -83,10 +85,8 @@ done # 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"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -133,10 +132,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +146,7 @@ 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 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +154,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -169,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -197,16 +198,19 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# 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"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/gradlew.bat b/gradlew.bat index 93e3f59..24c62d5 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -21,8 +23,8 @@ @rem @rem ########################################################################## -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions set DIRNAME=%~dp0 if "%DIRNAME%"=="" set DIRNAME=. @@ -43,13 +45,13 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 -goto fail +"%COMSPEC%" /c exit 1 :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% @@ -57,36 +59,24 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 -goto fail +"%COMSPEC%" /c exit 1 :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -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! -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 +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel -:omega +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL%