From 44be8c5c73caae173477b7c83f56233b8d9de58d Mon Sep 17 00:00:00 2001 From: huangzhangshu Date: Wed, 4 Sep 2024 21:18:14 +0800 Subject: [PATCH] chore: add shellspec coverage --- .github/workflows/shellspec-push.yml | 14 +++++++++++++- .shellspec | 4 ++-- Makefile | 10 +++++++++- README.md | 2 ++ utils/get_shellspec_include_path.sh | 12 ++++++++++++ 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100755 utils/get_shellspec_include_path.sh diff --git a/.github/workflows/shellspec-push.yml b/.github/workflows/shellspec-push.yml index 4169f90b6..3830147a5 100644 --- a/.github/workflows/shellspec-push.yml +++ b/.github/workflows/shellspec-push.yml @@ -52,7 +52,19 @@ jobs: done echo shell_file_path=$SHELL_FILE_PATH >> $GITHUB_OUTPUT + - name: Install kcov + if: ${{ steps.get_file_path.outputs.shell_file_path }} + run: sudo apt-get install -y bash kcov + - name: shellspec test if: ${{ steps.get_file_path.outputs.shell_file_path }} run: | - make scripts-test + make scripts-test-kcov + + - name: Upload coverage + if: ${{ steps.get_file_path.outputs.shell_file_path }} + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + run: | + bash <(curl -s https://codecov.io/bash) -s coverage + diff --git a/.shellspec b/.shellspec index 9e95fb9d6..24ab30d72 100644 --- a/.shellspec +++ b/.shellspec @@ -10,8 +10,8 @@ # By default only shell scripts whose names contain .sh are coverage targeted. If you want to include other files, you need to adjust options with --kcov-options. # --kcov-options "--include-path=. --path-strip-level=1" -# --kcov-options "--include-pattern=.sh" -# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/" +--kcov-options "--include-pattern=.sh" +--kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/" ## Example: Include script "myprog" with no extension # --kcov-options "--include-pattern=.sh,myprog" diff --git a/Makefile b/Makefile index 15b389043..7edb33490 100644 --- a/Makefile +++ b/Makefile @@ -112,4 +112,12 @@ endif # run shellspec tests .PHONY: scripts-test scripts-test: install-shellspec ## Run shellspec unit test cases. - @shellspec --load-path $(SHELLSPEC_LOAD_PATH) --default-path $(SHELLSPEC_DEFAULT_PATH) --shell $(SHELLSPEC_DEFAULT_SHELL) \ No newline at end of file + @shellspec --load-path $(SHELLSPEC_LOAD_PATH) --default-path $(SHELLSPEC_DEFAULT_PATH) --shell $(SHELLSPEC_DEFAULT_SHELL) + + +SHELLSPEC_INCLUDE_PATH := $(shell ./utils/get_shellspec_include_path.sh) + +# run shellspec tests with coverage report +.PHONY: scripts-test-kcov +scripts-test-kcov: install-shellspec ## Run shellspec unit test cases. + @shellspec --load-path $(SHELLSPEC_LOAD_PATH) --default-path $(SHELLSPEC_DEFAULT_PATH) --shell $(SHELLSPEC_DEFAULT_SHELL) --kcov --kcov-options "--include-path=$(SHELLSPEC_INCLUDE_PATH) --path-strip-level=1" diff --git a/README.md b/README.md index 89d851bbe..123120ff1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # kubeblocks-addons KubeBlocks add-ons. +[![codecov](https://codecov.io/gh/apecloud/kubeblocks-addons/graph/badge.svg?token=NGTPFMY8NG)](https://codecov.io/gh/apecloud/kubeblocks-addons) + ## Add-on Tutorial > NOTE: This tutorial is applicable for KubeBlocks version 0.9.0. diff --git a/utils/get_shellspec_include_path.sh b/utils/get_shellspec_include_path.sh new file mode 100755 index 000000000..72de068dd --- /dev/null +++ b/utils/get_shellspec_include_path.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +INCLUDE_PATH="" +for dir in $(find addons -maxdepth 2 -type d -name "scripts-ut-spec"); do + if [ -z "$INCLUDE_PATH" ]; then + INCLUDE_PATH=$dir + else + INCLUDE_PATH=${INCLUDE_PATH},$dir + fi +done + +echo "${INCLUDE_PATH}"