Skip to content

Commit

Permalink
Add a script to automatically write the formula
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb committed Dec 29, 2023
1 parent 46dc2ab commit 932e7fb
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore assets downloaded by update script.
*_asset
4 changes: 1 addition & 3 deletions Formula/pls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ class Pls < Formula
if OS.mac?
url "https://github.com/pls-rs/pls/releases/download/v0.0.1-beta.3/pls-x86_64-apple-darwin.zip"
sha256 "5ba90ddb239fb1d76c462ebf3b7265a16b613651e230230b3b8c8c53e4e51c48"
end

if OS.linux?
elsif OS.linux?
url "https://github.com/pls-rs/pls/releases/download/v0.0.1-beta.3/pls-x86_64-unknown-linux-musl.zip"
sha256 "a8e30f7475ba339494d059aea37ecca7dcde2dd1ed1ecfbada0082a6ba8b429b"
end
Expand Down
29 changes: 29 additions & 0 deletions Template/pls.rb.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Pls < Formula
desc "Prettier and powerful ls for the pros"
homepage "https://pls.cli.rs/"
license "GPL-3.0-or-later"

if OS.mac?
url "{{ MAC_URL }}"
sha256 "{{ MAC_SHA }}"
elsif OS.linux?
url "{{ LINUX_URL }}"
sha256 "{{ LINUX_SHA }}"
end

depends_on "libgit2"

def install
bin.install "pls"
end

test do
linkage_with_libgit2 = (bin/"pls").dynamically_linked_libraries.any? do |dll|
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)

File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s
end

assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version."
end
end
28 changes: 28 additions & 0 deletions scripts/update_formula.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

REPO="pls-rs/pls"
RELEASE=$(curl -s "https://api.github.com/repos/${REPO}/releases" | jq -r '.[0]')

NAME=$(echo ${RELEASE} | jq -r '.name')
echo "Latest release is ${NAME}."

MAC_URL=$(echo ${RELEASE} | jq -r '.assets[] | select(.name | contains("apple-darwin")).browser_download_url')
echo "Downloading macOS asset from ${MAC_URL}."

curl -sL ${MAC_URL} -o mac_asset
MAC_SHA=$(shasum -a 256 mac_asset | awk '{ print $1 }')
echo "SHA256 for macOS asset is ${MAC_SHA}."

LINUX_URL=$(echo ${RELEASE} | jq -r '.assets[] | select(.name | contains("unknown-linux-musl")).browser_download_url')
echo "Downloading Linux asset from ${LINUX_URL}."

curl -sL ${LINUX_URL} -o linux_asset
LINUX_SHA=$(shasum -a 256 linux_asset | awk '{ print $1 }')
echo "SHA256 for Linux asset is ${LINUX_SHA}."

sed -e "s|{{ MAC_URL }}|$MAC_URL|g" \
-e "s|{{ MAC_SHA }}|$MAC_SHA|g" \
-e "s|{{ LINUX_URL }}|$LINUX_URL|g" \
-e "s|{{ LINUX_SHA }}|$LINUX_SHA|g" "Template/pls.rb.jinja" > "Formula/pls.rb"

echo "Formula written!"

0 comments on commit 932e7fb

Please sign in to comment.