From 1a221406ac23ee578144be53a4082dcffa9b00b1 Mon Sep 17 00:00:00 2001 From: s2g090123 Date: Wed, 15 May 2024 21:39:12 +0800 Subject: [PATCH] New: Update the danger workflow --- .github/workflows/danger_checks.yml | 80 ++++++++++++++++++---------- buildscripts/detekt.gradle | 29 +++++----- danger/dangerfiles/DangerAndroidLint | 6 +++ danger/dangerfiles/DangerDeteKt | 6 +++ danger/dangerfiles/DangerKtlint | 12 +++++ danger/dangerfiles/DangerPR | 13 +++++ danger/gemfiles/GemAndroidLint | 5 ++ danger/gemfiles/GemDeteKt | 6 +++ danger/gemfiles/GemKtlint | 5 ++ danger/gemfiles/GemPR | 5 ++ 10 files changed, 126 insertions(+), 41 deletions(-) create mode 100644 danger/dangerfiles/DangerAndroidLint create mode 100644 danger/dangerfiles/DangerDeteKt create mode 100644 danger/dangerfiles/DangerKtlint create mode 100644 danger/dangerfiles/DangerPR create mode 100644 danger/gemfiles/GemAndroidLint create mode 100644 danger/gemfiles/GemDeteKt create mode 100644 danger/gemfiles/GemKtlint create mode 100644 danger/gemfiles/GemPR diff --git a/.github/workflows/danger_checks.yml b/.github/workflows/danger_checks.yml index 6c475b62..c5135480 100644 --- a/.github/workflows/danger_checks.yml +++ b/.github/workflows/danger_checks.yml @@ -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 @@ -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: @@ -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 @@ -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: @@ -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 @@ -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: @@ -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 diff --git a/buildscripts/detekt.gradle b/buildscripts/detekt.gradle index 8260b42b..de6a18c1 100644 --- a/buildscripts/detekt.gradle +++ b/buildscripts/detekt.gradle @@ -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") } diff --git a/danger/dangerfiles/DangerAndroidLint b/danger/dangerfiles/DangerAndroidLint new file mode 100644 index 00000000..85c783c7 --- /dev/null +++ b/danger/dangerfiles/DangerAndroidLint @@ -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 diff --git a/danger/dangerfiles/DangerDeteKt b/danger/dangerfiles/DangerDeteKt new file mode 100644 index 00000000..53c50c8b --- /dev/null +++ b/danger/dangerfiles/DangerDeteKt @@ -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 diff --git a/danger/dangerfiles/DangerKtlint b/danger/dangerfiles/DangerKtlint new file mode 100644 index 00000000..071867d9 --- /dev/null +++ b/danger/dangerfiles/DangerKtlint @@ -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 diff --git a/danger/dangerfiles/DangerPR b/danger/dangerfiles/DangerPR new file mode 100644 index 00000000..7b9d57cd --- /dev/null +++ b/danger/dangerfiles/DangerPR @@ -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? diff --git a/danger/gemfiles/GemAndroidLint b/danger/gemfiles/GemAndroidLint new file mode 100644 index 00000000..305eafd5 --- /dev/null +++ b/danger/gemfiles/GemAndroidLint @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +gem 'danger-android_lint' diff --git a/danger/gemfiles/GemDeteKt b/danger/gemfiles/GemDeteKt new file mode 100644 index 00000000..8f098933 --- /dev/null +++ b/danger/gemfiles/GemDeteKt @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +gem 'oga' +gem 'danger-kotlin_detekt' diff --git a/danger/gemfiles/GemKtlint b/danger/gemfiles/GemKtlint new file mode 100644 index 00000000..93daab7a --- /dev/null +++ b/danger/gemfiles/GemKtlint @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +gem 'danger-ktlint' diff --git a/danger/gemfiles/GemPR b/danger/gemfiles/GemPR new file mode 100644 index 00000000..65a6ea41 --- /dev/null +++ b/danger/gemfiles/GemPR @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +gem 'danger'