Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not use goreleaser #126

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 103 additions & 19 deletions .github/workflows/release.yaml
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*.*
98 changes: 51 additions & 47 deletions Makefile
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),main)
$(error current branch is not main)
endif
@gobump up -w .
git commit -am "bump up version to $(VERSION)"
git tag "v$(VERSION)"
git push origin main
git push origin "refs/tags/v$(VERSION)"
15 changes: 1 addition & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/google/go-cmp v0.5.8
github.com/jackc/pgx/v4 v4.18.1
github.com/k0kubun/pp v2.4.0+incompatible
github.com/mattn/go-sqlite3 v1.14.19
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/olekukonko/tablewriter v0.0.5
github.com/sourcegraph/jsonrpc2 v0.2.0
github.com/urfave/cli/v2 v2.26.0
Expand All @@ -19,26 +19,13 @@ require (

require (
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/godror/knownpb v0.1.1 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
Loading
Loading