-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Обновляет версии Gradle, AGP, Kotlin * Настраивает detekt в проекте * Переносит объявление библиотек в version catalog * Удаляет лишние файлы из build-logic * Настраивает проверки на PR * Исправляет версию Java для сборки * Добавляет флажков к запуску Gradle * Исправляет число ошибок detekt, требуемых для остановки сборки * Настраивает ReviewDog для лучшей видимости ошибок статического анализа * Добавляет удаление комментариев от бота перед запуском проверок * Добавляет документацию про detektAll и detektFormat
- Loading branch information
1 parent
44f0d99
commit 4425519
Showing
19 changed files
with
1,127 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
root = true | ||
|
||
# See conf/detekt.yml, values should be the same | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 120 | ||
|
||
ij_kotlin_imports_layout = *, java.**, javax.**, kotlin.**, kotlinx.android.synthetic.**, ^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: PR checks | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
|
||
jobs: | ||
pr-checks: | ||
runs-on: ubuntu-latest | ||
env: | ||
commonGradleFlags: --parallel --stacktrace --no-configuration-cache --no-daemon | ||
detektReportPath: ./build/reports/detekt/detekt.xml | ||
reviewdogSetup: -f=checkstyle -name="detekt" -level=error -filter-mode=added | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Cleanup Github-Actions bot comments | ||
run: | | ||
sh ./ci/github_comments_cleanup.sh "${{ github.repository_owner }}" "${{ github.event.repository.name }}" "${{ github.event.number }}" "github-actions[bot]" "${{ secrets.GITHUB_TOKEN }}" | ||
- name: Setup Reviewdog | ||
uses: reviewdog/action-setup@v1 | ||
with: | ||
reviewdog_version: latest | ||
|
||
- name: Setup JDK 17 for build | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: gradle | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Warming up Gradle | ||
run: ./gradlew help $commonGradleFlags | ||
|
||
- name: Run detekt | ||
run: ./gradlew detektAll $commonGradleFlags | ||
|
||
- name: Run Reviewdog for Detekt as Github Review | ||
env: | ||
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
reviewdog $reviewdogSetup -reporter=github-pr-review <$detektReportPath | ||
- name: Run Reviewdog for Detekt as Github CHECK | ||
env: | ||
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
reviewdog $reviewdogSetup -reporter=github-pr-check <$detektReportPath | ||
- name: Assemble app | ||
run: ./gradlew :app:assembleDebug $commonGradleFlags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
group = "ru.practicum.android.buildlogic" | ||
|
||
dependencies { | ||
implementation(projects.gradleExt) | ||
|
||
implementation(libs.staticAnalysis.detektPlugin) | ||
// workaround for https://github.com/gradle/gradle/issues/15383 | ||
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) | ||
} |
87 changes: 87 additions & 0 deletions
87
build-logic/checks/src/main/kotlin/convention.detekt.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import io.gitlab.arturbosch.detekt.Detekt | ||
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask | ||
import ru.practicum.android.withVersionCatalog | ||
|
||
plugins { | ||
id("io.gitlab.arturbosch.detekt") | ||
} | ||
|
||
fun Detekt.setupCommonDetektSettings() { | ||
// Common properties | ||
parallel = true | ||
autoCorrect = false | ||
disableDefaultRuleSets = false | ||
buildUponDefaultConfig = false | ||
|
||
// workaround for https://github.com/gradle/gradle/issues/15383 | ||
project.withVersionCatalog { libs -> | ||
jvmTarget = JavaVersion.valueOf(libs.versions.java.get()).toString() | ||
} | ||
|
||
// Setup sources for run | ||
setSource(files(projectDir)) | ||
include("**/*.kt") | ||
include("**/*.kts") | ||
exclude("**/resources/**") | ||
exclude("**/build/**") | ||
|
||
// reports configuration | ||
reports { | ||
xml.required.set(true) | ||
html.required.set(true) | ||
txt.required.set(true) | ||
sarif.required.set(false) | ||
} | ||
} | ||
|
||
val detektAll by tasks.register<Detekt>("detektAll") { | ||
description = "Runs over whole code base without the starting overhead for each module." | ||
|
||
setupCommonDetektSettings() | ||
|
||
// Configuration | ||
config.setFrom(files(project.rootDir.resolve("conf/detekt.yml"))) | ||
} | ||
|
||
val detektFormat by tasks.register<Detekt>("detektFormat") { | ||
description = "Reformats whole code base." | ||
|
||
setupCommonDetektSettings() | ||
autoCorrect = true | ||
|
||
// Configuration | ||
config.setFrom(files(project.rootDir.resolve("conf/detekt.yml"))) | ||
} | ||
|
||
val detektProjectBaseline by tasks.register<DetektCreateBaselineTask>("detektProjectBaseline") { | ||
description = "Overrides current baseline." | ||
|
||
// Setup sources for run | ||
setSource(files(projectDir)) | ||
include("**/*.kt") | ||
include("**/*.kts") | ||
exclude("**/resources/**") | ||
exclude("**/build/**") | ||
|
||
// Common properties | ||
buildUponDefaultConfig.set(true) | ||
ignoreFailures.set(true) | ||
parallel.set(true) | ||
|
||
// workaround for https://github.com/gradle/gradle/issues/15383 | ||
project.withVersionCatalog { libs -> | ||
jvmTarget = JavaVersion.valueOf(libs.versions.java.get()).toString() | ||
} | ||
|
||
// Configuration | ||
config.setFrom(files(project.rootDir.resolve("conf/detekt.yml"))) | ||
} | ||
|
||
// workaround for https://github.com/gradle/gradle/issues/15383 | ||
project.withVersionCatalog { libs -> | ||
dependencies { | ||
add("detekt", libs.staticAnalysis.detektCli) | ||
add("detektPlugins", libs.staticAnalysis.detektFormatting) | ||
add("detektPlugins", libs.staticAnalysis.detektLibraries) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
group = "ru.practicum.android.buildlogic" | ||
|
||
dependencies { | ||
// workaround for https://github.com/gradle/gradle/issues/15383 | ||
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) | ||
} |
17 changes: 17 additions & 0 deletions
17
build-logic/gradle-ext/src/main/kotlin/ru/practicum/android/VersionCatalogExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ru.practicum.android | ||
|
||
import org.gradle.accessors.dm.LibrariesForLibs | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.the | ||
|
||
|
||
/** | ||
* Workaround to make version catalog accessible in convention plugins | ||
* https://github.com/gradle/gradle/issues/15383 | ||
*/ | ||
fun Project.withVersionCatalog(block: (libs: LibrariesForLibs) -> Unit) { | ||
if (project.name != "gradle-kotlin-dsl-accessors") { | ||
val libs = the<LibrariesForLibs>() | ||
block.invoke(libs) | ||
} | ||
} |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
plugins { | ||
id("com.android.application") version "8.1.0" apply false | ||
id("org.jetbrains.kotlin.android") version "1.8.0" apply false | ||
} | ||
id("com.android.application") version "8.1.4" apply false | ||
id("org.jetbrains.kotlin.android") version "1.9.21" apply false | ||
id("convention.detekt") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
# Variables | ||
repo_owner="$1" | ||
repo_name="$2" | ||
pull_number="$3" | ||
username="$4" | ||
github_token="$5" | ||
|
||
# List all comments in the pull request | ||
comments_url="https://api.github.com/repos/$repo_owner/$repo_name/pulls/$pull_number/comments" | ||
echo "Comments URL: $comments_url" | ||
|
||
comments=$(curl \ | ||
-L \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $github_token" \ | ||
"$comments_url" | jq -c '.[] | select(.user.login == "'$username'") | .url') | ||
|
||
echo "$comments" | while read -r comment_url; do | ||
# Remove quotes from comment_url | ||
fixed_comment_url="${comment_url%\"}" | ||
fixed_comment_url="${comment_url#\"}" | ||
|
||
curl -s -X DELETE \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $github_token" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
$fixed_comment_url | ||
sleep 1 | ||
|
||
echo "Deleted comment: $fixed_comment_url" | ||
done |
Oops, something went wrong.