Skip to content

Commit d638f9e

Browse files
authored
Merge pull request #245 from noborus/auto-update-homebrew
Update homebrew-tap automatically
2 parents e340061 + f851e94 commit d638f9e

File tree

4 files changed

+113
-10
lines changed

4 files changed

+113
-10
lines changed

.github/trdsql.template.rb

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
class Trdsql < Formula
2+
desc "Tools for executing SQL queries to CSV, LTSV, JSON and TBLN"
3+
homepage "https://github.com/noborus/trdsql/"
4+
version "{{ version }}"
5+
6+
on_macos do
7+
if Hardware::CPU.arm?
8+
url "{{ DARWIN_ARM64_URL }}"
9+
sha256 "{{ DARWIN_ARM64_SHA256 }}"
10+
def install
11+
bin.install "trdsql"
12+
end
13+
end
14+
if Hardware::CPU.intel?
15+
url "{{ DARWIN_AMD64_URL }}"
16+
sha256 "{{ DARWIN_AMD64_SHA256 }}"
17+
def install
18+
bin.install "trdsql"
19+
end
20+
end
21+
end
22+
23+
on_linux do
24+
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
25+
url "{{ LINUX_ARM64_URL }}"
26+
sha256 "{{ LINUX_ARM64_SHA256 }}"
27+
def install
28+
bin.install "trdsql"
29+
end
30+
end
31+
32+
if Hardware::CPU.intel?
33+
url "{{ LINUX_AMD64_URL }}"
34+
sha256 "{{ LINUX_AMD64_SHA256 }}"
35+
def install
36+
bin.install "trdsql"
37+
end
38+
end
39+
end
40+
41+
test do
42+
assert_equal "3\n", pipe_output("#{bin}/trdsql 'select count(*) from -'", "a\nb\nc\n")
43+
end
44+
end

.github/update-homebrew-tap.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
template_file=".github/trdsql.template.rb"
4+
5+
output_file=".github/trdsql.rb"
6+
7+
VERSION=$(git describe --tags 2>/dev/null)
8+
9+
get_url_and_sha256() {
10+
local file_path="$1"
11+
local file_name=$(basename "$file_path")
12+
local url="https://github.com/noborus/trdsql/releases/download/$VERSION/$file_name"
13+
local sha256=$(sha256sum "$file_path" | awk '{print $1}')
14+
echo "$url $sha256"
15+
}
16+
17+
darwin_arm64=$(get_url_and_sha256 "dist/trdsql_${VERSION}_darwin_arm64.zip")
18+
darwin_arm64_url=$(echo "${darwin_arm64% *}" | sed 's/\//\\\//g')
19+
darwin_arm64_sha256=${darwin_arm64#* }
20+
21+
darwin_amd64=$(get_url_and_sha256 "dist/trdsql_${VERSION}_darwin_amd64.zip")
22+
darwin_amd64_url=$(echo "${darwin_amd64% *}" | sed 's/\//\\\//g')
23+
darwin_amd64_sha256=${darwin_amd64#* }
24+
25+
linux_arm64=$(get_url_and_sha256 "dist/trdsql_${VERSION}_linux_arm64.zip")
26+
linux_arm64_url=$(echo "${linux_arm64% *}" | sed 's/\//\\\//g')
27+
linux_arm64_sha256=${linux_arm64#* }
28+
29+
linux_amd64=$(get_url_and_sha256 "dist/trdsql_${VERSION}_linux_amd64.zip")
30+
linux_amd64_url=$(echo "${linux_amd64% *}" | sed 's/\//\\\//g')
31+
linux_amd64_sha256=${linux_amd64#* }
32+
33+
ver=$(echo "$VERSION" | sed 's/^v//g')
34+
sed -e "s/{{ version }}/$ver/g" \
35+
-e "s/{{ DARWIN_ARM64_URL }}/$darwin_arm64_url/g" \
36+
-e "s/{{ DARWIN_ARM64_SHA256 }}/$darwin_arm64_sha256/g" \
37+
-e "s/{{ DARWIN_AMD64_URL }}/$darwin_amd64_url/g" \
38+
-e "s/{{ DARWIN_AMD64_SHA256 }}/$darwin_amd64_sha256/g" \
39+
-e "s/{{ LINUX_ARM64_URL }}/$linux_arm64_url/g" \
40+
-e "s/{{ LINUX_ARM64_SHA256 }}/$linux_arm64_sha256/g" \
41+
-e "s/{{ LINUX_AMD64_URL }}/$linux_amd64_url/g" \
42+
-e "s/{{ LINUX_AMD64_SHA256 }}/$linux_amd64_sha256/g" \
43+
"$template_file" > "$output_file"

.github/workflows/release.yml

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
1+
name: Release upload
2+
"on":
3+
release:
4+
types:
5+
- published
6+
17
jobs:
28
build:
39
runs-on: ubuntu-latest
410
steps:
511
- name: Check out code into the Go module directory
6-
uses: actions/checkout@v3
12+
uses: actions/checkout@v4
713
- name: Install Go
814
if: success()
915
uses: actions/setup-go@v4
1016
with:
1117
go-version: "1.21"
1218
- name: Set environment variables
19+
shell: bash
1320
run: |
1421
echo "GOPATH=${{ runner.workspace }}" >> $GITHUB_ENV
1522
echo "${{ runner.workspace }}/bin" >> $GITHUB_PATH
16-
shell: bash
1723
- name: Setup XGO
1824
run: go install github.com/crazy-max/xgo@latest
1925
- name: Run dist
2026
run: make dist
2127
- name: Upload Asset to Release with a wildcard
22-
uses: AButler/[email protected]
28+
uses: softprops/action-gh-release@v1
29+
if: startsWith(github.ref, 'refs/tags/')
2330
with:
2431
files: dist/*.zip
25-
repo-token: ${{ secrets.GITHUB_TOKEN }}
26-
name: Release upload
27-
"on":
28-
release:
29-
types:
30-
- published
32+
- name: update homebrew
33+
run: |
34+
bash .github/update-homebrew-tap.sh
35+
- name: Pushes homebrew-tap
36+
uses: dmnemec/copy_file_to_another_repo_action@main
37+
env:
38+
API_TOKEN_GITHUB: ${{ secrets.TAP_GITHUB_TOKEN }}
39+
with:
40+
source_file: '.github/trdsql.rb'
41+
destination_repo: 'noborus/homebrew-tap'
42+
destination_branch: 'master'
43+
user_email: '[email protected]'
44+
user_name: 'Noboru Saito'
45+
commit_message: 'Brew formula update for trdsql'
46+

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ifeq ($(strip $(VERSION)),)
99
else
1010
LDFLAGS="-X github.com/noborus/trdsql.Version=$(VERSION)"
1111
endif
12-
GOVERSION="1.21.x"
12+
GOVERSION ?= "1.21.x"
1313
BUILDFLAG=-tags $(TAGS) -ldflags=$(LDFLAGS)
1414
GOBUILD=$(GOCMD) build $(BUILDFLAG)
1515
GOTEST=$(GOCMD) test -tags $(TAGS) ./...

0 commit comments

Comments
 (0)