Skip to content

Commit

Permalink
Update misc repo infra (#75)
Browse files Browse the repository at this point in the history
* Spotless 0.47

* JDK 21

* Modernize CI

* Kotlin 1.9.22

* Enable CC

* Update misc dependencies

* Gradle 8.6
  • Loading branch information
ZacSweers authored Feb 12, 2024
1 parent 097f1a4 commit 33a9984
Show file tree
Hide file tree
Showing 24 changed files with 96 additions and 124 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/checksum.sh

This file was deleted.

37 changes: 22 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
name: CI

on: [push, pull_request]
on:
# Only run push on main
push:
branches:
- main
paths-ignore:
- '**/*.md'
# Always run on PRs
pull_request:
branches: [ main ]
merge_group:

concurrency:
group: 'ci-${{ github.event.merge_group.head_ref || github.head_ref }}-${{ github.workflow }}'
cancel-in-progress: true

jobs:
build:
Expand All @@ -11,27 +25,20 @@ jobs:
uses: actions/checkout@v4

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Generate cache key
run: ./.github/workflows/checksum.sh checksum.txt

- uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ matrix.java-version }}-${{ hashFiles('checksum.txt') }}
restore-keys: |
${{ runner.os }}-gradle-${{ matrix.java-version }}-
uses: gradle/wrapper-validation-action@v2

- name: Configure JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '20'
java-version: '21'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Test
run: ./gradlew check

