Skip to content

Commit

Permalink
*: add CI pipe line (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Aug 23, 2022
1 parent 0de79f7 commit 2ca3230
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 28 deletions.
90 changes: 90 additions & 0 deletions .github/workflow_calls/common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: common
on:
workflow_call:
inputs:
debug:
type: boolean
description: "set tmate on failure"
required: true

jobs:
build_cmd:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: "checkout repo"
uses: actions/checkout@v3
- name: "setup golang"
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: "try to use build cache"
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
~/Library/Caches/go-build
~\AppData\Local\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: "build cmd"
run: make
- name: "set up tmate session if necessary"
if: ${{ failure() && inputs.debug }}
uses: mxschmitt/action-tmate@v3

build:
runs-on: ubuntu-latest
steps:
- name: "checkout repo"
uses: actions/checkout@v3
- name: "setup golang"
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: "try to use build cache"
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
~/Library/Caches/go-build
~\AppData\Local\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: "build all"
run: make build
- name: "set up tmate session if necessary"
if: ${{ failure() && inputs.debug }}
uses: mxschmitt/action-tmate@v3

test:
runs-on: ubuntu-latest
steps:
- name: "checkout repo"
uses: actions/checkout@v3
- name: "setup golang"
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: "try to use build cache"
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
~/Library/Caches/go-build
~\AppData\Local\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: "test all"
run: make test
- name: "set up tmate session if necessary"
if: ${{ failure() && inputs.debug }}
uses: mxschmitt/action-tmate@v3
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: build
on:
workflow_dispatch:
inputs:
debug:
type: boolean
description: "Run the build with tmate debugging enabled"
required: false
default: false
pull_request:
branches:
- master
- release-*

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
build_cmd:
uses: ./.github/workflow_calls/common.yml@test
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}

build:
needs: build_cmd
uses: ./.github/workflow_calls/common.yml@test
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: test
on:
workflow_dispatch:
inputs:
debug:
type: boolean
description: "Run the build with tmate debugging enabled"
required: false
default: false
workflow_run:
workflows: ["build"]
branches:
- master
- release-*
types:
- completed

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
test:
uses: ./.github/workflow_calls/common.yml@test
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ bin
.DS_Store
vendor
.vscode/
.coverage*
44 changes: 16 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,29 @@
# limitations under the License.

PROJECTNAME = $(shell basename "$(PWD)")
TOOL_BIN_PATH := $(shell pwd)/.tools/bin
GOBASE = $(shell pwd)
GOBIN := $(shell pwd)/bin
BUILD_TAGS ?=
LDFLAGS ?=
export GOBIN := $(TOOL_BIN_PATH)
export PATH := $(TOOL_BIN_PATH):$(PATH)

default: weirproxy weirctl

weirproxy:
GOFLAGS ?= -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -tags '${BUILD_TAGS}'
ifeq ("$(WITH_RACE)", "1")
go build -race -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -tags '${BUILD_TAGS}' -o bin/weirproxy cmd/weirproxy/main.go
else
go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -tags '${BUILD_TAGS}' -o bin/weirproxy cmd/weirproxy/main.go
GOFLAGS = $(GOFLAGS) -race
endif
EXECUTABLE_TARGETS := $(patsubst cmd/%,cmd_%,$(wildcard cmd/*))

weirctl:
ifeq ("$(WITH_RACE)", "1")
go build -race -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -tags '${BUILD_TAGS}' -o bin/weirctl cmd/weirctl/main.go
else
go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -tags '${BUILD_TAGS}' -o bin/weirctl cmd/weirctl/main.go
endif
default: cmd

cmd: $(EXECUTABLE_TARGETS)

go-test:
build: cmd
go build $(GOFLAGS) ./...

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

test:
go test -coverprofile=.coverage.out ./...
go tool cover -func=.coverage.out -o .coverage.func
tail -1 .coverage.func
go tool cover -html=.coverage.out -o .coverage.html

go-lint-check: install-tools
golangci-lint run

go-lint-fix: install-tools
golangci-lint run --fix

install-tools:
@mkdir -p $(TOOL_BIN_PATH)
@test -e $(TOOL_BIN_PATH)/golangci-lint >/dev/null 2>&1 || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOL_BIN_PATH) v1.30.0

0 comments on commit 2ca3230

Please sign in to comment.