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

Replace Danger with Danger-Kotlin #154

Merged
merged 3 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up Ruby from .ruby-version
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: build
run: |
./gradlew --continue clean
mkdir -p build/reports
./gradlew --continue build --stacktrace 2>build/reports/build-error-log.txt
- name: lint and test
if: success()
run: ./gradlew --continue clean ktlintCheck lintDebug testDebug --stacktrace
run: ./gradlew --continue ktlintCheck lintDebug testDebug --stacktrace
- name: 'Upload lint and test reports'
uses: actions/upload-artifact@v3
if: cancelled() != true
Expand All @@ -50,9 +46,11 @@ jobs:
**/build/reports
**/build/test-results
retention-days: 7
- name: Run Danger
- name: Run Danger-Kotlin
if: cancelled() != true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JOB_STATUS: ${{ job.status }}
run: |
bundle exec danger --remove-previous-comments --fail-on-errors=true
uses: docker://ghcr.io/danger/danger-kotlin:1.2.0
with:
args: --failOnErrors --no-publish-check
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
tags:
- v*
paths-ignore:
- .github/workflows/pr.yml
- .gitattributes
- .gitignore
- Dangerfile.df.kts
- README.md
- LICENSE
concurrency:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ gen-external-apklibs
# with Android Studio 3.5.

# End of https://gitignore.io/developers/gitignore/api/android

### Danger-Kotlin
danger_out.json
69 changes: 69 additions & 0 deletions Dangerfile.df.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:DependsOn("io.github.ackeecz:danger-kotlin-junit:0.1.0")
@file:DependsOn("io.github.417-72ki:danger-kotlin-checkstyle_format:0.0.2")
@file:OptIn(ExperimentalPathApi::class)

import io.github.ackeecz.danger.junit.JUnitPlugin
import jp.room417.danger_kotlin_checkstyle_format.CheckstyleFormat
import systems.danger.kotlin.*
import java.io.File
import java.io.IOException
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.*
import kotlin.streams.toList

register plugin JUnitPlugin
register plugin CheckstyleFormat

danger(args) {
val path = Path(System.getProperty("user.dir"))

path.forEachDirectoryEntryRecursive(glob = "**/build/reports/**/build-error-log.txt") {
it.useLines { seq ->
seq.forEach { line ->
when {
line.startsWith("w: ") -> {
warn(line.removeRange(0, 2))
}
line.startsWith("e: ") -> {
fail(line.removeRange(0, 2))
}
}
}
}
}
path.forEachDirectoryEntryRecursive(glob = "**/build/reports/ktlint/**/ktlint*.xml") {
CheckstyleFormat.basePath = if (System.getenv("CI") == "true") {
Path("/home/runner/work/android-common-library/android-common-library")
} else {
Path(System.getenv("WORKING_DIR") ?: System.getProperty("user.dir"))
}
CheckstyleFormat.report(it)
}

path.forEachDirectoryEntryRecursive(glob = "**/build/test-results/*/*.xml") {
JUnitPlugin.parse(File(it.toUri()))
JUnitPlugin.report()
}
}

@SinceKotlin("1.5")
@Throws(IOException::class)
fun Path.forEachDirectoryEntryRecursive(glob: String, action: (Path) -> Unit) {
if (notExists()) return
if (!glob.contains("/")) return forEachDirectoryEntry(glob, action)
when (val subdir = glob.split("/").first()) {
"*" -> forEachDirectoryEntry(glob = "*") {
if (it.isDirectory())
it.forEachDirectoryEntryRecursive(glob.removePrefix("${subdir}/"), action)
}
"**" -> forEachDirectoryEntry(glob = "**") {
if (it.isDirectory())
it.forEachDirectoryEntryRecursive(glob.removePrefix("${subdir}/"), action)
}
else -> resolve(subdir)
.forEachDirectoryEntryRecursive(glob.removePrefix("${subdir}/"), action)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("ktlint:filename")
package jp.room417.common.sampleApp.di

import android.content.Context
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ allprojects {
}

ktlint {
version = "0.45.2"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


disabledRules = [
"filename",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"import-ordering",
"no-wildcard-imports",
]
Expand Down