Giter VIP home page Giter VIP logo

swift's Introduction


Formalize your Pull Request etiquette.

Write your Dangerfiles in Swift.

Requirements

Latest version requires Swift 4.2

  • If you are using Swift 4.1 use v0.4.1
  • If you are using Swift 4.0, Use 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:

  • 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: "1.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

With Docker support ready for GitHub Actions.

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

Dev

You need to be using Xcode 10.

git clone https://github.com/danger/danger-swift.git
cd danger-swift
swift build
swift run komondor install
swift package generate-xcodeproj
open Danger.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

Long-term

I, orta, only plan on bootstrapping this project, as I won't be using this in production. I'm happy to help support others who want to own this idea and really make it shine though! So if you're interested in helping out, make a few PRs and I'll give you org access.

swift's People

Contributors

absolute-heike avatar acecilia avatar alvarhansen avatar ashfurrow avatar atul9 avatar chaoscoder avatar d-date avatar eneko avatar f-meloni avatar fabiotacke avatar fassko avatar hirad avatar hiragram avatar josephduffy avatar jpmartha avatar kdawgwilk avatar orta avatar peril-staging[bot] avatar petrpavlik avatar roland9 avatar sd10 avatar sega-zero avatar sunshinejr avatar tylermilner avatar vknabel avatar yhkaplan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.