Skip to content

Commit 4eaa7a3

Browse files
ci(makefile): add makefile for ci
1 parent 0b13d90 commit 4eaa7a3

2 files changed

Lines changed: 79 additions & 48 deletions

File tree

.github/workflows/ci.yml

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,59 +24,62 @@ on:
2424
- develop
2525

2626
jobs:
27-
unit-test:
28-
name: Go Test
29-
runs-on: ubuntu-latest
30-
if: github.repository == 'apache/dubbo-admin'
31-
steps:
32-
- uses: actions/checkout@v4
33-
- name: Set up Go 1.x
34-
uses: actions/setup-go@v5
35-
with:
36-
go-version-file: go.mod
37-
- name: Download dependencies
38-
run: |
39-
go mod download
40-
- name: Go Test
41-
run: |
42-
go test ./... -gcflags=-l -coverprofile=coverage.txt -covermode=atomic
43-
- name: "Upload test result"
44-
if: always()
45-
uses: actions/upload-artifact@v4
46-
with:
47-
name: test-coverage
48-
path: "**/coverage.txt"
49-
- name: Coverage
50-
run: bash <(curl -s https://codecov.io/bash)
51-
5227
license-check:
53-
name: License Check - Go
28+
name: License Check
5429
runs-on: ubuntu-latest
5530
if: github.repository == 'apache/dubbo-admin'
5631
steps:
5732
- uses: actions/checkout@v4
58-
- name: Set up Go 1.x
59-
uses: actions/setup-go@v5
60-
with:
61-
go-version-file: go.mod
62-
6333
- name: Check License Header
6434
uses: apache/skywalking-eyes/header@main
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
with:
38+
config: .licenserc.yaml
39+
mode: check
6540

66-
go-fmt:
67-
name: Go fmt
68-
runs-on: ubuntu-latest
41+
CI:
42+
name: CI (${{ matrix.os }} - Go ${{ matrix.go_version }})
43+
runs-on: ${{ matrix.os }}
44+
strategy:
45+
# If you want to matrix build , you can append the following list.
46+
matrix:
47+
go_version:
48+
- "1.24"
49+
- "1.23"
50+
os:
51+
- ubuntu-latest
6952
if: github.repository == 'apache/dubbo-admin'
7053
steps:
7154
- uses: actions/checkout@v4
72-
- name: Set up Go 1.x
55+
- name: Setup Go ${{ matrix.go_version }}
7356
uses: actions/setup-go@v5
7457
with:
7558
go-version-file: go.mod
76-
- name: Download dependencies
77-
run: |
78-
go mod download
79-
- name: Go Fmt
80-
run: |
81-
go fmt ./... && git status && [[ -z `git status -s` ]]
82-
# diff -u <(echo -n) <(gofmt -d -s .)
59+
- name: Cache dependencies
60+
# ref: https://github.com/actions/cache/blob/main/examples.md#go---module
61+
uses: actions/cache@v4
62+
with:
63+
# Cache, works only on Linux
64+
path: |
65+
~/.cache/go-build
66+
~/go/pkg/mod
67+
# Cache key
68+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
69+
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key
70+
restore-keys: |
71+
${{ runner.os }}-go-
72+
- name: Check Code Format
73+
run: make fmt && git status && [[ -z `git status -s` ]]
74+
- name: Run Unit Test
75+
run: make test
76+
# TODO(marsevilspirit): add lint
77+
- name: Upload test result
78+
if: always()
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: test-coverage
82+
path: "**/coverage.txt"
83+
- name: Coverage
84+
# TODO(marsevilspirit): fix coverage
85+
run: bash <(curl -s https://codecov.io/bash)

Makefile

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,38 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
SHELL := /usr/bin/env bash
16+
SHELL := bash
17+
.DELETE_ON_ERROR:
18+
.DEFAULT_GOAL := help
19+
.SHELLFLAGS := -eu -o pipefail -c
20+
MAKEFLAGS += --warn-undefined-variables
21+
MAKEFLAGS += --no-builtin-rules
22+
MAKEFLAGS += --no-print-directory
1723

18-
.PHONY: build-dubbo-admin
19-
build-dubbo-admin:
20-
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
21-
-ldflags "-X github.com/apache/dubbo-admin/pkg/version.gitTag=$(GIT_VERSION)" \
22-
-o bin/dubbo-admin app/dubbo-main/main.go && cp app/dubbo-admin/dubbo-admin.yaml bin/
24+
.PHONY: help test fmt clean lint
25+
26+
help:
27+
@echo "Available commands:"
28+
@echo " test - Run unit tests"
29+
@echo " clean - Clean test generate files"
30+
@echo " fmt - Format code"
31+
@echo " lint - Run golangci-lint"
32+
33+
# Run unit tests
34+
test: clean
35+
go test ./... -gcflags=-l -coverprofile=coverage.txt -covermode=atomic
36+
37+
fmt:
38+
go fmt ./...
39+
40+
# Clean test generate files
41+
clean:
42+
rm -rf coverage.txt
43+
44+
# Run golangci-lint
45+
lint: install-golangci-lint
46+
go vet ./...
47+
golangci-lint run ./... --timeout=10m
48+
49+
install-golangci-lint:
50+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0

0 commit comments

Comments
 (0)