Last active
December 4, 2019 13:19
-
-
Save hkusu/3a1d60c4d441ad8fa2b8a3749015809a to your computer and use it in GitHub Desktop.
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
// 各モジュールの build.gradle で設定する | |
// gradle/ktlint.gradle に記述を切り出して各 build.gradle で apply from: rootProject.file('gradle/ktlint.gradle') とした方が良いかも | |
// ... | |
configurations { | |
ktlint | |
} | |
dependencies { | |
ktlint "com.pinterest:ktlint:0.34.2" | |
} | |
task ktlint(type: JavaExec, group: "verification") { | |
description = "Check Kotlin code style." | |
classpath = configurations.ktlint | |
main = "com.pinterest.ktlint.Main" | |
args "--android", "--color", "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/reports/ktlint-results.xml", "src/**/*.kt" | |
ignoreExitValue true | |
} | |
check.dependsOn ktlint |
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
name: Check pull request | |
on: pull_request | |
jobs: | |
check: | |
name: Check pull request | |
runs-on: ubuntu-18.04 | |
steps: | |
- uses: actions/checkout@v1 | |
- uses: actions/setup-java@v1 | |
with: | |
java-version: 1.8 | |
- uses: actions/setup-ruby@v1 | |
with: | |
ruby-version: '2.6' | |
architecture: 'x64' | |
- name: Get gem directory | |
id: gem-dir | |
run: echo "::set-output name=dir::$(gem environment gemdir)" | |
- uses: actions/cache@v1 # ~/.gradle配下は400Mを超えるので現状ではキャッシュできない.. | |
with: | |
path: ${{ steps.gem-dir.outputs.dir }} | |
key: ${{ runner.os }}-gem-${{ hashFiles('.github/workflows/check-pull-request.yml') }} | |
restore-keys: ${{ runner.os }}-gem- | |
- name: Run ktlint | |
run: ./gradlew ktlint | |
- name: Run Android Lint # フレーバー・ビルドタイプがモジュール毎に異なる場合はモジュール毎に ./gradlew app:lintHoge する | |
run: ./gradlew lintDebug | |
- name: Set up and run Danger | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gem install danger | |
gem install danger-checkstyle_format | |
gem install danger-android_lint | |
danger | |
- name: Run Unit Test # フレーバー・ビルドタイプがモジュール毎に異なる場合はモジュール毎に ./gradlew app:lintHogeUnitTest する | |
run: ./gradlew testDebugUnitTest | |
notify-success: | |
name: Notify success | |
needs: [check] | |
runs-on: ubuntu-18.04 | |
steps: | |
- name: Notify Slack | |
run: | | |
curl -X POST \ | |
-H 'Content-type: application/json' \ | |
-H 'Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}' \ | |
-d '{"channel":"kusu_test_github","username":"github-actions","icon_url":"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png","text":"Success"}' \ | |
https://slack.com/api/chat.postMessage | |
notify-failure: | |
name: Notify failure | |
needs: [check] | |
if: failure() | |
runs-on: ubuntu-18.04 | |
steps: | |
- name: Notify Slack | |
run: | | |
curl -X POST \ | |
-H 'Content-type: application/json' \ | |
-H 'Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}' \ | |
-d '{"channel":"kusu_test_github","username":"github-actions","icon_url":"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png","text":"Failure"}' \ | |
https://slack.com/api/chat.postMessage |
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
github.dismiss_out_of_range_messages | |
# ktlint | |
Dir.glob("**//build/reports/ktlint-results.xml").each { |report| | |
checkstyle_format.base_path = Dir.pwd | |
checkstyle_format.report report.to_s | |
} | |
# Android Lint | |
Dir.glob("**//build/reports/lint-results*.xml").each { |report| | |
android_lint.skip_gradle_task = true | |
android_lint.report_file = report.to_s | |
android_lint.filtering = true | |
android_lint.lint(inline_mode: true) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment