Skip to content

Commit

Permalink
update makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-Morgan committed Sep 3, 2024
1 parent 2358778 commit d6cfb97
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
go-version: "1.21"

- name: Unit Test
run: go test -race -covermode=atomic -coverprofile=coverage.out ./...
run: make test

- name: Benchmark
run: go test -bench=. -benchmem -run=none ./...
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
TOOLS_SHELL="./hack/tools.sh"

.PHONY: test
test:
@${TOOLS_SHELL} test
@echo "go test finished"



.PHONY: vet
vet:
@${TOOLS_SHELL} vet
@echo "vet check finished"
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ module github.com/cloudwego-contrib/cwgo-pkg

go 1.21


replace github.com/apache/thrift => github.com/apache/thrift v0.13.0
22 changes: 22 additions & 0 deletions hack/resolve-modules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# This is used by the linter action.
# Recursively finds all directories with a go.mod file and creates
# a GitHub Actions JSON output option.

set -o errexit

HOME=$(
cd "$(dirname "${BASH_SOURCE[0]}")" &&
cd .. &&
pwd
)

source "${HOME}/hack/util.sh"
all_modules=$(util::find_modules)
PATHS=""
for mod in $all_modules; do
PATHS+=$(printf '{"workdir":"%s"},' ${mod})
done

echo "::set-output name=matrix::{\"include\":[${PATHS%?}]}"
51 changes: 51 additions & 0 deletions hack/tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

HOME=$(
cd "$(dirname "${BASH_SOURCE[0]}")" &&
cd .. &&
pwd
)

source "${HOME}/hack/util.sh"

all_modules=$(util::find_modules)

# test all mod
function test() {
for mod in $all_modules; do
pushd "$mod" >/dev/null &&
echo "go test $(sed -n 1p go.mod | cut -d ' ' -f2)" &&
go test -race -covermode=atomic -coverprofile=coverage.out ./...
popd >/dev/null || exit
done
}

# vet all mod
function vet() {
for mod in $all_modules; do
pushd "$mod" >/dev/null &&
echo "go vet $(sed -n 1p go.mod | cut -d ' ' -f2)" &&
go vet -stdmethods=false ./...
popd >/dev/null || exit
done
}

function help() {
echo "use: test,vet"
}

case $1 in
vet)
vet
;;
test)
test
;;
*)
help
;;
esac
14 changes: 14 additions & 0 deletions hack/util.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# find all go mod path
# returns an array contains mod path
function util::find_modules() {
find . -not \( \
\( \
-path './output' \
-o -path './.git' \
-o -path '*/third_party/*' \
-o -path '*/vendor/*' \
\) -prune \
\) -name 'go.mod' -print0 | xargs -0 -I {} dirname {}
}

0 comments on commit d6cfb97

Please sign in to comment.