From 8dab09824f9230d6b10240b890c7d27c53e22660 Mon Sep 17 00:00:00 2001 From: Arkadiusz Galwas Date: Tue, 20 Feb 2024 18:09:11 +0100 Subject: [PATCH] Add Github action for the common logging library --- .github/workflows/test-common.yaml | 33 ++++++++++++ common/Makefile | 9 +++- common/before-commit.sh | 86 ------------------------------ 3 files changed, 40 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/test-common.yaml delete mode 100755 common/before-commit.sh diff --git a/.github/workflows/test-common.yaml b/.github/workflows/test-common.yaml new file mode 100644 index 000000000000..8d8899775dc5 --- /dev/null +++ b/.github/workflows/test-common.yaml @@ -0,0 +1,33 @@ +name: Run unit tests +on: + push: + branches: [ "main" ] + pull_request: +permissions: + contents: read +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up cache + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + /home/runner/work/common/bin + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Set up go environment + uses: actions/setup-go@v4 + with: + go-version: 1.21.5 + + - name: Run unit tests + run: make test + diff --git a/common/Makefile b/common/Makefile index 71a446e1913f..3050cae11a4c 100644 --- a/common/Makefile +++ b/common/Makefile @@ -4,8 +4,13 @@ TAG = $(DOCKER_TAG) .PHONY: build build: - ./before-commit.sh - cd logging && ./before-commit.sh && cd - + go mod vendor + go mod verify + go test -count 100 -race -coverprofile=cover.out ./... + +testi: +.PHONY: test +test: build .PHONY: ci-pr ci-pr: build diff --git a/common/before-commit.sh b/common/before-commit.sh deleted file mode 100755 index cea47e1a802f..000000000000 --- a/common/before-commit.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env bash - -RED='\033[0;31m' -GREEN='\033[0;32m' -INVERTED='\033[7m' -NC='\033[0m' # No Color - -echo -e "${INVERTED}" -echo "USER: " + ${USER} -echo "PATH: " + ${PATH} -echo "GOPATH:" + ${GOPATH} -echo -e "${NC}" - -## -# GO MOD VENDOR -## -echo "? go mod vendor" -GO111MODULE=on go mod vendor -vendorResult=$? -if [[ ${vendorResult} != 0 ]]; then - echo -e "${RED}✗ go mod vendor${NC}\n$vendorResult${NC}" - exit 1 -else echo -e "${GREEN}√ go mod vendor${NC}" -fi - -## -# GO MOD VERIFY -## -echo "? go mod verify" -verifyResult=$(GO111MODULE=on go mod verify) -if [[ $? != 0 ]]; then - echo -e "${RED}✗ go mod verify\n$verifyResult${NC}" - exit 1 -else echo -e "${GREEN}√ go mod verify${NC}" -fi - -## -# GO TEST -## -echo "? go test" -go test -count 100 -race -coverprofile=cover.out ./... -# Check if tests passed -if [[ $? != 0 ]]; then - echo -e "${RED}✗ go test\n${NC}" - rm cover.out - exit 1 -else - echo -e "Total coverage: $(go tool cover -func=cover.out | grep total | awk '{print $3}')" - rm cover.out - echo -e "${GREEN}√ go test${NC}" -fi - - -## -# GO IMPORTS & FMT -## -go build -o goimports-vendored ./vendor/golang.org/x/tools/cmd/goimports -buildGoImportResult=$? -if [[ ${buildGoImportResult} != 0 ]]; then - echo -e "${RED}✗ go build goimports${NC}\n$buildGoImportResult${NC}" - exit 1 -fi - -goFilesToCheck=$(find . -type f -name "*.go" | egrep -v "/vendor") -goImportsResult=$(echo "${goFilesToCheck}" | xargs -L1 ./goimports-vendored -w -l) -rm goimports-vendored - -if [[ $(echo ${#goImportsResult}) != 0 ]]; then - echo -e "${RED}✗ goimports and fmt${NC}\n$goImportsResult${NC}" - exit 1 -else echo -e "${GREEN}√ goimports and fmt${NC}" -fi - -## -# GO VET -## -packagesToVet=($(go list ./... | grep -v /vendor/)) - -for vPackage in "${packagesToVet[@]}"; do - vetResult=$(go vet ${vPackage}) - if [[ $(echo ${#vetResult}) != 0 ]]; then - echo -e "${RED}✗ go vet ${vPackage} ${NC}\n$vetResult${NC}" - exit 1 - else echo -e "${GREEN}√ go vet ${vPackage} ${NC}" - fi -done