danger / swift

⚠️ Stop saying "you forgot to …" in code review
https://danger.systems/swift/
MIT License
1.05k stars 135 forks source link

Speed-up danger swift on Bitrise #404

Open andr3a88 opened 3 years ago

andr3a88 commented 3 years ago

Hi, do you know a way to speed up the installation of danger-swift on Bitrise? Currently it takes me 4 minutes for the step

+---+---------------------------------------------------------------+----------+
| ✓ | Brew install danger-swift                                     | 4.1 min  |
+---+---------------------------------------------------------------+----------+

Step detail:

Run brew command
$ brew "install" "danger/tap/danger-swift"
==> Tapping danger/tap
Cloning into '/usr/local/Homebrew/Library/Taps/danger/homebrew-tap'...
Tapped 3 formulae (30 files, 124.2KB).
==> Installing danger-swift from danger/tap
==> Downloading https://github.com/danger/danger-js/releases/download/10.6.0/danger-macos.zip
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/66146807/e1523e80-4edb-11eb-840e-b4523ac1fca2?X-Amz-Algorithm=AWS4-HMAC-SHA236&X-Amz-Credential=AKIAIWNJYAX2H53A%2F20210115%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210115T170144Z&X-Amz-Expires=300&X-Amz-Signature=c151fbfcf171f7c7abd2f07b28a6ddd3a459ef6f0ba7a58045fd93bfeaaac3c5&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=66146807&response-content-disposition=attachment%3B%20filename%3Ddanger-macos.zip&response-content-type=application%2Foctet-stream
==> Downloading https://github.com/danger/danger-swift/archive/3.7.1.tar.gz
==> Downloading from https://codeload.github.com/danger/swift/tar.gz/3.7.1
==> Installing dependencies for danger/tap/danger-swift: danger/tap/danger-js
==> Installing danger/tap/danger-swift dependency: danger/tap/danger-js
🍺  /usr/local/Cellar/danger-js/10.6.0: 3 files, 84MB, built in 5 seconds
==> Installing danger/tap/danger-swift
==> make install PREFIX=/usr/local/Cellar/danger-swift/3.7.1
🍺  /usr/local/Cellar/danger-swift/3.7.1: 19 files, 11.5MB, built in 2 minutes 42 seconds
orta commented 3 years ago

I'd recommend using SwiftPM and caching your build dir probably

rogerluan commented 3 years ago

☝️ Yeah, it takes ~16 seconds here using SPM (also on Bitrise)

andr3a88 commented 3 years ago

@rogerluan do you use a specific step on bitrise?

rogerluan commented 3 years ago

Nope, just a script directly:

swift run danger-swift ci --id 'Danger: Static Analysis' --dangerfile ./Dangerfile.swift
andr3a88 commented 3 years ago

@rogerluan Is it possible to use SPM even if I don't use it in my main project? I don't want to create confusion in the root folder, do you have an example of a basic configuration?

rogerluan commented 3 years ago

Yes it is, I used to not use SPM in the main project either. I don't mean to be rude but you can check installation steps here https://danger.systems/swift/guides/getting_started.html#installation 🙈 It's pretty much creating a fake file in the project, and a Package.swift file in the root folder. Do notice, however that you'll have to open your project by clicking the .xcworkspace file and not the package.swift, to launch your main project. :)

andr3a88 commented 3 years ago

@rogerluan thanks for the information.

I tried with this simple Package.swift:

// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "DangerSwiftBitriseStep",
    dependencies: [
      .package(name: "danger-swift", url: "https://github.com/danger/swift.git", from: "3.0.0")
    ],
    targets: [
        .target(name: "DangerSwiftBitriseStep", dependencies: ["danger-swift"], path: "Sources", sources: ["Fake.swift"]),
    ]
)

Locally works fine, when i run on Bitrise i have this error during git-clone step

fatal: No url found for submodule path 'DangerSwift/.build/checkouts/Logger' in .gitmodules
ERROR: submodule update: fatal: No url found for submodule path 'DangerSwift/.build/checkouts/Logger' in .gitmodules

I will see next week if I continue on this path, Bitrise many times makes me lose more time than necessary

rogerluan commented 3 years ago

Try this:

// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "your-main-target-name",
    dependencies: [
        .package(name: "danger-swift", url: "https://github.com/danger/swift", from: "3.7.2"),
    ],
    targets: [
        // This is just an arbitrary Swift file in our app, that has
        // no dependencies outside of Foundation, the dependencies section
        // ensures that the library for Danger gets build also.
        .target(name: "your-main-target-name", dependencies: [
            .product(name: "Danger", package: "danger-swift"),
        ], path: "your-main-target-name", sources: [ "Fake.swift" ]),
    ]
)
AvdLee commented 2 years ago

FYI: Danger is pre-installed on Bitrise. If you cache the .build directory it should actually be super fast

colinhumber commented 2 years ago
fatal: No url found for submodule path 'DangerSwift/.build/checkouts/Logger' in .gitmodules
ERROR: submodule update: fatal: No url found for submodule path 'DangerSwift/.build/checkouts/Logger' in .gitmodules

I've run into this error as well. I'm not sure if I'm caching the .build directory correctly. When I include it in our repo I get a git warning:

hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint:   git submodule add <url> .build/checkouts/Logger
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint:   git rm --cached .build/checkouts/Logger
hint: 
hint: See "git help submodule" for more information.

I'm sure I'm just missing something really basic or misunderstanding where things should be cached 😅

colinhumber commented 2 years ago

Oh nevermind. I was caching in the repo, not on the CI machine itself. 🤦🏼‍♂️