Skip to content

How to run Danger swift

lmarceau edited this page Oct 22, 2025 · 3 revisions

Context

We're using Danger Swift in our CI pipeline to automate some code checks on pull requests. Here's how you can modify and run the Dangerfile.swift.

How to run locally

Let’s run the Dangerfile.swift against an existing PR. It will only leave messages in your terminal, not on the PR. Those steps are sumamrized from the Danger documentation.

  1. You can install Danger locally with Brew running brew install danger/tap/danger-swift.
  2. Create a personal access token here since Danger needs it to run. Take note of that access token somewhere safe.
  3. Add your token to your terminal export DANGER_GITHUB_API_TOKEN='your_token'
  4. You can then run the Dangerfile.swift locally on an opened PR with the command swift run danger-swift pr https://github.com/mozilla-mobile/firefox-ios/pull/TODO. Just replace the command with the PR number you want it to run on.

How to run with code coverage

Some parts of the Dangerfile.swift code relies on the code coverage information. To run those specific functions, you need to generate the code coverage JSON file with the following command. Replace the TODO with your own derived data information.

xcrun xccov view --report --json ~/Library/Developer/Xcode/DerivedData/Client-TODO/Logs/Test/*.xcresult > coverage.json

Writing new Danger functions

You can refer to the Danger Github API here.

Clone this wiki locally