Skip to content

Commit 2ca0f4f

Browse files
authored
Merge pull request #2972 from kolyshkin/fix-ci
CI: fix GHA CI not running unit tests in cmd
2 parents 8b96dc6 + 4421e25 commit 2ca0f4f

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ jobs:
2424
- name: Run tests
2525
env:
2626
GOLANG_VERSION: ${{ matrix.go-versions }}
27-
run: source ${{ matrix.environment-variables }} && make docker-test
27+
run: |
28+
source ${{ matrix.environment-variables }}
29+
make test
2830
test-integration:
2931
strategy:
3032
matrix:
@@ -36,15 +38,11 @@ jobs:
3638
steps:
3739
- name: Checkout code
3840
uses: actions/checkout@v2
39-
with:
40-
fetch-depth: 1
41-
path: go/src/github.com/google/cadvisor
4241
- name: Run integration tests
4342
env:
4443
GOLANG_VERSION: ${{ matrix.go-versions }}
4544
run: |
4645
set -ex
47-
cd $GITHUB_WORKSPACE/go/src/github.com/google/cadvisor
4846
source ${{ matrix.environment-variables }}
4947
make docker-test-integration
5048
- name: Upload cAdvisor log file

Makefile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
GO := go
1616
GOLANGCI_VER := v1.42.1
17-
pkgs = $(shell $(GO) list ./... | grep -v vendor)
18-
cmd_pkgs = $(shell cd cmd && $(GO) list ./... | grep -v vendor)
17+
GO_TEST ?= $(GO) test $(or $(GO_FLAGS),-race)
1918
arch ?= $(shell go env GOARCH)
2019

2120
ifeq ($(arch), amd64)
@@ -29,13 +28,12 @@ all: presubmit build test
2928

3029
test:
3130
@echo ">> running tests"
32-
@$(GO) test -short -race $(pkgs)
33-
@cd cmd && $(GO) test -short -race $(cmd_pkgs)
31+
@# Filter out integration.
32+
$(GO) list ./... | grep -vw integration | xargs $(GO_TEST)
33+
cd cmd && $(GO_TEST) ./...
3434

35-
test-with-libpfm:
36-
@echo ">> running tests"
37-
@$(GO) test -short -race -tags="libpfm" $(pkgs)
38-
@cd cmd && $(GO) test -short -race -tags="libpfm" $(cmd_pkgs)
35+
test-with-libpfm: GO_FLAGS=-race -tags libpfm
36+
test-with-libpfm: test
3937

4038
container-test:
4139
@echo ">> runinng tests in a container"
@@ -45,9 +43,9 @@ docker-test: container-test
4543
@echo "docker-test target is deprecated, use container-test instead"
4644

4745
test-integration:
48-
@GO_FLAGS=${$GO_FLAGS:-"-race"} ./build/build.sh
49-
go test -c github.com/google/cadvisor/integration/tests/api
50-
go test -c github.com/google/cadvisor/integration/tests/healthz
46+
GO_FLAGS=$(or $(GO_FLAGS),-race) ./build/build.sh
47+
$(GO_TEST) -c github.com/google/cadvisor/integration/tests/api
48+
$(GO_TEST) -c github.com/google/cadvisor/integration/tests/healthz
5149
@./build/integration.sh
5250

5351
docker-test-integration:

build/unit-in-container.sh

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,28 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
set -e
17+
set -ex
1818

19-
CONTAINER_ENGINE=$(command -v docker || true)
20-
if [ "$CONTAINER_ENGINE" == "" ]; then
21-
CONTAINER_ENGINE=$(command -v podman || true)
22-
fi
23-
if [ "$CONTAINER_ENGINE" == "" ]; then
24-
echo "Unable to find docker and podman. Exiting."
19+
if ! CONTAINER_ENGINE=$(command -v docker || command -v podman); then
20+
echo "Neither docker nor podman found. Exiting."
2521
exit 1
2622
fi
2723

2824
function run_tests() {
29-
BUILD_CMD="go test $GO_FLAGS $(go list $GO_FLAGS ./... | grep -v 'vendor\|integration' | tr '\n' ' ') && \
30-
cd cmd && go test $GO_FLAGS $(go list $GO_FLAGS ./... | grep -v 'vendor\|integration' | tr '\n' ' ')"
25+
BUILD_CMD="make test"
3126
if [ "$BUILD_PACKAGES" != "" ]; then
32-
BUILD_CMD="echo 'deb http://deb.debian.org/debian buster-backports main'>/etc/apt/sources.list.d/buster.list && \
33-
apt update && \
34-
apt install -y -t buster-backports $BUILD_PACKAGES && \
27+
BUILD_CMD="echo 'deb http://deb.debian.org/debian buster-backports main'>/etc/apt/sources.list.d/buster.list
28+
apt update
29+
apt install -y -t buster-backports $BUILD_PACKAGES
3530
$BUILD_CMD"
3631
fi
3732

3833
$CONTAINER_ENGINE run --rm \
3934
-w /go/src/github.com/google/cadvisor \
4035
-v ${PWD}:/go/src/github.com/google/cadvisor \
36+
-e GO_FLAGS \
4137
golang:${GOLANG_VERSION} \
42-
bash -c "$BUILD_CMD"
38+
bash -e -c "$BUILD_CMD"
4339
}
4440

4541
GO_FLAGS=${GO_FLAGS:-"-tags=netgo -race"}

0 commit comments

Comments
 (0)