Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add shellspec ci #1007

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/check-chart-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ on:
- "addons/**"
- "addons-cluster/**"
branches:
- '*'
- '*/*'
- '**'
tags-ignore:
- '*'
- '**'

jobs:
check-addons-helm:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/shellcheck-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ name: Shell Check
on:
push:
branches:
- '*'
- '*/*'
- '**'
tags-ignore:
- '*'
- '**'

env:
BASE_BRANCH: origin/main
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/shellspec-pr-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ShellSpec Test PR Review

on:
pull_request_review:
paths:
- "addons/*/scripts-ut-spec/**"
types: [submitted]


jobs:
shellspec-test:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
all_but_latest: true
access_token: ${{ env.GITHUB_TOKEN }}

- uses: actions/checkout@v4

- name: shellspec test
run: |
make scripts-test
70 changes: 70 additions & 0 deletions .github/workflows/shellspec-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: ShellSpec Test

on:
push:
branches:
- '**'
tags-ignore:
- '**'

env:
BASE_BRANCH: origin/main

jobs:
shellspec-test:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
if: ${{ github.ref_name != 'main' }}
uses: styfle/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
all_but_latest: true
access_token: ${{ env.GITHUB_TOKEN }}

- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get base commit id
id: get_base_commit_id
env:
REF_NAME: ${{ github.ref_name }}
run: |
BASE_COMMITID=`bash .github/utils/utils.sh --type 1 \
--branch-name "${{ env.REF_NAME }}" \
--base-branch "${{ env.BASE_BRANCH }}"`

echo "BASE_COMMITID:$BASE_COMMITID"
echo BASE_COMMITID=$BASE_COMMITID >> $GITHUB_ENV

- name: Get file path
id: get_file_path
run: |
FILE_PATH=`git diff --name-only HEAD ${{ env.BASE_COMMITID }}`
echo "FILE_PATH: $FILE_PATH"
SHELL_FILE_PATH=""
for filePath in $(echo "$FILE_PATH"); do
if [[ "${filePath}" == *"addons/"*"/scripts-ut-spec/"* && -f "${filePath}" ]]; then
SHELL_FILE_PATH="${SHELL_FILE_PATH} ${filePath}"
fi
done
echo shell_file_path=$SHELL_FILE_PATH >> $GITHUB_OUTPUT

- name: Install kcov
if: ${{ steps.get_file_path.outputs.shell_file_path || github.ref_name == 'main' }}
run: sudo apt-get install -y bash kcov

- name: shellspec test
if: ${{ steps.get_file_path.outputs.shell_file_path || github.ref_name == 'main' }}
run: |
make scripts-test-kcov

- name: Upload coverage
if: ${{ steps.get_file_path.outputs.shell_file_path || github.ref_name == 'main' }}
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}"
Loading