• Stars
    star
    958
  • Rank 47,718 (Top 1.0 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚠️ Stop saying "you forgot to …" in code review


Formalize your Pull Request etiquette.

Write your Dangerfiles in Swift.

Requirements

Latest version requires Swift 5.5

If you are using an older Swift, use the supported version according to next table.

Swift version Danger support version
5.4 v3.15.0
5.3 v3.13.0
5.2 v3.11.1
5.1 v3.8.0
4.2 v2.0.7
4.1 v0.4.1
4.0 v0.3.6

What it looks like today

You can make a Dangerfile that looks through PR metadata, it's fully typed.

import Danger

let danger = Danger()
let allSourceFiles = danger.git.modifiedFiles + danger.git.createdFiles

let changelogChanged = allSourceFiles.contains("CHANGELOG.md")
let sourceChanges = allSourceFiles.first(where: { $0.hasPrefix("Sources") })

if !changelogChanged && sourceChanges != nil {
  warn("No CHANGELOG entry added.")
}

// You can use these functions to send feedback:
message("Highlight something in the table")
warn("Something pretty bad, but not important enough to fail the build")
fail("Something that must be changed")

markdown("Free-form markdown that goes under the table, so you can do whatever.")

Using Danger Swift

All of the docs are on the user-facing website: https://danger.systems/swift/

Commands

  • danger-swift ci - Use this on CI
  • danger-swift pr https://github.com/Moya/Harvey/pull/23 - Use this to build your Dangerfile
  • danger-swift local - Use this to run danger against your local changes from master
  • danger-swift edit - Creates a temporary Xcode project for working on a Dangerfile

Plugins

Infrastructure exists to support plugins, which can help you avoid repeating the same Danger rules across separate repos.

e.g. A plugin implemented with the following at https://github.com/username/DangerPlugin.git.

// DangerPlugin.swift
import Danger

public struct DangerPlugin {
    let danger = Danger()
    public static func doYourThing() {
        // Code goes here
    }
}

Swift Package Manager (More performant)

You can use Swift PM to install both danger-swift and your plugins:

  • Install Danger JS

    $ npm install -g danger
  • Add to your Package.swift:

    let package = Package(
        ...
        products: [
            ...
            .library(name: "DangerDeps[Product name (optional)]", type: .dynamic, targets: ["DangerDependencies"]), // dev
            ...
        ],
        dependencies: [
            ...
            .package(url: "https://github.com/danger/swift.git", from: "3.0.0"), // dev
            // Danger Plugins
            .package(url: "https://github.com/username/DangerPlugin.git", from: "0.1.0") // dev
            ...
        ],
        targets: [
            .target(name: "DangerDependencies", dependencies: ["Danger", "DangerPlugin"]), // dev
            ...
        ]
    )
  • Add the correct import to your Dangerfile.swift:

    import DangerPlugin
    
    DangerPlugin.doYourThing()
  • Create a folder called DangerDependencies in Sources with an empty file inside like Fake.swift

  • To run Danger use swift run danger-swift command

  • (Recommended) If you are using Swift PM to distribute your framework, use Rocket, or a similar tool, to comment out all the dev dependencies from your Package.swift. This prevents these dev dependencies from being downloaded and compiled with your framework by consumers.

  • (Recommended) cache the .build folder on your repo

Marathon (Easy to use)

By suffixing package: [url] to an import, you can directly import Swift PM package as a dependency

For example, a plugin could be used by the following.

// Dangerfile.swift

import DangerPlugin // package: https://github.com/username/DangerPlugin.git

DangerPlugin.doYourThing()

You can see an example danger-swift plugin.

(Recommended) Cache the ~/.danger-swift folder

Setup

For a Mac:

# Install danger-swift, and a bundled danger-js locally
brew install danger/tap/danger-swift
 # Run danger
danger-swift ci

For Linux:

# Install danger-swift
git clone https://github.com/danger/danger-swift.git
cd danger-swift
make install

# Install danger-js
npm install -g danger

 # Run danger
danger-swift ci

GitHub Actions

You can add danger/swift to your actions

jobs:
  build:
    runs-on: ubuntu-latest
    name: "Run Danger"
    steps:
      - uses: actions/checkout@v1
      - name: Danger
        uses: danger/[email protected]
        with:
            args: --failOnErrors --no-publish-check
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Danger has two different pre built images that you can use with your action:

In order to import one of those use the docker:// prefix

jobs:
  build:
    runs-on: ubuntu-latest
    name: "Run Danger"
    steps:
      - uses: actions/checkout@v1
      - name: Danger
        uses: docker://ghcr.io/danger/danger-swift:3.15.0
        with:
            args: --failOnErrors --no-publish-check
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Local compiled danger-js

To use a local compiled copy of danger-js use the danger-js-path argument:

danger-swift command --danger-js-path path/to/danger-js

Current working directory

Many people prefers using the SPM Danger configuration, because is more performing. But having a Package.swift on your root folder can be annoying, especially now that Xcode (from 11) doesn't put on the recents list an xcproj (or xcworkspace) when there is a Package.swift in the same folder. With the --cwd parameter you can specify a working directory. This allows you to have your Package.swift in another directory and still run danger-swift as it was executed from your project root directory.

swift run danger-swift command --cwd path/to/working-directory

Dev

You need to be using Xcode >= 13.2.1.

git clone https://github.com/danger/danger-swift.git
cd danger-swift
swift build
swift run komondor install
swift package generate-xcodeproj
open danger-swift.xcodeproj

Then I tend to run danger-swift using swift run:

swift run danger-swift pr https://github.com/danger/swift/pull/95

If you want to emulate how DangerJS's process will work entirely, then use:

swift build && cat Fixtures/eidolon_609.json | ./.build/debug/danger-swift

Deploying

Run swift run rocket $VERSION on master e.g. swift run rocket 1.0.0

Maintainer

Danger Swift is maintained by @f-meloni, and maybe you?

More Repositories

1

danger

🚫 Stop saying "you forgot to …" in code review (in Ruby)
Ruby
5,457
star
2

danger-js

⚠️ Stop saying "you forgot to …" in code review
TypeScript
5,001
star
3

kotlin

⚠️ Stop saying "you forgot to …" in code review
Kotlin
496
star
4

peril

☢️ Serious and immediate danger.
TypeScript
458
star
5

awesome-danger

An awesome list of all things Danger
317
star
6

python

⚠️ Stop saying "you forgot to …" in code review
Python
91
star
7

rust

⚠️ Stop saying "you forgot to …" in code review
Rust
42
star
8

dart

Dart
41
star
9

danger-mention

Danger plugin to automatically mention potential reviewers on pull requests
Ruby
29
star
10

design

Design Work and Media Kit
20
star
11

danger-plugin-template

An opinionated template for creating a Danger plugin
Ruby
19
star
12

danger-gitlab-gem

A gem that holds the GitLab specific dependency tree
Ruby
9
star
13

danger.systems

Old website for Danger.Systems -> New website =
HTML
9
star
14

peril.systems

Migrated into the main peril repo
TypeScript
7
star
15

generator-danger-plugin

Yeoman generator to generate a Danger plugin
JavaScript
6
star
16

peril-settings

🔎 The danger org's instance of Peril's settings
TypeScript
6
star
17

danger-plugin-api

A gem for Danger plugin authors to use to use for SemVer on the API
Ruby
5
star
18

hazmat

Web infrastructure management for Peril - migrated into the peril repo
TypeScript
5
star
19

danger-ts

An npx-able mix of Danger and TypeScript
JavaScript
4
star
20

homebrew-tap

The homebrew repo for Danger projects
Ruby
4
star
21

java

4
star
22

danger-js-gem

A gem that exists to ensure all dependencies are set up for Danger when using a JS Dangerfile.
Ruby
4
star
23

peril-settings-linter

A node module for listing the settings file
TypeScript
3
star
24

dangerfile-gem-template

A gem template for Dangerfile gems.
Ruby
2
star
25

dashboard.peril.systems

Migrated into the peril repo
TypeScript
1
star