Skip to content

Commit

Permalink
Import code
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkruss committed May 24, 2021
0 parents commit a87b5dd
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
81 changes: 81 additions & 0 deletions .github/workflows/bump-stable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Bump stable formula

on:
repository_dispatch:
types:
- bump-relay-stable

jobs:

bump-relay-stable:

name: Bump stable Relay formula
runs-on: macos-11.0

if: github.event.action == 'bump-relay-stable'

steps:

- name: Checkout code
uses: actions/checkout@v2

- name: Install GNU sed
run: brew install gnu-sed

- name: Download release assets
env:
RELEASE: ${{ toJson(github.event.client_payload.release) }}
run: |
while IFS= read -r asset; do
NAME=$(echo $asset | jq -r '.name')
URL=$(echo $asset | jq -r '.url')
echo "Downloading $NAME from $URL"
curl -sS --fail -o $NAME --location $URL \
--header "Accept: application/octet-stream" \
--header "Authorization: Bearer ${{ secrets.TOKEN_GH }}"
done < <(echo $RELEASE | jq -c '.assets[] | select(.name | contains("darwin"))')
- name: Update formula
env:
RELEASE: ${{ toJson(github.event.client_payload.release) }}
run: |
TAG_NAME=$(echo $RELEASE | jq -r '.tag_name')
echo "Updating stable tag to $TAG_NAME"
gsed -i "s/, tag: \"v.*\"/, tag: \"$TAG_NAME\"/" Formula/relay.rb
for f in *.tar.gz; do
HASH=$(shasum --algorithm 256 $f | head -c 64)
MARKER=$(echo $f | cut -d - -f 3- | gsed 's/.tar.gz//')
URL=$(echo $RELEASE | jq -r ".assets[] | select(.name==\"$f\") | .browser_download_url")
echo "Setting URL for stable $MARKER marker to $URL"
gsed -i "/.*# stable: $MARKER/!b;n;c\ \ \ \ \ \ \ \ \ \ url \"$URL\"" Formula/relay.rb
echo "Setting checksum for stable $MARKER marker to $HASH"
gsed -i "/.*# stable: $MARKER/!b;n;n;c\ \ \ \ \ \ \ \ \ \ sha256 \"$HASH\"" Formula/relay.rb
done
- name: Check formula style
run: brew style Formula/relay.rb

- name: Commit changes
env:
RELEASE: ${{ toJson(github.event.client_payload.release) }}
run: |
TAG_NAME=$(echo $RELEASE | jq -r '.tag_name')
BRANCH=pr/stable-$TAG_NAME
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
echo "Pushing changes to $BRANCH branch"
git checkout -b $BRANCH
git add Formula/relay.rb
git commit -m "Bump stable to $TAG_NAME"
git push -u origin $BRANCH
- name: Open pull request
uses: octokit/request-action@v2.x
with:
route: POST /repos/cachewerk/homebrew-relay/pulls
base: main
head: pr/stable-${{ github.event.client_payload.release.tag_name }}
title: Relay ${{ github.event.client_payload.release.tag_name }}
body: See https://github.com/cachewerk/relay/releases/tag/${{ github.event.client_payload.release.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GH }}
125 changes: 125 additions & 0 deletions Formula/relay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
require "securerandom"

class Relay < Formula
desc "Next-generation caching layer for PHP"
homepage "https://relaycache.com"

php_ver = Utils.safe_popen_read("#{HOMEBREW_PREFIX}/bin/php-config", "--version").chomp.slice(0, 3)

stable do
url "https://github.com/cachewerk/relay.git", tag: "v0.1.0"

resource "ext-relay" do
if Hardware::CPU.arm?
case php_ver
when "8.0" # stable: php8.0-darwin-arm64
url "https://cachewerk.s3.amazonaws.com/relay/v0.1.0/relay-v0.1.0-php8.0-darwin-arm64.tar.gz"
sha256 "..."
when "7.4" # stable: php7.4-darwin-arm64
url "https://cachewerk.s3.amazonaws.com/relay/v0.1.0/relay-v0.1.0-php7.4-darwin-arm64.tar.gz"
sha256 "..."
end
else
case php_ver
when "8.0" # stable: php8.0-darwin-x86-64
url "https://cachewerk.s3.amazonaws.com/relay/v0.1.0/relay-v0.1.0-php8.0-darwin-x86-64.tar.gz"
sha256 "..."
when "7.4" # stable: php7.4-darwin-x86-64
url "https://cachewerk.s3.amazonaws.com/relay/v0.1.0/relay-v0.1.0-php7.4-darwin-x86-64.tar.gz"
sha256 "..."
end
end
end
end

