Skip to content

Commit

Permalink
introduce goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 committed Oct 25, 2023
1 parent f8b0fd4 commit 3f37b3e
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 75 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,27 @@ jobs:
with:
go-version: ${{ matrix.go }}

- name: Test
- name: Test v1
run: make test
env:
GO111MODULE: "on"

- name: Test v2
run: make test
working-directory: v2

goreleaser-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Check GoReleaser configure v1
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: check
workdir: v2
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/artifacts/
/release/
/go.work

dist/
33 changes: 33 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines bellow are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- format: tar.gz
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

changelog:
use: github-native
sort: asc
72 changes: 0 additions & 72 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,80 +1,8 @@
GOVERSION=$(shell go version)
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
VERSION=$(patsubst "%",%,$(lastword $(shell grep 'const Version' internal/config/version.go)))
ARTIFACTS_DIR=$(CURDIR)/artifacts/$(VERSION)
RELEASE_DIR=$(CURDIR)/release/$(VERSION)
SRC_FILES=$(shell find . -type f -name '*.go')
GITHUB_USERNAME=shogo82148

help: ## Show this text.
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

all: build-windows-amd64 build-linux-amd64 build-darwin-amd64 ## Build binaries.

.PHONY: all test clean help

test: ## Run test.
go test -v -race ./...
go vet ./...

clean: ## Remove built files.


##### build settings

.PHONY: build build-windows-amd64 build-linux-amd64 build-darwin-amd64

$(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH):
@mkdir -p $@

$(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH)/rdsmysql$(SUFFIX): $(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH) $(SRC_FILES)
@echo " * Building binary for $(GOOS)/$(GOARCH)..."
@CGO_ENABLED=0 go build -o $@ cmd/rdsmysql/*.go

$(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH)/rdsmysqldump$(SUFFIX): $(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH) $(SRC_FILES)
@echo " * Building binary for $(GOOS)/$(GOARCH)..."
@CGO_ENABLED=0 go build -o $@ cmd/rdsmysqldump/*.go

build: $(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH)/rdsmysql$(SUFFIX) $(ARTIFACTS_DIR)/rdsmysql_$(GOOS)_$(GOARCH)/rdsmysqldump$(SUFFIX)

build-windows-amd64:
@$(MAKE) build GOOS=windows GOARCH=amd64 SUFFIX=.exe

build-linux-amd64:
@$(MAKE) build GOOS=linux GOARCH=amd64

build-darwin-amd64:
@$(MAKE) build GOOS=darwin GOARCH=amd64


##### release settings

.PHONY: release-windows-amd64 release-linux-amd64 release-darwin-amd64
.PHONY: release-targz release-zip release-files release-upload

$(RELEASE_DIR)/rdsmysql_$(GOOS)_$(GOARCH):
@mkdir -p $@

release-windows-amd64:
@$(MAKE) release-zip GOOS=windows GOARCH=amd64 SUFFIX=.exe

release-linux-amd64:
@$(MAKE) release-targz GOOS=linux GOARCH=amd64

release-darwin-amd64:
@$(MAKE) release-targz GOOS=darwin GOARCH=amd64

release-targz: build $(RELEASE_DIR)/rdsmysql_$(GOOS)_$(GOARCH)
@echo " * Creating tar.gz for $(GOOS)/$(GOARCH)"
tar -czf $(RELEASE_DIR)/rdsmysql_$(GOOS)_$(GOARCH).tar.gz -C $(ARTIFACTS_DIR) rdsmysql_$(GOOS)_$(GOARCH)

release-zip: build $(RELEASE_DIR)/rdsmysql_$(GOOS)_$(GOARCH)
@echo " * Creating zip for $(GOOS)/$(GOARCH)"
cd $(ARTIFACTS_DIR) && zip -9 $(RELEASE_DIR)/rdsmysql_$(GOOS)_$(GOARCH).zip rdsmysql_$(GOOS)_$(GOARCH)/*

release-files: release-windows-amd64 release-linux-amd64 release-darwin-amd64

release-upload: release-files
ghr -u $(GITHUB_USERNAME) --draft --replace v$(VERSION) $(RELEASE_DIR)
2 changes: 2 additions & 0 deletions v2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

dist/
33 changes: 33 additions & 0 deletions v2/.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines bellow are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- format: tar.gz
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

changelog:
use: github-native
sort: asc
8 changes: 8 additions & 0 deletions v2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
help: ## Show this text.
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: all test clean help

test: ## Run test.
go test -v -race ./...

0 comments on commit 3f37b3e

Please sign in to comment.