From f851e9403d5c8f5124238e0a7164b70e4023aa47 Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Tue, 17 Oct 2023 00:05:25 +0900 Subject: [PATCH] Update homebrew-tap automatically --- .github/trdsql.template.rb | 44 ++++++++++++++++++++++++++++++++++ .github/update-homebrew-tap.sh | 43 +++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 34 +++++++++++++++++++------- Makefile | 2 +- 4 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 .github/trdsql.template.rb create mode 100644 .github/update-homebrew-tap.sh diff --git a/.github/trdsql.template.rb b/.github/trdsql.template.rb new file mode 100644 index 0000000..8134f21 --- /dev/null +++ b/.github/trdsql.template.rb @@ -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 diff --git a/.github/update-homebrew-tap.sh b/.github/update-homebrew-tap.sh new file mode 100644 index 0000000..2cfc344 --- /dev/null +++ b/.github/update-homebrew-tap.sh @@ -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" \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d2b1e4..d76a9c0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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/upload-release-assets@v2.0 + 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: 'noborusai@gmail.com' + user_name: 'Noboru Saito' + commit_message: 'Brew formula update for trdsql' + \ No newline at end of file diff --git a/Makefile b/Makefile index cf96bf2..939e81f 100644 --- a/Makefile +++ b/Makefile @@ -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) ./...