Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Add] Local CI for android team #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: 2.1
jobs:
build:
working_directory: ~/AndroidSetup
docker:
- image: circleci/android:api-28
environment:
GRADLE_OPTS: -Xmx4g -Dorg.gradle.daemon=false
JVM_OPTS: -Xmx4g
steps:
- checkout
- restore_cache:
key: gradle-{{ checksum "build.gradle.kts" }}-{{ checksum "buildSrc/src/main/kotlin/Config.kt" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "app/build.gradle.kts" }}
- run:
name: Download Dependencies
command: ./gradlew androidDependencies
- save_cache:
paths:
- ~/.gradle
key: gradle-{{ checksum "build.gradle.kts" }}-{{ checksum "buildSrc/src/main/kotlin/Config.kt" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "app/build.gradle.kts" }}
- run:
name: Run Detekt
command: ./gradlew detekt
- run:
name: Run Ktlint
command: ./gradlew ktlintCheck
- run:
name: Run UnitTest
command: ./gradlew testDebugUnitTest
- run:
name: Save UnitTest results
command: |
mkdir -p ~/test-results/junit/
find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} ~/test-results/junit/ \;
when: always
- store_test_results:
path: ~/test-results
- store_artifacts:
path: app/build/reports
destination: reports
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
apply(from = "$rootDir/team-props/git-hooks.gradle.kts")

repositories {
google()
jcenter()
Expand Down
41 changes: 41 additions & 0 deletions team-props/git-hooks.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
fun isLinuxOrMacOs(): Boolean {
return isMac() || isLinux()
}

fun isLinux(): Boolean {
return System.getProperty("os.name").toLowerCase().contains("linux")
}

fun isMac(): Boolean {
val osName = System.getProperty("os.name").toLowerCase()
return osName.contains("mac os")
|| osName.contains("macos")
}

tasks.register("copyGitHooks", Copy::class) {
description = "Copies the git hooks from team-props/git-hooks to the .git folder."
val path = if (isLinux()) "$rootDir/team-props/git-hooks/linux"
else "$rootDir/team-props/git-hooks/mac"
from(path) {
include("**/*.sh")
rename("(.*).sh", "$1")
}
into("$rootDir/.git/hooks")
onlyIf { isLinuxOrMacOs() }
}

tasks.register("installGitHooks", Exec::class) {
description = "Installs the pre-commit git hooks from team-props/git-hooks."
group = "git hooks"
workingDir = rootDir
setCommandLine("chmod", "-R", "+x", ".git/hooks/")
dependsOn("copyGitHooks")
onlyIf { isLinuxOrMacOs() }
doLast {
logger.info("Git hook installed successfully!")
}
}

afterEvaluate {
tasks["clean"].dependsOn("installGitHooks")
}
17 changes: 17 additions & 0 deletions team-props/git-hooks/linux/commit-msg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
echo "Checking your commit message"

<<comment
\b word
\s space
.* any chars
^, $: start, end
comment

commit_regex='^\[\b(add|modify|fix|revert|hotfix)\b\]\s.+$'
error_msg="Aborting commit. Your commit message does not follow the commit message rule"

if ! grep -iqE "$commit_regex" "$1"; then
echo "$error_msg" >&2
exit 1
fi
33 changes: 33 additions & 0 deletions team-props/git-hooks/linux/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
echo "Running static analysis..."

echo "Start running ktlint"
./gradlew ktlintFormat ktlintCheck --daemon
status0=$?
if [[ "$status0" = 0 ]] ; then
echo "ktlint found no problems."
else
echo 1>&2 "ktlint found violations it could not fix. Please check ktlint report at \"build/reports/ktlint/ktlint.html\" "
exit 1
fi

echo "Start running detektCheck"
./gradlew detekt --daemon
status1=$?
if [[ "$status1" = 0 ]] ; then
echo "detekt found no problems."
else
echo 1>&2 "ktlint found violations. Please check ktlint report at \"build/reports/detekt/detekt-report.html\" "
exit 1
fi

echo "Start running unit test"
./gradlew testDebug --daemon
status2=$?
if [[ "$status2" = 0 ]] ; then
echo "run unit test success."
git add .
else
echo 1>&2 "run unit test failure, please re-check"
exit 1
fi
18 changes: 18 additions & 0 deletions team-props/git-hooks/mac/commit-msg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
echo "Checking your commit message"

<<comment
\b word
(?i) case insensitive
\s space
.* any chars
^, $: start, end
comment

commit_regex='^\[\b(?i)(add|modify|fix|revert|hotfix)\b\]\s.+$'
error_msg="Aborting commit. Your commit message does not follow the commit message rule"

if ! grep -iqE "$commit_regex" "$1"; then
echo "$error_msg" >&2
exit 1
fi
33 changes: 33 additions & 0 deletions team-props/git-hooks/mac/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
echo "Running static analysis..."

echo "Start running ktlint"
./gradlew ktlintFormat ktlintCheck --daemon
status0=$?
if [[ "$status0" = 0 ]] ; then
echo "ktlint found no problems."
else
echo 1>&2 "ktlint found violations it could not fix. Please check ktlint report at \"build/reports/ktlint/ktlint.html\" "
exit 1
fi

echo "Start running detektCheck"
./gradlew detekt --daemon
status1=$?
if [[ "$status1" = 0 ]] ; then
echo "detekt found no problems."
else
echo 1>&2 "ktlint found violations. Please check ktlint report at \"build/reports/detekt/detekt-report.html\" "
exit 1
fi

echo "Start running unit test"
./gradlew testDebug --daemon
status2=$?
if [[ "$status2" = 0 ]] ; then
echo "run unit test success."
git add .
else
echo 1>&2 "run unit test failure, please re-check"
exit 1
fi