Skip to content

Commit

Permalink
Update tap on release
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb committed Dec 30, 2023
1 parent 95d8967 commit 4e31be3
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Package

on:
release:
workflow_dispatch:

jobs:
brew:
name: Update tap
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
path: code

- name: Checkout tap
uses: actions/checkout@v4
with:
repository: pls-rs/homebrew-pls
path: tap

- name: Update tap
working-directory: code
run: |
./pkg/brew/update_formula.sh "pkg/brew/pls.template" "$GITHUB_WORKSPACE/tap/Formula/pls.rb"
if ! git diff-index --quiet HEAD; then
git config user.name "Dhruv Bhanushali"
git config user.email "[email protected]"
git commit --all --message "Update formula"
git push origin main
fi
30 changes: 30 additions & 0 deletions pkg/brew/pls.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Pls < Formula
desc "Prettier and powerful ls for the pros"
homepage "https://pls.cli.rs/"
version "{{ VERSION }}"
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
29 changes: 29 additions & 0 deletions pkg/brew/update_formula.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

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

VERSION=$(echo "$RELEASE" | jq -r '.name' | cut -c 2-)
echo "Latest release is $VERSION."

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 /tmp/mac_asset
MAC_SHA=$(shasum -a 256 /tmp/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 /tmp/linux_asset
LINUX_SHA=$(shasum -a 256 /tmp/linux_asset | awk '{ print $1 }')
echo "SHA256 for Linux asset is $LINUX_SHA."

sed -e "s|{{ VERSION }}|$VERSION|g" \
-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" "$1" > "$2"

echo "Formula written!"

0 comments on commit 4e31be3

Please sign in to comment.