Skip to content

Commit

Permalink
Initial Github Action workflow + static analysis (+33 squashed commits)
Browse files Browse the repository at this point in the history
Squashed commits:
[3ac28e0] Run static analysis in parallel
[be45ad5] Move static analysis to reusable workflow
[9a35a8d] Support for detekt
[e2abeaa] Better reporting
[82dfa8f] Split ktlint tasks
[431cf69] Use other plugin for publishing checkstyle results
[9091c1a] Always collect ktlint results
[7157a9a] Syntax
[ae75c5e] Better gradle caching
Testing ktlint results
[9b7e579] Correct ktlint report path
[dac6a27] Fix files cached by ktlint
[643c9d0] Run correct ktlint task
[895d2be] Run Ktlint and gather results
[fcf5de4] More cleanup
[c9a1fd2] Cleanup
[a80290c] Add Realm Java Compatibility project (#882)
[bd7057f] Introduce a new top-level task for publishing packages used by CI nodes.
[a68dd30] Use better Gradle task for caching
[e951681] Use enabled flag for publications.
[652ddb4] Use same version of NDK
[6da6985] Cache NDK + use publish task
[0263693] Only build for Android
[73d879e] More syntax
[f13d290] Syntax error
[d40aba7] Install CMake and Ninja
[8b99435] Add ccache
[80e6095] Setup Java
[99703bf] Update pr.yml

Checkout code
[f1c52d1] Remove description
[0e7a2a9] wip
[3fc1971] Run on ubuntu
[10d4e0e] Attempt to build
[15360c4] Trigger draft PR
  • Loading branch information
cmelchior committed Jun 16, 2022
1 parent 2649ea8 commit a1a5466
Show file tree
Hide file tree
Showing 47 changed files with 1,385 additions and 96 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/include_static_analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Static Analysis

on:
workflow_call:

jobs:
ktlint:
runs-on: ubuntu-latest
steps:

- name: Checkout code
uses: actions/checkout@v3
with:
submodules: "recursive"

- name: Setup Gradle and task/dependency caching
uses: gradle/gradle-build-action@v2
with:
cache-read-only: false # TODO How to configure caching here?

- name: Run Ktlint
run: ./gradlew ktlintCheck

- name: Stash Ktlint results
if: always()
run: |
rm -rf /tmp/ktlint
rm -rf /tmp/detekt
mkdir /tmp/ktlint
mkdir /tmp/detekt
rsync -a --delete --ignore-errors examples/kmm-sample/androidApp/build/reports/ktlint/ /tmp/ktlint/example/ || true
rsync -a --delete --ignore-errors test/build/reports/ktlint/ /tmp/ktlint/test/ || true
rsync -a --delete --ignore-errors packages/cinterop/build/reports/ktlint/ /tmp/ktlint/cinterop/ || true
rsync -a --delete --ignore-errors packages/library-base/build/reports/ktlint/ /tmp/ktlint/library-base/ || true
rsync -a --delete --ignore-errors packages/library-sync/build/reports/ktlint/ /tmp/ktlint/library-sync/ || true
rsync -a --delete --ignore-errors packages/plugin-compiler/build/reports/ktlint/ /tmp/ktlint/plugin-compiler/ || true
rsync -a --delete --ignore-errors packages/gradle-plugin/build/reports/ktlint/ /tmp/ktlint/plugin-gradle/ || true
rsync -a --delete --ignore-errors benchmarks/build/reports/ktlint/ /tmp/ktlint/benchmarks/ || true
- name: Publish Ktlint results
uses: jwgmeligmeyling/checkstyle-github-action@master
if: always()
with:
name: Ktlint Results
title: Ktlint Analyzer report
path: '/tmp/ktlint/**/*.xml'

detekt:
runs-on: ubuntu-latest
steps:

- name: Checkout code
uses: actions/checkout@v3
with:
submodules: "recursive"

- name: Setup Gradle and task/dependency caching
uses: gradle/gradle-build-action@v2
with:
cache-read-only: false # TODO How to configure caching here?

- name: Run Detekt
run: ./gradlew detekt

- name: Stash Detekt results
if: always()
run: |
rm -rf /tmp/detekt
mkdir /tmp/detekt
rsync -a --delete --ignore-errors examples/kmm-sample/androidApp/build/reports/detekt/ /tmp/detekt/example/ || true
rsync -a --delete --ignore-errors test/build/reports/detekt/ /tmp/detekt/test/ || true
rsync -a --delete --ignore-errors packages/cinterop/build/reports/detekt/ /tmp/detekt/cinterop/ || true
rsync -a --delete --ignore-errors packages/library-base/build/reports/detekt/ /tmp/detekt/library-base/ || true
rsync -a --delete --ignore-errors packages/library-sync/build/reports/detekt/ /tmp/detekt/library-sync/ || true
rsync -a --delete --ignore-errors packages/plugin-compiler/build/reports/detekt/ /tmp/detekt/plugin-compiler/ || true
rsync -a --delete --ignore-errors packages/gradle-plugin/build/reports/detekt/ /tmp/detekt/plugin-gradle/ || true
rsync -a --delete --ignore-errors benchmarks/build/reports/detekt/ /tmp/detekt/benchmarks/ || true
- name: Publish Detekt results
uses: jwgmeligmeyling/checkstyle-github-action@master
if: always()
with:
name: Detekt Results
title: Detekt Analyzer report
path: '/tmp/detekt/**/*.xml'
65 changes: 62 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,67 @@
name: 'PR Build'
description: 'Build and test a pull request'
"on":
name: PR Build
on:
pull_request:
paths-ignore:
- '**.md'
env:
REALM_DISABLE_ANALYTICS: true
jobs:
static-analysis:
uses: ./.github/workflows/include_static_analysis.yml

build-packages:
runs-on: ubuntu-latest
needs: static-analysis
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: "recursive"

- name: Validate Gradle Wrapper
uses: gradle/[email protected]

# TODO I'm not sure this catches changes to our Config.kt, what is the impact?
# https://github.com/actions/setup-java#caching-packages-dependencies
- name: Setup Java 11
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11

# TODO Default behavior is only caching from main/master. Unclear what the best caching strategy is for us.
# TODO What is the rules and limits for caching on Github
- name: Setup Gradle and task/dependency caching
uses: gradle/gradle-build-action@v2
with:
cache-read-only: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/releases' && github.ref != 'refs/heads/feature/github-actions' }}

- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.21.4'

- name: Setup Ninja
uses: ashutoshvarma/setup-ninja@master

# TODO How to do ccache caching? It is unclear what the tradeoffs are?
- name: Install ccache
uses: hendrikmuhs/[email protected]
with:
key: realm-kotlin-${{ matrix.os }}

- name: Prepend ccache executables to the PATH
run: echo PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" >> $GITHUB_ENV

# TOOD This matches 23.2.8568313, but what happens if we a define specific version in our build?
- name: Setup NDK
uses: nttld/setup-ndk@v1
with:
ndk-version: r23c


# - name: Build packages
# working-directory: packages
# run: ./gradlew publishCIPackages --info


28 changes: 17 additions & 11 deletions DEPRECATED-Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pipeline {
stage('Tests macOS - Unit Tests') {
when { expression { runTests } }
steps {
testAndCollect("packages", "macosTest")
testAndCollect("packages", "cleanAllTests macosTest")
}
}
stage('Tests Android - Unit Tests') {
Expand All @@ -171,7 +171,7 @@ pipeline {
withLogcatTrace(
"unittest",
{
testAndCollect("packages", "connectedAndroidTest")
testAndCollect("packages", "cleanAllTests connectedAndroidTest")
}
)
}
Expand All @@ -185,7 +185,7 @@ pipeline {
"integrationtest",
{
forwardAdbPorts()
testAndCollect("test", "connectedAndroidTest")
testAndCollect("test", "cleanAllTests connectedAndroidTest")
}
)
}
Expand All @@ -197,7 +197,7 @@ pipeline {
steps {
testWithServer([
{
testAndCollect("test", "macosTest")
testAndCollect("test", "cleanAllTests macosTest")
},
])
}
Expand All @@ -209,18 +209,18 @@ pipeline {
// This will overwrite previous test results, but should be ok as we would not get here
// if previous stages failed.
{
testAndCollect("test", "macosTest -Pkotlin.native.binary.memoryModel=experimental")
testAndCollect("test", "cleanAllTests macosTest -Pkotlin.native.binary.memoryModel=experimental")
},
])
}
}
stage('Tests JVM') {
when { expression { runTests } }
steps {
testAndCollect("test", ':base:jvmTest --tests "io.realm.kotlin.test.compiler*"')
testAndCollect("test", ':base:jvmTest --tests "io.realm.kotlin.test.shared*"')
testAndCollect("test", 'cleanAllTests :base:jvmTest --tests "io.realm.kotlin.test.compiler*"')
testAndCollect("test", 'cleanAllTests :base:jvmTest --tests "io.realm.kotlin.test.shared*"')
testWithServer([
{ testAndCollect("test", ':sync:jvmTest') }
{ testAndCollect("test", 'cleanAllTests :sync:jvmTest') }
])
}
}
Expand All @@ -229,7 +229,7 @@ pipeline {
steps {
testWithServer([
{
testAndCollect("test", "iosTest")
testAndCollect("test", "cleanAllTests iosTest")
}
])
}
Expand All @@ -248,6 +248,12 @@ pipeline {
runBuildMinAndroidApp()
}
}
stage('Test Realm Java Compatibility App') {
when { expression { runTests } }
steps {
testAndCollect("examples/realm-java-compatibility", "connectedAndroidTest")
}
}
stage('Publish SNAPSHOT to Maven Central') {
when { expression { shouldPublishSnapshot(version) } }
steps {
Expand Down Expand Up @@ -561,12 +567,12 @@ def forwardAdbPorts() {
"""
}

def testAndCollect(dir, task) {
def testAndCollect(dir, tasks) {
withEnv(['PATH+USER_BIN=/usr/local/bin']) {
try {
sh """
pushd $dir
./gradlew cleanAllTests $task --info --stacktrace --no-daemon
./gradlew $tasks --info --stacktrace --no-daemon
popd
"""
} finally {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object Versions {
const val compileSdkVersion = 31
const val buildToolsVersion = "31.0.0"
const val buildTools = "7.1.0" // https://maven.google.com/web/index.html?q=gradle#com.android.tools.build:gradle
const val ndkVersion = "23.1.7779620"
const val ndkVersion = "23.2.8568313"
}
const val androidxBenchmarkPlugin = "1.1.0-beta04" // https://maven.google.com/web/index.html#androidx.benchmark:androidx.benchmark.gradle.plugin
const val androidxStartup = "1.1.0" // https://maven.google.com/web/index.html?q=startup#androidx.startup:startup-runtime
Expand Down
70 changes: 70 additions & 0 deletions examples/realm-java-compatibility/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2022 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
id "io.realm.kotlin"
}

apply plugin: "realm-android"

android {
compileSdkVersion = 31

defaultConfig {
applicationId "io.realm.kotlin.demo.javacompatibility"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

realm {
syncEnabled = true
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'

implementation "io.realm.kotlin:library-sync:${Realm.version}"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
21 changes: 21 additions & 0 deletions examples/realm-java-compatibility/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Loading

0 comments on commit a1a5466

Please sign in to comment.