head do
url "https://github.com/cachewerk/relay.git", branch: "main"

resource "ext-relay" do
if Hardware::CPU.arm?
case php_ver
when "8.0" # head: php8.0-darwin-arm64
url "https://cachewerk.s3.amazonaws.com/relay/relay-dev-php8.0-darwin-arm64.tar.gz"
when "7.4" # head: php7.4-darwin-arm64
url "https://cachewerk.s3.amazonaws.com/relay/relay-dev-php7.4-darwin-arm64.tar.gz"
end
else
case php_ver
when "8.0" # head: php8.0-darwin-x86-64
url "https://cachewerk.s3.amazonaws.com/relay/relay-dev-php8.0-darwin-x86-64.tar.gz"
when "7.4" # head: php7.4-darwin-x86-64
url "https://cachewerk.s3.amazonaws.com/relay/relay-dev-php7.4-darwin-x86-64.tar.gz"
end
end
end
end

bottle :unneeded

# depends_on "concurrencykit" # > v0.7.0
# depends_on "hiredis" # > v1.0.0
# depends_on "jemalloc"
# depends_on "liblzf"
# depends_on "lz4"
# depends_on "zstd"
depends_on "php"

def conf_dir
Pathname(Utils.safe_popen_read("#{HOMEBREW_PREFIX}/bin/php-config", "--ini-dir").chomp)
end

def install
extensions = Utils.safe_popen_read("#{HOMEBREW_PREFIX}/bin/php", "-m")

["json", "igbinary", "msgpack"].each do |name|
unless /^#{name}/.match?(extensions)
raise "Relay requires the `#{name}` extension. Install it using `\033[32mpecl install #{name}\033[0m`."
end
end

resource("ext-relay").stage do
mv "relay-static-notls.so", "relay.so"

# re-link OpenSSL
["libssl", "libcrypto"].each do |link|
system "install_name_tool",
"-change",
`otool -L relay.so | grep #{link} | awk '{print $1}'`.chomp,
`otool -L #{HOMEBREW_PREFIX}/bin/php | grep #{link} | awk '{print $1}'`.chomp,
"relay.so"
end

ENV["LC_ALL"] = "C"
system "/usr/bin/sed",
"-i ''",
"s/31415926-5358-9793-2384-626433832795/#{SecureRandom.uuid}/",
"relay.so"

lib.install "relay.so"

# set absolute path to extension
inreplace "relay.ini", "extension = relay.so", "extension = #{lib}/relay.so"

# install ini file to `etc/` (won't overwrite)
(etc/"relay").install "relay.ini"

# upsert absolute path to extension if `relay.ini` already existed
inreplace etc/"relay/relay.ini", /extension =.+$/, "extension = #{lib}/relay.so"

# create ini soft link if necessary
ln_s etc/"relay/relay.ini", conf_dir/"ext-relay.ini" unless (conf_dir/"ext-relay.ini").exist?
end
end

def caveats
<<~EOS
The Relay extension for PHP was installed at:
#{lib}/relay.so
The configuration file was symlinked to:
#{conf_dir}/ext-relay.ini
Run `\033[32mphp --ri relay\033[0m` to ensure it’s working.
EOS
end
end
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Relay Homebrew repository

Install the Relay extension for PHP using Homebrew:

```bash
brew tap cachewerk/tap
brew install relay

# or in a single command
brew install cachewerk/tap/relay
```

## Links

- [Documentation](https://relaycache.com/docs)
- [Twitter](https://twitter.com/RelayCache)
- [Discussions](https://github.com/cachewerk/relay/discussions)

## Development

Check the formula syntax before committing.

```bash
brew style cachewerk/tap
```

0 comments on commit a87b5dd

Please sign in to comment.