- name: Publish (default branch only)
if: github.repository == 'slackhq/EitherNet' && github.ref == 'refs/heads/main'
run: ./gradlew publishAllPublicationsToMavenCentralRepository -PmavenCentralUsername=${{ secrets.SONATYPEUSERNAME }} -PmavenCentralPassword=${{ secrets.SONATYPEPASSWORD }}
run: ./gradlew publish -PmavenCentralUsername=${{ secrets.SONATYPEUSERNAME }} -PmavenCentralPassword=${{ secrets.SONATYPEPASSWORD }}
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Releasing
2. Update the `CHANGELOG.md` for the impending release.
3. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version)
4. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version)
5. `./gradlew publish`
5. `./gradlew publish --no-configuration-cache`
6. Update the `gradle.properties` to the next SNAPSHOT version.
7. `git commit -am "Prepare next development version."`
8. `git push && git push --tags`
7 changes: 2 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ kotlin {

tasks.compileTestKotlin {
compilerOptions {
optIn.addAll(
"kotlin.ExperimentalStdlibApi",
"kotlinx.coroutines.ExperimentalCoroutinesApi",
)
optIn.addAll("kotlin.ExperimentalStdlibApi", "kotlinx.coroutines.ExperimentalCoroutinesApi")
// Enable new jvmdefault behavior
// https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-m3-generating-default-methods-in-interfaces/
freeCompilerArgs.add("-Xjvm-default=all")
Expand Down Expand Up @@ -107,7 +104,7 @@ spotless {
endWithNewline()
licenseHeaderFile(
"spotless/spotless.kt",
"(import|plugins|buildscript|dependencies|pluginManagement|rootProject)"
"(import|plugins|buildscript|dependencies|pluginManagement|rootProject)",
)
}
}
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.caching=true
org.gradle.configuration-cache=true

# New Kotlin IC flags
kotlin.compiler.suppressExperimentalICOptimizationsWarning=true
Expand Down
20 changes: 10 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[versions]
coroutines = "1.7.2"
kotlin = "1.9.20"
jdk = "20"
kotlin = "1.9.22"
jdk = "21"
jvmTarget = "11"
ksp = "1.9.20-1.0.13"
ktfmt = "0.46"
moshi = "1.15.0"
ksp = "1.9.22-1.0.17"
ktfmt = "0.47"
moshi = "1.15.1"
okhttp = "4.9.0"
retrofit = "2.9.0"

[plugins]
binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.13.2" }
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.23.0" }
binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.14.0" }
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.23.5" }
dokka = { id = "org.jetbrains.dokka", version = "1.9.10" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.25.3" }
spotless = { id = "com.diffplug.spotless", version = "6.22.0" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.27.0" }
spotless = { id = "com.diffplug.spotless", version = "6.25.0" }

[libraries]
androidProcessingApi = "com.google.android:android:4.1.1.4"
Expand All @@ -34,4 +34,4 @@ okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
okhttp-mockwebserver = { module = "com.squareup.okhttp3:mockwebserver", version.ref = "okhttp" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit-converterScalars = { module = "com.squareup.retrofit2:converter-scalars", version.ref = "retrofit" }
truth = "com.google.truth:truth:1.1.4"
truth = "com.google.truth:truth:1.4.0"
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
17 changes: 9 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -144,15 +145,15 @@ 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
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
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -201,11 +202,11 @@ fi
# 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 $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.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_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" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ 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

Expand All @@ -57,11 +57,11 @@ 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

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/slack/eithernet/Annotations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ public fun ResultType.toType(): Type {
Types.newParameterizedTypeWithOwner(
ownerType.javaObjectType,
rawType.javaObjectType,
*typeArgs.map(ResultType::toType).toTypedArray()
*typeArgs.map(ResultType::toType).toTypedArray(),
)
} else {
Types.newParameterizedType(
rawType.javaObjectType,
*typeArgs.map(ResultType::toType).toTypedArray()
*typeArgs.map(ResultType::toType).toTypedArray(),
)
}
}
Expand Down Expand Up @@ -160,19 +160,19 @@ internal fun createResultType(type: Type): ResultType {
canonicalize(ownerType) as Class<*>,
canonicalize(rawType) as Class<*>,
typeArgs,
isArray
isArray,
)
}

private fun createResultType(
ownerType: Class<*>,
rawType: Class<*>,
typeArgs: Array<ResultType>,
isArray: Boolean
isArray: Boolean,
): ResultType =
ResultType(
rawType = rawType.kotlin,
typeArgs = typeArgs,
ownerType = ownerType.kotlin,
isArray = isArray
isArray = isArray,
)
28 changes: 12 additions & 16 deletions src/main/java/com/slack/eithernet/ApiResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ public sealed interface ApiResult<out T : Any, out E : Any> {

/** Returns a new [HttpFailure] with given [code] and optional [error]. */
@JvmOverloads
public fun <E : Any> httpFailure(
code: Int,
error: E? = null,
): HttpFailure<E> {
public fun <E : Any> httpFailure(code: Int, error: E? = null): HttpFailure<E> {
checkHttpFailureCode(code)
return HttpFailure(code, error, emptyMap())
}
Expand Down Expand Up @@ -223,9 +220,8 @@ public object ApiResultConverterFactory : Converter.Factory() {
return ApiResultConverter(delegateConverter)
}

private class ApiResultConverter(
private val delegate: Converter<ResponseBody, Any>,
) : Converter<ResponseBody, ApiResult<*, *>> {
private class ApiResultConverter(private val delegate: Converter<ResponseBody, Any>) :
Converter<ResponseBody, ApiResult<*, *>> {
override fun convert(value: ResponseBody): ApiResult<*, *>? {
return delegate.convert(value)?.let(ApiResult.Companion::success)
}
Expand Down Expand Up @@ -281,23 +277,23 @@ public object ApiResultCallAdapterFactory : CallAdapter.Factory() {
call,
Response.success(
ApiFailure(error = t.error, tags = mapOf(Request::class to call.request()))
)
),
)
}
is IOException -> {
callback.onResponse(
call,
Response.success(
NetworkFailure(error = t, tags = mapOf(Request::class to call.request())),
)
NetworkFailure(error = t, tags = mapOf(Request::class to call.request()))
),
)
}
else -> {
callback.onResponse(
call,
Response.success(
UnknownFailure(error = t, tags = mapOf(Request::class to call.request())),
)
UnknownFailure(error = t, tags = mapOf(Request::class to call.request()))
),
)
}
}
Expand Down Expand Up @@ -352,9 +348,9 @@ public object ApiResultCallAdapterFactory : CallAdapter.Factory() {
Response.success(
UnknownFailure(
error = e,
tags = mapOf(okhttp3.Response::class to response.raw())
tags = mapOf(okhttp3.Response::class to response.raw()),
)
)
),
)
return
}
Expand All @@ -367,9 +363,9 @@ public object ApiResultCallAdapterFactory : CallAdapter.Factory() {
HttpFailure(
code = response.code(),
error = errorBody,
tags = mapOf(okhttp3.Response::class to response.raw())
tags = mapOf(okhttp3.Response::class to response.raw()),
)
)
),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ import kotlin.annotation.AnnotationTarget.TYPEALIAS
@Target(CLASS, FUNCTION, TYPEALIAS, PROPERTY)
@RequiresOptIn(
level = ERROR,
message = "Indicates that a given API is currently experimental and subject to change."
message = "Indicates that a given API is currently experimental and subject to change.",
)
public annotation class ExperimentalEitherNetApi
8 changes: 1 addition & 7 deletions src/main/java/com/slack/eithernet/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,7 @@ public fun <T : Any, E : Any, C> ApiResult<T, E>.foldOld(
onHttpFailure: (ApiResult.Failure.HttpFailure<E>) -> C,
onApiFailure: (ApiResult.Failure.ApiFailure<E>) -> C,
): C {
return foldOldInternal(
onSuccess,
onNetworkFailure,
onUnknownFailure,
onHttpFailure,
onApiFailure,
)
return foldOldInternal(onSuccess, onNetworkFailure, onUnknownFailure, onHttpFailure, onApiFailure)
}

// Separate so we can call it from the two old deprecated versions above
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/slack/eithernet/InternalEitherNetApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ import kotlin.annotation.AnnotationTarget.TYPEALIAS
level = ERROR,
message =
"This is an internal EitherNet API that " +
"should not be used from outside of EitherNet. No compatibility guarantees are provided."
"should not be used from outside of EitherNet. No compatibility guarantees are provided.",
)
public annotation class InternalEitherNetApi
Loading

0 comments on commit 33a9984

Please sign in to comment.