Skip to content

Commit

Permalink
Update homebrew-tap automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
noborus committed Oct 16, 2023
1 parent e340061 commit f851e94
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 10 deletions.
44 changes: 44 additions & 0 deletions .github/trdsql.template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Trdsql < Formula
desc "Tools for executing SQL queries to CSV, LTSV, JSON and TBLN"
homepage "https://github.com/noborus/trdsql/"
version "{{ version }}"

on_macos do
if Hardware::CPU.arm?
url "{{ DARWIN_ARM64_URL }}"
sha256 "{{ DARWIN_ARM64_SHA256 }}"
def install
bin.install "trdsql"
end
end
if Hardware::CPU.intel?
url "{{ DARWIN_AMD64_URL }}"
sha256 "{{ DARWIN_AMD64_SHA256 }}"
def install
bin.install "trdsql"
end
end
end

on_linux do
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "{{ LINUX_ARM64_URL }}"
sha256 "{{ LINUX_ARM64_SHA256 }}"
def install
bin.install "trdsql"
end
end

if Hardware::CPU.intel?
url "{{ LINUX_AMD64_URL }}"
sha256 "{{ LINUX_AMD64_SHA256 }}"
def install
bin.install "trdsql"
end
end
end

test do
assert_equal "3\n", pipe_output("#{bin}/trdsql 'select count(*) from -'", "a\nb\nc\n")
end
end
43 changes: 43 additions & 0 deletions .github/update-homebrew-tap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

template_file=".github/trdsql.template.rb"

output_file=".github/trdsql.rb"

VERSION=$(git describe --tags 2>/dev/null)

get_url_and_sha256() {
local file_path="$1"
local file_name=$(basename "$file_path")
local url="https://github.com/noborus/trdsql/releases/download/$VERSION/$file_name"
local sha256=$(sha256sum "$file_path" | awk '{print $1}')
echo "$url $sha256"
}

darwin_arm64=$(get_url_and_sha256 "dist/trdsql_${VERSION}_darwin_arm64.zip")
darwin_arm64_url=$(echo "${darwin_arm64% *}" | sed 's/\//\\\//g')
darwin_arm64_sha256=${darwin_arm64#* }

darwin_amd64=$(get_url_and_sha256 "dist/trdsql_${VERSION}_darwin_amd64.zip")
darwin_amd64_url=$(echo "${darwin_amd64% *}" | sed 's/\//\\\//g')
darwin_amd64_sha256=${darwin_amd64#* }

linux_arm64=$(get_url_and_sha256 "dist/trdsql_${VERSION}_linux_arm64.zip")
linux_arm64_url=$(echo "${linux_arm64% *}" | sed 's/\//\\\//g')
linux_arm64_sha256=${linux_arm64#* }

linux_amd64=$(get_url_and_sha256 "dist/trdsql_${VERSION}_linux_amd64.zip")
linux_amd64_url=$(echo "${linux_amd64% *}" | sed 's/\//\\\//g')
linux_amd64_sha256=${linux_amd64#* }

ver=$(echo "$VERSION" | sed 's/^v//g')
sed -e "s/{{ version }}/$ver/g" \
-e "s/{{ DARWIN_ARM64_URL }}/$darwin_arm64_url/g" \
-e "s/{{ DARWIN_ARM64_SHA256 }}/$darwin_arm64_sha256/g" \
-e "s/{{ DARWIN_AMD64_URL }}/$darwin_amd64_url/g" \
-e "s/{{ DARWIN_AMD64_SHA256 }}/$darwin_amd64_sha256/g" \
-e "s/{{ LINUX_ARM64_URL }}/$linux_arm64_url/g" \
-e "s/{{ LINUX_ARM64_SHA256 }}/$linux_arm64_sha256/g" \
-e "s/{{ LINUX_AMD64_URL }}/$linux_amd64_url/g" \
-e "s/{{ LINUX_AMD64_SHA256 }}/$linux_amd64_sha256/g" \
"$template_file" > "$output_file"
34 changes: 25 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
name: Release upload
"on":
release:
types:
- published

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
if: success()
uses: actions/setup-go@v4
with:
go-version: "1.21"
- name: Set environment variables
shell: bash
run: |
echo "GOPATH=${{ runner.workspace }}" >> $GITHUB_ENV
echo "${{ runner.workspace }}/bin" >> $GITHUB_PATH
shell: bash
- name: Setup XGO
run: go install github.com/crazy-max/xgo@latest
- name: Run dist
run: make dist
- name: Upload Asset to Release with a wildcard
uses: AButler/[email protected]
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: dist/*.zip
repo-token: ${{ secrets.GITHUB_TOKEN }}
name: Release upload
"on":
release:
types:
- published
- name: update homebrew
run: |
bash .github/update-homebrew-tap.sh
- name: Pushes homebrew-tap
uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{ secrets.TAP_GITHUB_TOKEN }}
with:
source_file: '.github/trdsql.rb'
destination_repo: 'noborus/homebrew-tap'
destination_branch: 'master'
user_email: '[email protected]'
user_name: 'Noboru Saito'
commit_message: 'Brew formula update for trdsql'

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ifeq ($(strip $(VERSION)),)
else
LDFLAGS="-X github.com/noborus/trdsql.Version=$(VERSION)"
endif
GOVERSION="1.21.x"
GOVERSION ?= "1.21.x"
BUILDFLAG=-tags $(TAGS) -ldflags=$(LDFLAGS)
GOBUILD=$(GOCMD) build $(BUILDFLAG)
GOTEST=$(GOCMD) test -tags $(TAGS) ./...
Expand Down

0 comments on commit f851e94

Please sign in to comment.