Skip to content

Commit

Permalink
Merge pull request #84 from s2g090123/83-update-the-danger-plugin-in-ci
Browse files Browse the repository at this point in the history
New: Update the danger workflow
  • Loading branch information
s2g090123 authored May 15, 2024
2 parents 27fe975 + 1a22140 commit 722f88a
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 41 deletions.
80 changes: 53 additions & 27 deletions .github/workflows/danger_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,32 @@ on:
- '*'

jobs:
pr:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 100

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'

- name: Danger Checks
env:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gem install bundler
bundle config set --local gemfile danger/gemfiles/GemPR
bundle install
bundle exec danger --dangerfile=danger/dangerfiles/DangerPR --danger_id=pr
ktlint:
runs-on: ubuntu-latest
needs: [pr]

steps:
- name: Checkout code
Expand All @@ -18,14 +42,6 @@ jobs:
- name: Check ktlint
run: ./gradlew ktlintCheck

- name: Archive ktlint Reports
if: always()
uses: actions/upload-artifact@v2
with:
name: ktlint-report
path: |
app/build/reports/ktlint/*
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -36,11 +52,20 @@ jobs:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gem install bundler
bundle config set --local gemfile danger/gemfiles/GemKtlint
bundle install
bundle exec danger
bundle exec danger --dangerfile=danger/dangerfiles/DangerKtlint --danger_id=ktlint
- name: Archive ktlint Reports
uses: actions/upload-artifact@v2
with:
name: ktlint-report
path: |
app/build/reports/ktlint/*
detekt:
runs-on: ubuntu-latest
needs: [pr]

steps:
- name: Checkout code
Expand All @@ -51,14 +76,6 @@ jobs:
- name: Check detekt
run: ./gradlew detekt

- name: Archive detekt Reports
if: always()
uses: actions/upload-artifact@v2
with:
name: detekt-report
path: |
app/build/reports/detekt/detekt.html
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -69,11 +86,20 @@ jobs:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gem install bundler
bundle config set --local gemfile danger/gemfiles/GemDeteKt
bundle install
bundle exec danger
bundle exec danger --dangerfile=danger/dangerfiles/DangerDeteKt --danger_id=detekt
- name: Archive detekt Reports
uses: actions/upload-artifact@v2
with:
name: detekt-report
path: |
app/build/reports/detekt/detekt.html
androidLint:
runs-on: ubuntu-latest
needs: [pr]

steps:
- name: Checkout code
Expand All @@ -84,14 +110,6 @@ jobs:
- name: Check Android lint
run: ./gradlew lint

- name: Archive android lint Reports
if: always()
uses: actions/upload-artifact@v2
with:
name: android-lint-report
path: |
app/build/reports/lint-results-debug.html
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -102,5 +120,13 @@ jobs:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gem install bundler
bundle config set --local gemfile danger/gemfiles/GemAndroidLint
bundle install
bundle exec danger
bundle exec danger --dangerfile=danger/dangerfiles/DangerAndroidLint --danger_id=androidlint
- name: Archive android lint Reports
uses: actions/upload-artifact@v2
with:
name: android-lint-report
path: |
app/build/reports/lint-results-debug.html
29 changes: 15 additions & 14 deletions buildscripts/detekt.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
apply plugin: "io.gitlab.arturbosch.detekt"

detekt {
buildUponDefaultConfig = true
parallel = true
ignoreFailures = true
config.setFrom("${rootProject.projectDir}/config/detekt/detekt_config.yml")
buildUponDefaultConfig = true
parallel = true
ignoreFailures = true
config.setFrom("${rootProject.projectDir}/config/detekt/detekt_config.yml")
}

tasks.named("detekt").configure {
reports {
html.required.set(true)
xml.required.set(false)
txt.required.set(false)
sarif.required.set(false)
md.required.set(false)
html.outputLocation.set(file("$buildDir/reports/detekt/detekt.html"))
}
// Exclude specific files
// exclude("**/*.kt")
reports {
html.required.set(true)
xml.required.set(true)
txt.required.set(false)
sarif.required.set(false)
md.required.set(false)
html.outputLocation.set(file("$buildDir/reports/detekt/detekt.html"))
xml.outputLocation.set(file("$buildDir/reports/detekt/detekt.xml"))
}
// Exclude specific files
// exclude("**/*.kt")
}
6 changes: 6 additions & 0 deletions danger/dangerfiles/DangerAndroidLint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
lint_dir = '**/build/reports/lint-results-debug.xml'
Dir[lint_dir].each do |file_name|
android_lint.skip_gradle_task = true
android_lint.report_file = file_name
android_lint.lint(inline_mode: true)
end
6 changes: 6 additions & 0 deletions danger/dangerfiles/DangerDeteKt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
detekt_dir = "**/build/reports/detekt/detekt.xml"
Dir[detekt_dir].each do |file_name|
kotlin_detekt.skip_gradle_task = true
kotlin_detekt.report_file = file_name
kotlin_detekt.detekt(inline_mode: true)
end
12 changes: 12 additions & 0 deletions danger/dangerfiles/DangerKtlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ktlint_dir = [
"**/build/reports/ktlint/ktlintAndroidTestSourceSetCheck/ktlintAndroidTestSourceSetCheck.json",
"**/build/reports/ktlint/ktlintMainSourceSetCheck/ktlintMainSourceSetCheck.json",
"**/build/reports/ktlint/ktlintTestSourceSetCheck/ktlintTestSourceSetCheck.json"
]
ktlint_dir.each do |dir|
Dir[dir].each do |file_name|
ktlint.skip_lint = true
ktlint.report_file = file_name
ktlint.lint(inline_mode: true)
end
end
13 changes: 13 additions & 0 deletions danger/dangerfiles/DangerPR
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
message "Thanks @#{github.pr_author}!"

# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
warn("PR is classed as Work in Progress") if github.pr_title.include? "WIP"

# Warn when there is a big PR
warn("Big PR") if git.lines_of_code > 500

# Warn to encourage a PR description
warn("Please provide a summary in the PR description to make it easier to review") if github.pr_body.length == 0

# Warn to encourage that labels should have been used on the PR
warn("Please add labels to this PR") if github.pr_labels.empty?
5 changes: 5 additions & 0 deletions danger/gemfiles/GemAndroidLint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem 'danger-android_lint'
6 changes: 6 additions & 0 deletions danger/gemfiles/GemDeteKt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem 'oga'
gem 'danger-kotlin_detekt'
5 changes: 5 additions & 0 deletions danger/gemfiles/GemKtlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem 'danger-ktlint'
5 changes: 5 additions & 0 deletions danger/gemfiles/GemPR
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem 'danger'

0 comments on commit 722f88a

Please sign in to comment.