Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork151
License
danger/swift
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Formalize your Pull Request etiquette.
Write your Dangerfiles in Swift.
Latest version requires Swift 5.8
If you are using an older Swift, use the supported version according to next table.
| Swift version | Danger support version |
|---|---|
| 5.5-5.7 | v3.18.1 |
| 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 |
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.")
All of the docs are on the user-facing website:https://danger.systems/swift/
danger-swift ci- Use this on CIdanger-swift pr https://github.com/Moya/Harvey/pull/23- Use this to build your Dangerfiledanger-swift local- Use this to run danger against your local changes from masterdanger-swift edit- Creates a temporary Xcode project for working on a Dangerfile
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}}
You can use Swift PM to install bothdanger-swift and your plugins:
Install Danger JS
$ npm install -g danger
Add to your
Package.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 your
Dangerfile.swift:import DangerPluginDangerPlugin.doYourThing()
Create a folder called
DangerDependenciesinSourceswith an empty file inside likeFake.swiftTo run
Dangeruseswift 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 your
Package.swift. This prevents these dev dependencies from being downloaded and compiled with your framework byconsumers.(Recommended) cache the
.buildfolder on your repo
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
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:
- https://github.com/orgs/danger/packages/container/package/danger-swift
- https://github.com/orgs/danger/packages/container/package/danger-swift-with-swiftlint (Danger + Swiftlint)
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 }}
To use a local compiled copy of danger-js use thedanger-js-path argument:
danger-swiftcommand --danger-js-path path/to/danger-jsMany 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.
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.xcodeprojThen 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
Runswift run rocket $VERSION onmaster e.g.swift run rocket 1.0.0
Danger Swift is maintained by@f-meloni, and maybe you?
About
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
