Maintaining a Homebrew Tap for Swift Projects

brew install mxcl/made/swift-sh

Why Should I Do This?

How To Make a Tap

  1. Tag a release for your project ✻
  2. Create a new repository on GitHub, name it homebrew-tap
  3. Add a file called your-project.rb, adapting the following:
class ProjectName < Formula
desc "Describe your project"
homepage "https://github.com/your/project"
url "https://github.com/your/project/archive/1.2.3.tar.gz"
def install
system "swift", "build",
"--configuration", "release",
"--disable-sandbox"
bin.install '.build/release/your-project'
end
end
class ProjectName < Formula
desc "…"
homepage ""
url ""
sha256 "INSERT-SHA256-HERE" def install
# …
end
end

Automating Formula Updates

os: osx
language: swift
osx_image: xcode10.2
env:
- HOMEBREW_NO_AUTO_UPDATE=1
- HOMEBREW_NO_INSTALL_CLEANUP=1
deploy:
provider: script
on:
all_branches: true
condition: $TRAVIS_BRANCH =~ ^v?\d+\.\d+\.\d+$
script:
- USER=$(dirname $TRAVIS_REPO_SLUG)
- PROJ=$(basename $TRAVIS_REPO_SLUG)
- URL="https://github.com/$TRAVIS_SLUG/archive/$TRAVIS_TAG.tar.gz"
- ORIGIN="https://$GITHUB_TOKEN@github.com/$USER/homebrew-tap.git"
# grab the tap
- brew tap $USER/homebrew-tap
- cd /usr/local/Homebrew/Library/Taps/$USER/homebrew-tap

# update the formula URL
- sed -E -i '' 's~^ url ".+"~ url "'$URL\"~ ./swift-sh.rb
- brew fetch $PROJ || true
# ^^ fails because SHA is wrong, hence || true

# figure out the sha
- SHA256=$(shasum --algorithm 256 $(brew --cache --build-from-source $PROJ) | awk '{print $1}')

# update the formula SHA
- sed -E -i '' 's/^ sha256 ".+"/ sha256 "'$SHA256\"/ $PROJ.rb
# commit to the tap
- git remote set-url origin "$ORIGIN"
- git add $PROJ.rb
- git config user.name "Travis"
- git config user.email "bot@travis-ci.com"
- git commit -m "$PROJ $TRAVIS_TAG"
- git push origin master

Automatic Bottling

Optional Extras

Add Travis for Your Tap

An Idea

  1. Scan GitHub periodically for new Package.swift which build binaries
  2. Create formula for those repos (via a template obv.)
  3. Periodically scan for new releases for those repos and update the formula

--

--

--

ceo@tea.inc.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The 12 Factor Data Architecture - enabling a modern event driven data fabric

Kubernetes, Strimzi, Amazon MSK and Kafka-Proxy: A recipe for automation

A beginners guide to Ruby on Rails!

Vocaloid and UTAU

Resiliency Patterns with Ninja — CNCF Roadmap

What new features to build

Hacking the Tenda AC10–1200 Router Part 4: sscanf buffer overflow

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Max Howell

Max Howell

ceo@tea.inc.

More from Medium

Guide to manage secrets in SwiftUI app

New configuration file

Integrate a complex Swift Package into your iOS app

How to embed a UIKit Alert with Text Field in SwiftUI

An iPhone that displays an Alert with Text Field on a wooden table.

How To Create Localizable And Use For Swift