Skip to content

Commit 62e2384

Browse files
authored
chore: add shellspec ci (#1007)
1 parent 3d322a8 commit 62e2384

File tree

8 files changed

+125
-9
lines changed

8 files changed

+125
-9
lines changed

.github/workflows/check-chart-push.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ on:
66
- "addons/**"
77
- "addons-cluster/**"
88
branches:
9-
- '*'
10-
- '*/*'
9+
- '**'
1110
tags-ignore:
12-
- '*'
11+
- '**'
1312

1413
jobs:
1514
check-addons-helm:

.github/workflows/shellcheck-push.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ name: Shell Check
33
on:
44
push:
55
branches:
6-
- '*'
7-
- '*/*'
6+
- '**'
87
tags-ignore:
9-
- '*'
8+
- '**'
109

1110
env:
1211
BASE_BRANCH: origin/main
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: ShellSpec Test PR Review
2+
3+
on:
4+
pull_request_review:
5+
paths:
6+
- "addons/*/scripts-ut-spec/**"
7+
types: [submitted]
8+
9+
10+
jobs:
11+
shellspec-test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Cancel Previous Runs
15+
uses: styfle/[email protected]
16+
env:
17+
GITHUB_TOKEN: ${{ github.token }}
18+
with:
19+
all_but_latest: true
20+
access_token: ${{ env.GITHUB_TOKEN }}
21+
22+
- uses: actions/checkout@v4
23+
24+
- name: shellspec test
25+
run: |
26+
make scripts-test

.github/workflows/shellspec-push.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: ShellSpec Test
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
tags-ignore:
8+
- '**'
9+
10+
env:
11+
BASE_BRANCH: origin/main
12+
13+
jobs:
14+
shellspec-test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Cancel Previous Runs
18+
if: ${{ github.ref_name != 'main' }}
19+
uses: styfle/[email protected]
20+
env:
21+
GITHUB_TOKEN: ${{ github.token }}
22+
with:
23+
all_but_latest: true
24+
access_token: ${{ env.GITHUB_TOKEN }}
25+
26+
- uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Get base commit id
31+
id: get_base_commit_id
32+
env:
33+
REF_NAME: ${{ github.ref_name }}
34+
run: |
35+
BASE_COMMITID=`bash .github/utils/utils.sh --type 1 \
36+
--branch-name "${{ env.REF_NAME }}" \
37+
--base-branch "${{ env.BASE_BRANCH }}"`
38+
39+
echo "BASE_COMMITID:$BASE_COMMITID"
40+
echo BASE_COMMITID=$BASE_COMMITID >> $GITHUB_ENV
41+
42+
- name: Get file path
43+
id: get_file_path
44+
run: |
45+
FILE_PATH=`git diff --name-only HEAD ${{ env.BASE_COMMITID }}`
46+
echo "FILE_PATH: $FILE_PATH"
47+
SHELL_FILE_PATH=""
48+
for filePath in $(echo "$FILE_PATH"); do
49+
if [[ "${filePath}" == *"addons/"*"/scripts-ut-spec/"* && -f "${filePath}" ]]; then
50+
SHELL_FILE_PATH="${SHELL_FILE_PATH} ${filePath}"
51+
fi
52+
done
53+
echo shell_file_path=$SHELL_FILE_PATH >> $GITHUB_OUTPUT
54+
55+
- name: Install kcov
56+
if: ${{ steps.get_file_path.outputs.shell_file_path || github.ref_name == 'main' }}
57+
run: sudo apt-get install -y bash kcov
58+
59+
- name: shellspec test
60+
if: ${{ steps.get_file_path.outputs.shell_file_path || github.ref_name == 'main' }}
61+
run: |
62+
make scripts-test-kcov
63+
64+
- name: Upload coverage
65+
if: ${{ steps.get_file_path.outputs.shell_file_path || github.ref_name == 'main' }}
66+
env:
67+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
68+
run: |
69+
bash <(curl -s https://codecov.io/bash) -s coverage
70+

.shellspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
# 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.
1212
# --kcov-options "--include-path=. --path-strip-level=1"
13-
# --kcov-options "--include-pattern=.sh"
14-
# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/"
13+
--kcov-options "--include-pattern=.sh"
14+
--kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/"
1515

1616
## Example: Include script "myprog" with no extension
1717
# --kcov-options "--include-pattern=.sh,myprog"

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,12 @@ endif
112112
# run shellspec tests
113113
.PHONY: scripts-test
114114
scripts-test: install-shellspec ## Run shellspec unit test cases.
115-
@shellspec --load-path $(SHELLSPEC_LOAD_PATH) --default-path $(SHELLSPEC_DEFAULT_PATH) --shell $(SHELLSPEC_DEFAULT_SHELL)
115+
@shellspec --load-path $(SHELLSPEC_LOAD_PATH) --default-path $(SHELLSPEC_DEFAULT_PATH) --shell $(SHELLSPEC_DEFAULT_SHELL)
116+
117+
118+
SHELLSPEC_INCLUDE_PATH := $(shell ./utils/get_shellspec_include_path.sh)
119+
120+
# run shellspec tests with coverage report
121+
.PHONY: scripts-test-kcov
122+
scripts-test-kcov: install-shellspec ## Run shellspec unit test cases.
123+
@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"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# kubeblocks-addons
22
KubeBlocks add-ons.
33

4+
[![codecov](https://codecov.io/gh/apecloud/kubeblocks-addons/graph/badge.svg?token=NGTPFMY8NG)](https://codecov.io/gh/apecloud/kubeblocks-addons)
5+
46
## Add-on Tutorial
57
> NOTE: This tutorial is applicable for KubeBlocks version 0.9.0.
68

utils/get_shellspec_include_path.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
INCLUDE_PATH=""
4+
for dir in $(find addons -maxdepth 2 -type d -name "scripts-ut-spec"); do
5+
if [ -z "$INCLUDE_PATH" ]; then
6+
INCLUDE_PATH=$dir
7+
else
8+
INCLUDE_PATH=${INCLUDE_PATH},$dir
9+
fi
10+
done
11+
12+
echo "${INCLUDE_PATH}"

0 commit comments

Comments
 (0)