-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into line-break
- Loading branch information
Showing
5 changed files
with
168 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,110 @@ | ||
name: goreleaser | ||
|
||
name: Release | ||
on: | ||
pull_request: | ||
push: | ||
tags: | ||
- 'v*' | ||
env: | ||
GO_VERSION: stable | ||
|
||
jobs: | ||
goreleaser: | ||
build_for_linux: | ||
name: Build for Linux | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install build dependencies | ||
run: | | ||
sudo apt-get -qq update | ||
sudo apt-get install -y --no-install-recommends \ | ||
build-essential | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Build amd64 | ||
env: | ||
CGO_ENABLED: 1 | ||
GOOS: linux | ||
GOARCH: amd64 | ||
run: make release | ||
- name: Archive artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: dist-linux | ||
path: sqls-linux-*.zip | ||
|
||
build_for_macos: | ||
name: Build for MacOS | ||
runs-on: macos-latest | ||
steps: | ||
- name: Install build dependencies | ||
run: brew install coreutils | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Build amd64 | ||
env: | ||
CGO_ENABLED: 1 | ||
GOOS: darwin | ||
GOARCH: amd64 | ||
run: make release | ||
- name: Archive artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: dist-darwin | ||
path: sqls-darwin-*.zip | ||
|
||
build_for_windows: | ||
name: Build for Windows | ||
runs-on: windows-latest | ||
steps: | ||
- name: Install build dependencies | ||
run: choco install zip | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Build amd64 | ||
shell: bash | ||
env: | ||
CGO_ENABLED: 1 | ||
GOOS: windows | ||
GOARCH: amd64 | ||
run: make release | ||
- name: Archive artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: dist-windows | ||
path: sqls-windows-*.zip | ||
|
||
release: | ||
name: Draft Release | ||
needs: | ||
- build_for_linux | ||
- build_for_macos | ||
- build_for_windows | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v3 | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
go-version: 1.21 | ||
- name: Run GoReleaser(xcgo) Snapshot | ||
run: | | ||
make snapshot | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Run GoReleaser(xcgo) Publish | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
run: | | ||
make publish | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
name: sqls ${{ github.ref_name }} | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
draft: true | ||
generate_release_notes: true | ||
files: dist-*/sqls*.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,55 @@ | ||
NAME := sqls | ||
VERSION := $(shell git describe --tags `git rev-list --tags --max-count=1`) | ||
REVISION := $(shell git rev-parse --short HEAD) | ||
GOVERSION := $(go version) | ||
GITHUB_TOKEN := $(GITHUB_TOKEN) | ||
|
||
SRCS := $(shell find . -type f -name '*.go') | ||
LDFLAGS := -ldflags="-s -w -X \"main.version=$(VERSION)\" -X \"main.revision=$(REVISION)\"" | ||
DIST_DIRS := find * -type d -exec | ||
|
||
.PHONY: test | ||
test: | ||
go test ./... | ||
BIN := sqls | ||
ifeq ($(OS),Windows_NT) | ||
BIN := $(BIN).exe | ||
endif | ||
VERSION := $$(make -s show-version) | ||
CURRENT_REVISION := $(shell git rev-parse --short HEAD) | ||
BUILD_LDFLAGS := "-s -w -X main.revision=$(CURRENT_REVISION)" | ||
GOOS := $(shell go env GOOS) | ||
GOBIN ?= $(shell go env GOPATH)/bin | ||
export GO111MODULE=on | ||
|
||
.PHONY: all | ||
all: clean build | ||
|
||
.PHONY: build | ||
build: $(SRCS) | ||
go build $(LDFLAGS) ./... | ||
build: | ||
go build -ldflags=$(BUILD_LDFLAGS) -o $(BIN) . | ||
|
||
.PHONY: release | ||
release: | ||
go build -ldflags=$(BUILD_LDFLAGS) -o $(BIN) . | ||
zip -r sqls-$(GOOS)-$(VERSION).zip $(BIN) | ||
|
||
.PHONY: install | ||
install: $(SRCS) | ||
go install $(LDFLAGS) ./... | ||
|
||
.PHONY: lint | ||
lint: $(SRCS) | ||
golangci-lint run | ||
|
||
.PHONY: coverage | ||
coverage: | ||
go test -v -coverprofile=coverage.out ./... | ||
go tool cover -html=coverage.out | ||
|
||
.PHONY: stringer | ||
stringer: | ||
stringer -type Kind ./token/kind.go | ||
|
||
.PHONY: snapshot | ||
snapshot: $(SRCS) | ||
docker run --rm --privileged \ | ||
-v ${PWD}:/go/src/github.com/sqls-server/sqls \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-w /go/src/github.com/sqls-server/sqls \ | ||
mailchain/goreleaser-xcgo --snapshot --rm-dist | ||
|
||
.PHONY: publish | ||
publish: $(SRCS) | ||
docker run --rm --privileged \ | ||
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \ | ||
-v ${PWD}:/go/src/github.com/sqls-server/sqls \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-w /go/src/github.com/sqls-server/sqls \ | ||
mailchain/goreleaser-xcgo --rm-dist | ||
install: | ||
go install -ldflags=$(BUILD_LDFLAGS) . | ||
|
||
.PHONY: show-version | ||
show-version: $(GOBIN)/gobump | ||
gobump show -r . | ||
|
||
$(GOBIN)/gobump: | ||
go install github.com/x-motemen/gobump/cmd/gobump@latest | ||
|
||
.PHONY: test | ||
test: build | ||
go test -v ./... | ||
|
||
.PHONY: clean | ||
clean: | ||
go clean | ||
|
||
.PHONY: bump | ||
bump: $(GOBIN)/gobump | ||
ifneq ($(shell git status --porcelain),) | ||
$(error git workspace is dirty) | ||
endif | ||
ifneq ($(shell git rev-parse --abbrev-ref HEAD),master) | ||
$(error current branch is not master) | ||
endif | ||
@gobump up -w . | ||
git commit -am "bump up version to $(VERSION)" | ||
git tag "v$(VERSION)" | ||
git push origin master | ||
git push origin "refs/tags/v$(VERSION)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters