nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.9k stars 639 forks source link

Attach SPM artifact bundle to GitHub release #1213

Closed lordcodes closed 2 years ago

lordcodes commented 2 years ago

SPM has support for including command-line tools as a binary target. This allows you to depend purely on the binary without including the full source (and all its dependencies).

To support this there is an artifact bundle format specified by SPM, which you could build yourself and include into your tool, however, you can attach this to each GitHub release, which allows tools to depend on them using the URL of the GitHub release, so that they can link to that version.

For example, SwiftLint has started including this on their releases: https://github.com/realm/SwiftLint/releases/tag/0.47.1 as SwiftLintBinary-macos.artifactbundle.zip.

You can then use the tool via the SPM binary target format:

.binaryTarget(
    name: "SwiftFormat",
    url: "https://github.com/nicklockwood/SwiftFormat/releases/download/0.49.11/swiftformat-macos.artifactbundle.zip",
    checksum: "CHECKSUM"
),

I am currently building a 'Tuist' plugin and potentially SPM plugin to run SwiftLint and SwiftFormat and would use them via binaryTargets. In the meantime I will create a SwiftFormat fork and include the artifact bundle on a GitHub release on the fork.

I would happily contribute a PR to add creating this artifact bundle as part of the release process automatically. However, from looking it seemed like the release process of SwiftFormat involves building the binaries manually.

I can see the 'swiftformat' binary is actually included directly into the repo within the 'CommandLine' folder rather than just as source and so there could just be a simple script included that takes that binary and puts it into the 'artifactbundle' ZIP format so that it can then be attached to the release when the release is created on GitHub.

nicklockwood commented 2 years ago

@lordcodes that sounds great! I'd be happy to accept a PR.

lordcodes commented 2 years ago

@nicklockwood What sort of thing would you want for the release process? A shell script in the root that copies the binary from CommandLineTool into the right structure and outputs a ZIP?

nicklockwood commented 2 years ago

@lordcodes I was thinking a github action, but I guess a script I can locally would be even better.

lordcodes commented 2 years ago

I wasn't sure of the process for doing a release of SwiftFormat, so whatever fits into that best I guess. If the release was automated, where you just trigger it on GitHub Actions or create a tag, then using an action would be best to avoid forgetting to create the artifact bundle each time. However, if the release is manual then a script is best I guess to give flexibility. I will create a PR 👍🏻