Skip to content

Commit

Permalink
*: better workflow (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Sep 30, 2022
1 parent 876ba28 commit 87e4081
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
path: |
${{ env.GOCACHE }}
${{ env.GOMODCACHE }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-go-${{ inputs.ref }}
restore-keys: |
${{ runner.os }}-go-
- name: make ${{ inputs.target }}
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,9 @@ jobs:
target: "cmd"
all_platform: true

build:
if: ${{ github.event_name != 'push' }}
needs: cmd
uses: ./.github/workflows/common.yml
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}
ref: ${{ inputs.ref || github.ref }}
target: "build"

lint:
if: ${{ github.event_name != 'push' }}
needs: build
needs: cmd
uses: ./.github/workflows/common.yml
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}
Expand All @@ -56,7 +47,7 @@ jobs:

test:
if: ${{ github.event_name != 'push' }}
needs: build
needs: cmd
uses: ./.github/workflows/common.yml
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}
Expand Down
24 changes: 11 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,36 @@ endif
IMAGE_TAG ?= latest
EXECUTABLE_TARGETS := $(patsubst cmd/%,cmd_%,$(wildcard cmd/*))

.PHONY: cmd_% build test docker ./bin/golangci-lint ./bin/gocovmerge
.PHONY: cmd_% test lint docker golangci-lint gocovmerge

default: cmd

cmd: $(EXECUTABLE_TARGETS)
dev: cmd lint test

build: cmd
go build $(BUILDFLAGS) ./...
cd lib && go build $(BUILDFLAGS) ./...
cmd: $(EXECUTABLE_TARGETS)

cmd_%: OUTPUT=$(patsubst cmd_%,./bin/%,$@)
cmd_%: SOURCE=$(patsubst cmd_%,./cmd/%,$@)
cmd_%:
go build $(BUILDFLAGS) -o $(OUTPUT) $(SOURCE)

lint: ./bin/golangci-lint
golangci-lint:
GOBIN=$(GOBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

lint: golangci-lint
$(GOBIN)/golangci-lint run
cd lib && $(GOBIN)/golangci-lint run

test: ./bin/gocovmerge
gocovmerge:
GOBIN=$(GOBIN) go install github.com/wadey/gocovmerge@master

test: gocovmerge
rm -f .cover.*
go test -coverprofile=.cover.pkg ./...
cd lib && go test -coverprofile=../.cover.lib ./...
$(GOBIN)/gocovmerge .cover.* > .cover
rm -f .cover.*
go tool cover -html=.cover -o .cover.html

./bin/golangci-lint:
GOBIN=$(GOBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

./bin/gocovmerge:
GOBIN=$(GOBIN) go install github.com/wadey/gocovmerge@master

docker:
docker build $(DOCKERFLAG) -t "tiproxy:${IMAGE_TAG}" --build-arg='GOPROXY=$(shell go env GOPROXY),BUILDFLAGS=$(BUILDFLAGS),' -f docker/Dockerfile .

0 comments on commit 87e4081

Please sign in to comment.