The project is now on a stable version.
Is possible to generate a working danger-kotlin instance from the code that is currently on this repo, or use it via GitHub actions or brew.
You can make a Dangerfile.df.kts in your root project that looks through PR metadata, it's fully typed.
import systems.danger.kotlin.*
danger(args) {
val allSourceFiles = git.modifiedFiles + git.createdFiles
val changelogChanged = allSourceFiles.contains("CHANGELOG.md")
val sourceChanges = allSourceFiles.firstOrNull { it.contains("src") }
onGitHub {
val isTrivial = pullRequest.title.contains("#trivial")
// Changelog
if (!isTrivial && !changelogChanged && sourceChanges != null) {
warn(WordUtils.capitalize("any changes to library code should be reflected in the Changelog.\n\nPlease consider adding a note there and adhere to the [Changelog Guidelines](https://github.com/Moya/contributors/blob/master/Changelog%20Guidelines.md)."))
}
// Big PR Check
if ((pullRequest.additions ?: 0) - (pullRequest.deletions ?: 0) > 300) {
warn("Big PR, try to keep changes smaller if you can")
}
// Work in progress check
if (pullRequest.title.contains("WIP", false)) {
warn("PR is classed as Work in Progress")
}
}
}docker run --rm -v "${PWD}:/code" -w /code ghcr.io/danger/danger-kotlin:1.3.3 danger-kotlin localbrew install danger/tap/danger-kotlinbrew install danger/tap/danger-kotlin-intelYou need to have Xcode installed and not relying on command line tools. If you're seeing this error when running xcodebuild:
$ xcodebuild -version
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instanceYou can fix it with:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developerbash <(curl -s https://raw.githubusercontent.com/danger/kotlin/master/scripts/install.sh)
source ~/.bash_profileYou can add danger/kotlin to your actions
Parameters:
dangerfile: Path to danger file, required:false, default:Dangerfile.df.ktsrun-mode: Run mode:ci,local,pr, required:falsedefault:cijob-id:Reported CI job ID, required:false, default:danger/kotlinargs: Extra custom arguments like "--failOnErrors --no-publish-check" and etc, required:false
jobs:
build:
runs-on: ubuntu-latest
name: "Run Danger"
steps:
- uses: actions/checkout@v4
- name: Danger
uses: danger/kotlin@1.3.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}Danger a pre built images that you can use with your action:
https://github.com/orgs/danger/packages/container/package/danger-kotlin In order to import one of those use the docker:// prefix
jobs:
build:
runs-on: ubuntu-latest
name: "Run Danger"
container:
image: docker://ghcr.io/danger/danger-kotlin:1.3.3
steps:
- uses: actions/checkout@v4
- name: Run Danger
run: danger-kotlin ci --failOnErrors --no-publish-check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}You can activate the autocomplete following this additional steps:
- Install danger on your local machine
- Go to
Preferences -> Build, Execution, Deployment -> Compiler -> Kotlin Compiler(Preferences -> Kotlin Compilerin Android Studio, Recent Android Studio versions will show this option when you close all project and open the Settings from the initial screen) - At the bottom you will find a section
Kotlin Scripting - Complete the field
Script template classeswithsystems.danger.kts.DangerFileScript - Complete the field
Script templates classpathwith/usr/local/lib/danger/danger-kotlin.jar - Go to
Preferences -> Language & Frameworks -> Kotlin -> Kotlin Scripting - Make sure the script template
DangerFileScriptis active and above the defaultKotlin Script - Apply changes
- If opening the
Dangerfile.df.ktsthe autocomplete and syntax highlighting doesn't work, try to reboot your IDE or open the Dangerfile from your IDE as a single file. - If it still doesn't work, go to
Help -> Edit Custom VM Options...and add-Dkotlin.script.classpath=<path>/danger-kotlin.jar(replace the<path>with the absolute path to the JAR). Then restart the IDE. - You may also need to disable the "K2 mode" (search the settings for it) if you enabled it previously.
You can use any external dependency by adding the following lines at the top of your Dangerfile.df.kts
@file:Repository("https://repo.maven.apache.org")
@file:DependsOn("groupId:artifactId:version")danger-kotlin ci- Use this on CIdanger-kotlin pr https://github.com/Moya/Harvey/pull/23- Use this to build your Dangerfiledanger-kotlin local- Use this to run danger against your local changes from master
