Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

danger/swift

Repository files navigation


Formalize your Pull Request etiquette.

Write your Dangerfiles in Swift.

Requirements

Latest version requires Swift 5.8

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

Swift versionDanger support version
5.5-5.7v3.18.1
5.4v3.15.0
5.3v3.13.0
5.2v3.11.1
5.1v3.8.0
4.2v2.0.7
4.1v0.4.1
4.0v0.3.6

What it looks like today

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

import Dangerletdanger=Danger()letallSourceFiles= danger.git.modifiedFiles+ danger.git.createdFilesletchangelogChanged= allSourceFiles.contains("CHANGELOG.md")letsourceChanges= 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 separaterepos.

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

// DangerPlugin.swiftimport DangerpublicstructDangerPlugin{letdanger=Danger()publicstaticfunc doYourThing(){        // Code goes here}}

Swift Package Manager (More performant)

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

  • Install Danger JS

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

    letpackage=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 yourDangerfile.swift:

    import DangerPluginDangerPlugin.doYourThing()
  • Create a folder calledDangerDependencies inSources with an empty file inside likeFake.swift

  • To runDanger useswift run danger-swift command

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

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

Marathon (Easy to use)

By suffixingpackage: [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.swiftimport DangerPlugin // package: https://github.com/username/DangerPlugin.gitDangerPlugin.doYourThing()

You can see anexample danger-swift plugin.

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

Setup

For a Mac:

# Install danger-swift, and a bundled danger-js locallybrew install danger/tap/danger-swift# Run dangerdanger-swift ci

For Linux:

# Install danger-swiftgit clone https://github.com/danger/danger-swift.gitcd danger-swiftmake install# Install danger-jsnpm install -g danger# Run dangerdanger-swift ci

GitHub Actions

You can add danger/swift to your actions

jobs:build:runs-on:ubuntu-latestname:"Run Danger"steps:      -uses:actions/checkout@v1      -name:Dangeruses:danger/swift@3.15.0with:args:--failOnErrors --no-publish-checkenv: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 thedocker:// prefix

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

Local compiled danger-js

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

danger-swiftcommand --danger-js-path path/to/danger-js

Current working directory

Many people prefer using Danger within a Swift Package via SPM, because is more performant.

When doing so, however, having aPackage.swift in the root folder can be annoying, especially now that Xcode (since Xcode 11) doesn't show axcproj (orxcworkspace) on the Open Recents menu when there is aPackage.swift in the same folder.

With the--cwd parameter you can specify a working directory.This allows you to have yourPackage.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

Note that to do this, you must rundanger-swift from the directory where thePackage.swift is located, and pass the top-level directory relative to this directory to the--cwd command-line switch. For example, if you create a folder namedDanger in the top level of your repo for these files, you would need tocd Danger and then run the command[swift run] danger-swift cmd <cmd parameters> --cwd .. to tell Danger that it should look at the directory above where the command was executed to correctly invoke the tool.

Dev

You need to be using Xcode >= 13.2.1.

git clone https://github.com/danger/danger-swift.gitcd danger-swiftswift buildswift run komondor installswift package generate-xcodeprojopen danger-swift.xcodeproj

Then I tend to rundanger-swift usingswift run:

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

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

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

Deploying

Runswift run rocket $VERSION onmaster e.g.swift run rocket 1.0.0

Maintainer

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

About

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

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors76

Languages


[8]ページ先頭

©2009-2025 Movatter.jp