Skip to content

Commit

Permalink
chore: add shellspec coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
JashBook committed Sep 4, 2024
1 parent 6044d61 commit 44be8c5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/shellspec-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .shellspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
@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"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 12 additions & 0 deletions utils/get_shellspec_include_path.sh
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit 44be8c5

Please sign in to comment.