{"id":13683670,"url":"https://github.com/danger/swift","last_synced_at":"2025-05-14T08:06:29.263Z","repository":{"id":37549727,"uuid":"101339212","full_name":"danger/swift","owner":"danger","description":"⚠️ Stop saying \"you forgot to …\" in code review","archived":false,"fork":false,"pushed_at":"2025-05-13T14:58:25.000Z","size":2394,"stargazers_count":1093,"open_issues_count":83,"forks_count":146,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-05-13T15:56:23.368Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://danger.systems/swift/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danger.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["f-meloni"]}},"created_at":"2017-08-24T21:30:03.000Z","updated_at":"2025-05-13T14:58:31.000Z","dependencies_parsed_at":"2025-05-13T15:57:39.019Z","dependency_job_id":null,"html_url":"https://github.com/danger/swift","commit_stats":{"total_commits":1369,"total_committers":81,"mean_commits":"16.901234567901234","dds":0.3973703433162893,"last_synced_commit":"b41494ac499c6b5ab83acdc379e366c918d18022"},"previous_names":["danger/danger-swift"],"tags_count":99,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danger%2Fswift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danger%2Fswift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danger%2Fswift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danger%2Fswift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danger","download_url":"https://codeload.github.com/danger/swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101616,"owners_count":22014909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T13:02:21.968Z","updated_at":"2025-05-14T08:06:24.240Z","avatar_url":"https://github.com/danger.png","language":"Swift","funding_links":["https://github.com/sponsors/f-meloni"],"categories":["Swift"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://danger.systems/images/js/danger-js-sw-logo-hero-cachable@2x.png\" width=350 /\u003e\u003c/br\u003e\nFormalize your Pull Request etiquette.\n\u003c/p\u003e\n\nWrite your Dangerfiles in Swift.\n\n### Requirements\n\nLatest version requires Swift 5.8\n\nIf you are using an older Swift, use the supported version according to next table.\n\n| Swift version | Danger support version |\n| ------------- | ---------------------- |\n| 5.5-5.7       | v3.18.1                |\n| 5.4           | v3.15.0                |\n| 5.3           | v3.13.0                |\n| 5.2           | v3.11.1                |\n| 5.1           | v3.8.0                 |\n| 4.2           | v2.0.7                 |\n| 4.1           | v0.4.1                 |\n| 4.0           | v0.3.6                 |\n\n### What it looks like today\n\nYou can make a Dangerfile that looks through PR metadata, it's fully typed.\n\n```swift\nimport Danger\n\nlet danger = Danger()\nlet allSourceFiles = danger.git.modifiedFiles + danger.git.createdFiles\n\nlet changelogChanged = allSourceFiles.contains(\"CHANGELOG.md\")\nlet sourceChanges = allSourceFiles.first(where: { $0.hasPrefix(\"Sources\") })\n\nif !changelogChanged \u0026\u0026 sourceChanges != nil {\n  warn(\"No CHANGELOG entry added.\")\n}\n\n// You can use these functions to send feedback:\nmessage(\"Highlight something in the table\")\nwarn(\"Something pretty bad, but not important enough to fail the build\")\nfail(\"Something that must be changed\")\n\nmarkdown(\"Free-form markdown that goes under the table, so you can do whatever.\")\n```\n\n### Using Danger Swift\n\nAll of the docs are on the user-facing website: https://danger.systems/swift/\n\n### Commands\n\n- `danger-swift ci` - Use this on CI\n- `danger-swift pr https://github.com/Moya/Harvey/pull/23` - Use this to build your Dangerfile\n- `danger-swift local` - Use this to run danger against your local changes from master\n- `danger-swift edit` - Creates a temporary Xcode project for working on a Dangerfile\n\n#### Plugins\n\nInfrastructure exists to support plugins, which can help you avoid repeating the same Danger rules across separate\nrepos.\n\ne.g. A plugin implemented with the following at https://github.com/username/DangerPlugin.git.\n\n```swift\n// DangerPlugin.swift\nimport Danger\n\npublic struct DangerPlugin {\n    let danger = Danger()\n    public static func doYourThing() {\n        // Code goes here\n    }\n}\n```\n\n#### Swift Package Manager (More performant)\n\nYou can use Swift PM to install both `danger-swift` and your plugins:\n\n- Install Danger JS\n\n  ```bash\n  $ npm install -g danger\n  ```\n\n- Add to your `Package.swift`:\n\n  ```swift\n  let package = Package(\n      ...\n      products: [\n          ...\n          .library(name: \"DangerDeps[Product name (optional)]\", type: .dynamic, targets: [\"DangerDependencies\"]), // dev\n          ...\n      ],\n      dependencies: [\n          ...\n          .package(url: \"https://github.com/danger/swift.git\", from: \"3.0.0\"), // dev\n          // Danger Plugins\n          .package(url: \"https://github.com/username/DangerPlugin.git\", from: \"0.1.0\") // dev\n          ...\n      ],\n      targets: [\n          .target(name: \"DangerDependencies\", dependencies: [\"Danger\", \"DangerPlugin\"]), // dev\n          ...\n      ]\n  )\n  ```\n\n- Add the correct import to your `Dangerfile.swift`:\n\n  ```swift\n  import DangerPlugin\n\n  DangerPlugin.doYourThing()\n  ```\n\n- Create a folder called `DangerDependencies` in `Sources` with an empty file inside like\n  [Fake.swift](Sources/Danger-Swift/Fake.swift)\n- To run `Danger` use `swift run danger-swift command`\n- **(Recommended)** If you are using Swift PM to distribute your framework, use\n  [Rocket](https://github.com/f-meloni/Rocket), or a similar tool, to comment out all the dev dependencies from your\n  `Package.swift`. This prevents these dev dependencies from being downloaded and compiled with your framework by\n  consumers.\n- **(Recommended)** cache the `.build` folder on your repo\n\n#### Marathon (Easy to use)\n\nBy suffixing `package: [url]` to an import, you can directly import Swift PM package as a dependency\n\nFor example, a plugin could be used by the following.\n\n```swift\n// Dangerfile.swift\n\nimport DangerPlugin // package: https://github.com/username/DangerPlugin.git\n\nDangerPlugin.doYourThing()\n```\n\nYou can see an [example danger-swift plugin](https://github.com/ashfurrow/danger-swiftlint#danger-swiftlint).\n\n**(Recommended)** Cache the `~/.danger-swift` folder\n\n### Setup\n\nFor a Mac:\n\n```sh\n# Install danger-swift, and a bundled danger-js locally\nbrew install danger/tap/danger-swift\n # Run danger\ndanger-swift ci\n```\n\nFor Linux:\n\n```sh\n# Install danger-swift\ngit clone https://github.com/danger/danger-swift.git\ncd danger-swift\nmake install\n\n# Install danger-js\nnpm install -g danger\n\n # Run danger\ndanger-swift ci\n```\n\nGitHub Actions\n\nYou can add danger/swift to your actions\n\n```yml\njobs:\n  build:\n    runs-on: ubuntu-latest\n    name: \"Run Danger\"\n    steps:\n      - uses: actions/checkout@v1\n      - name: Danger\n        uses: danger/swift@3.15.0\n        with:\n            args: --failOnErrors --no-publish-check\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n```\n\nDanger has two different pre built images that you can use with your action:\n- https://github.com/orgs/danger/packages/container/package/danger-swift\n- https://github.com/orgs/danger/packages/container/package/danger-swift-with-swiftlint (Danger + Swiftlint)\n\nIn order to import one of those use the `docker://` prefix\n\n```yml\njobs:\n  build:\n    runs-on: ubuntu-latest\n    name: \"Run Danger\"\n    steps:\n      - uses: actions/checkout@v1\n      - name: Danger\n        uses: docker://ghcr.io/danger/danger-swift:3.15.0\n        with:\n            args: --failOnErrors --no-publish-check\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n```\n\n#### Local compiled danger-js\n\nTo use a local compiled copy of danger-js use the `danger-js-path` argument:\n\n```bash\ndanger-swift command --danger-js-path path/to/danger-js\n```\n\n#### Current working directory\n\nMany people prefer using Danger within a Swift Package via SPM, because is more performant. \n\nWhen doing so, however, having a `Package.swift` in the root folder can be annoying, especially now that Xcode (since Xcode 11) doesn't show a `xcproj` (or `xcworkspace`) on the Open Recents menu when there is a `Package.swift` in the same folder.\n\nWith the `--cwd` parameter you can specify a working directory.\nThis allows you to have your `Package.swift` in another directory and still run danger-swift as it was executed from your project root directory. \n\n```swift\nswift run danger-swift command --cwd path/to/working-directory\n```\n\nNote that to do this, you must run `danger-swift` from the directory where the `Package.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 named **Danger** in the top level of your repo for these files, you would need to `cd Danger` and then run the command `[swift run] danger-swift cmd \u003ccmd parameters\u003e --cwd ..` to tell Danger that it should look at the directory above where the command was executed to correctly invoke the tool.\n\n#### Dev\n\nYou need to be using Xcode \u003e= 13.2.1.\n\n```sh\ngit clone https://github.com/danger/danger-swift.git\ncd danger-swift\nswift build\nswift run komondor install\nswift package generate-xcodeproj\nopen danger-swift.xcodeproj\n```\n\nThen I tend to run `danger-swift` using `swift run`:\n\n```sh\nswift run danger-swift pr https://github.com/danger/swift/pull/95\n```\n\nIf you want to emulate how DangerJS's `process` will work entirely, then use:\n\n```sh\nswift build \u0026\u0026 cat Fixtures/eidolon_609.json | ./.build/debug/danger-swift\n```\n\n#### Deploying\n\nRun `swift run rocket $VERSION` on `master` e.g. `swift run rocket 1.0.0`\n\n### Maintainer\n\nDanger Swift is maintained by [@f-meloni](https://github.com/f-meloni), and maybe you?\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanger%2Fswift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanger%2Fswift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanger%2Fswift/lists"}