From 865eba87f54e5443c57d995f24e977a8f87529be Mon Sep 17 00:00:00 2001 From: mashiike Date: Wed, 29 Oct 2025 16:35:12 +0900 Subject: [PATCH 1/2] Modernize release workflow with tagpr and GoReleaser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace legacy Makefile-based workflow with tagpr + GoReleaser for automated releases. Add Taskfile for development tasks. - Add .goreleaser.yaml, Taskfile.yaml, .tagpr - Add .github/workflows/tagpr.yaml - Remove Makefile and .github/workflows/release.yaml - Update test workflow to use go test directly - Refactor version management to package-level variable 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .github/workflows/release.yaml | 34 -------- .github/workflows/tagpr.yaml | 47 +++++++++++ .github/workflows/test.yaml | 24 +++--- .gitignore | 6 ++ .goreleaser.yaml | 36 ++++++++ .tagpr | 5 ++ Makefile | 24 ------ Taskfile.yaml | 145 +++++++++++++++++++++++++++++++++ cmd/bqin/version.go | 3 +- version.go | 3 + 10 files changed, 255 insertions(+), 72 deletions(-) delete mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/tagpr.yaml create mode 100644 .goreleaser.yaml create mode 100644 .tagpr delete mode 100644 Makefile create mode 100644 Taskfile.yaml create mode 100644 version.go diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 2e65c29..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,34 +0,0 @@ -name: Release -on: - push: - branches: - - "!**/*" - tags: - - "v*" - -jobs: - release: - name: Release - runs-on: ubuntu-latest - steps: - - name: Set up Go - uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v1 - with: - go-version: 1.14 - - - name: Check out code into the Go module directory - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v1 - - - name: setup tools - run: | - go get -v github.com/mitchellh/gox@v1.0.1 - curl -sL https://github.com/tcnksm/ghr/releases/download/v0.13.0/ghr_v0.13.0_linux_amd64.tar.gz | tar zxvf - && install ghr_v0.13.0_linux_amd64/ghr ~/go/bin/ - - name: packages - run: PATH=~/go/bin:$PATH make packages - env: - CGO_ENABLED: 0 - - - name: release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: PATH=~/go/bin:$PATH make release diff --git a/.github/workflows/tagpr.yaml b/.github/workflows/tagpr.yaml new file mode 100644 index 0000000..9a64481 --- /dev/null +++ b/.github/workflows/tagpr.yaml @@ -0,0 +1,47 @@ +# .github/workflows/tagpr.yaml +name: tagpr and release +on: + push: + branches: ["master"] + workflow_dispatch: + inputs: + tag: + description: "release tag" + required: false + type: string + +permissions: + pull-requests: write + packages: write + contents: write + actions: write + +jobs: + tagpr: + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4 + with: + persist-credentials: true + ref: ${{ inputs.tag || github.ref }} + + - id: tagpr + uses: Songmu/tagpr@9c294c8b7b1815a5f3b7c61d6ee6aa50ac25b030 # v1 + if: ${{ github.event_name != 'workflow_dispatch' }} # skip on workflow_dispatch + + - name: Set up Go + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5 + with: + go-version-file: go.mod + cache: true + + - name: Run Go Releaser + uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6 + if: ${{ steps.tagpr.outputs.tag != '' || github.event_name == 'workflow_dispatch' }} + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8130a24..a083e6d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -3,7 +3,7 @@ on: push: paths: - "**.go" - - "Makefile" + - "Taskfile.yaml" - "go.mod" - "go.sum" - ".github/workflows/test.yaml" @@ -11,25 +11,25 @@ on: - main - master - feature/** + jobs: test: strategy: matrix: go: - - 1.13 - - 1.14 - name: Build + - "1.13" + - "1.14" + name: Test (Go ${{ matrix.go }}) runs-on: ubuntu-latest steps: + - name: Check out code + uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4 + - name: Set up Go - uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v1 + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5 with: go-version: ${{ matrix.go }} - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v1 + cache: true - - name: Build & Test - run: | - make test + - name: Test + run: go test -v -race ./... diff --git a/.gitignore b/.gitignore index 93ffb1e..07607e7 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,11 @@ go.sum # related release files pkg/ +# GoReleaser output +dist/ + vendor/ *~ + +CLAUDE.md +AGENTS.md diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..2e492ae --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,36 @@ +# GoReleaser configuration for bqin +# https://goreleaser.com/ + +version: 2 + +builds: + - id: bqin + main: ./cmd/bqin + binary: bqin + env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + - windows + goarch: + - amd64 + - arm64 + ignore: + - goos: windows + goarch: arm64 + ldflags: + - -s -w + - -X main.buildDate={{.Date}} + +archives: + - name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}" + files: + - LICENSE + - README.md + +checksum: + name_template: "checksums.txt" + +snapshot: + version_template: "{{ incpatch .Version }}-next" diff --git a/.tagpr b/.tagpr new file mode 100644 index 0000000..06005b2 --- /dev/null +++ b/.tagpr @@ -0,0 +1,5 @@ +[tagpr] + vPrefix = true + releaseBranch = master + versionFile = version.go + release = draft diff --git a/Makefile b/Makefile deleted file mode 100644 index 558078b..0000000 --- a/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -GIT_VER := $(shell git describe --tags) -DATE := $(shell date +%Y-%m-%dT%H:%M:%S%z) -export GO111MODULE := on - -.PHONY: build test install clean - -cmd/bqin/bqin: *.go cmd/bqin - cd cmd/bqin && go build -ldflags "-s -w -X main.version=${GIT_VER} -X main.buildDate=${DATE}" - -install: cmd/bqin/bqin - go install cmd/bqin - -test: - go test -v ./... - -packages: *.go cmd/bqin - cd cmd/bqin && gox -os="linux darwin" -arch="amd64" -output "../../pkg/{{.Dir}}-${GIT_VER}-{{.OS}}-{{.Arch}}" -ldflags "-s -w -X main.version=${GIT_VER} -X main.buildDate=${DATE}" - cd pkg && find . -name "*${GIT_VER}*" -type f -exec zip {}.zip {} \; - -release: - ghr -u kayac -r bqin -n "$(GIT_VER)" $(GIT_VER) pkg/ - -clean: - rm -f cmd/bqin/bqin pkg/* diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000..eb5db88 --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,145 @@ +# Taskfile for bqin development +# https://taskfile.dev/ + +version: "3" + +vars: + VERSION: + sh: git describe --tags --always --dirty 2>/dev/null || echo "dev" + BUILD_DATE: + sh: date +%Y-%m-%dT%H:%M:%S%z + BINARY: bqin + MAIN_PATH: ./cmd/bqin + LDFLAGS: -s -w -X main.version={{.VERSION}} -X main.buildDate={{.BUILD_DATE}} + +tasks: + default: + desc: Show available tasks + cmds: + - task -l + silent: true + + deps: + desc: Download and tidy dependencies + cmds: + - go mod download + - go mod tidy + + test: + desc: Run tests + cmds: + - go test -v -race -coverprofile=coverage.out ./... + sources: + - "**/*.go" + - go.mod + - go.sum + + test:short: + desc: Run tests without race detector (faster) + cmds: + - go test -v ./... + + coverage: + desc: Show test coverage in browser + deps: [test] + cmds: + - go tool cover -html=coverage.out + + lint: + desc: Run linters (requires staticcheck) + cmds: + - go vet ./... + - staticcheck ./... + preconditions: + - sh: command -v staticcheck + msg: "staticcheck not found. Install with: go install honnef.co/go/tools/cmd/staticcheck@latest" + + fmt: + desc: Format code + cmds: + - go fmt ./... + + build: + desc: Build binary for current platform + cmds: + - go build -ldflags "{{.LDFLAGS}}" -o {{.BINARY}} {{.MAIN_PATH}} + sources: + - "**/*.go" + - go.mod + - go.sum + generates: + - "{{.BINARY}}" + + install: + desc: Install binary to $GOPATH/bin + cmds: + - go install -ldflags "{{.LDFLAGS}}" {{.MAIN_PATH}} + + clean: + desc: Clean build artifacts + cmds: + - rm -f {{.BINARY}} + - rm -f coverage.out + - rm -rf dist/ + - rm -rf pkg/ + + run: + desc: Build and run (usage: task run -- [args]) + deps: [build] + cmds: + - ./{{.BINARY}} {{.CLI_ARGS}} + + goreleaser:check: + desc: Check goreleaser config + cmds: + - goreleaser check + preconditions: + - sh: command -v goreleaser + msg: "goreleaser not found. Install from: https://goreleaser.com/install/" + + goreleaser:build: + desc: Build with goreleaser (snapshot) + cmds: + - goreleaser build --snapshot --clean + preconditions: + - sh: command -v goreleaser + msg: "goreleaser not found. Install from: https://goreleaser.com/install/" + + goreleaser:release: + desc: Create a local release with goreleaser (for testing) + cmds: + - goreleaser release --snapshot --clean + preconditions: + - sh: command -v goreleaser + msg: "goreleaser not found. Install from: https://goreleaser.com/install/" + + ci: + desc: Run all CI checks (format, lint, test) + cmds: + - task: fmt + - task: lint + - task: test + + help: + desc: Show detailed help + cmds: + - | + echo "bqin development tasks" + echo "" + echo "Common tasks:" + echo " task test - Run all tests" + echo " task build - Build binary" + echo " task install - Install to GOPATH" + echo " task lint - Run linters" + echo " task ci - Run all CI checks" + echo "" + echo "Development:" + echo " task run -- [args] - Build and run with arguments" + echo " task coverage - View test coverage" + echo "" + echo "Release:" + echo " task goreleaser:check - Validate goreleaser config" + echo " task goreleaser:build - Test build with goreleaser" + echo "" + echo "For full list: task -l" + silent: true diff --git a/cmd/bqin/version.go b/cmd/bqin/version.go index c45a4dd..5d5ed50 100644 --- a/cmd/bqin/version.go +++ b/cmd/bqin/version.go @@ -9,7 +9,6 @@ import ( ) var ( - version string buildDate string ) @@ -30,7 +29,7 @@ func (_ *versionCmd) SetFlags(_ *flag.FlagSet) {} func (_ *versionCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { fmt.Println("bqin is a BigQuery data importer with AWS S3 and SQS messaging.") - fmt.Println("version:", version) + fmt.Println("version:", bqin.Version) fmt.Println("build:", buildDate) return subcommands.ExitSuccess } diff --git a/version.go b/version.go new file mode 100644 index 0000000..30417c7 --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package bqin + +var Version = "v0.3.1" From e16f340a5b586c11b851a9d8184289f64b91864d Mon Sep 17 00:00:00 2001 From: mashiike Date: Wed, 29 Oct 2025 16:36:18 +0900 Subject: [PATCH 2/2] fix: version --- cmd/bqin/common.go | 3 ++- cmd/bqin/version.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/bqin/common.go b/cmd/bqin/common.go index 32e3184..6210728 100644 --- a/cmd/bqin/common.go +++ b/cmd/bqin/common.go @@ -9,6 +9,7 @@ import ( "syscall" "github.com/google/subcommands" + "github.com/kayac/bqin" "github.com/kayac/bqin/internal/logger" ) @@ -36,7 +37,7 @@ func (w *cmdWrap) Execute(ctx context.Context, f *flag.FlagSet, args ...interfac minLevel = logger.DebugLevel } logger.Setup(os.Stderr, minLevel) - logger.Infof("bqin version: %s", version) + logger.Infof("bqin version: %s", bqin.Version) return w.Command.Execute(ctx, f, args...) } diff --git a/cmd/bqin/version.go b/cmd/bqin/version.go index 5d5ed50..a7a3f7d 100644 --- a/cmd/bqin/version.go +++ b/cmd/bqin/version.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/google/subcommands" + "github.com/kayac/bqin" ) var (