-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from micha37-martins/dev
Dev
- Loading branch information
Showing
15 changed files
with
4,802 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# yamllint disable rule:line-length | ||
--- | ||
name: Coverage | ||
|
||
# yamllint disable-line rule:truthy | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
|
||
jobs: | ||
coverage: | ||
runs-on: ubuntu-22.04 | ||
container: | ||
image: kcov/kcov:v42 | ||
options: --privileged | ||
# volumes: | ||
# - ${{ github.workspace }}:/workspace | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3.6.0 | ||
|
||
- name: Install necessary tools (Git and Curl) | ||
run: | | ||
apt-get update && apt-get install -y curl git jq smartmontools | ||
- name: Install specific version of bats | ||
run: | | ||
curl -L https://github.com/bats-core/bats-core/archive/v1.4.1.tar.gz | tar -xz | ||
cd bats-core-1.4.1 | ||
./install.sh /usr/local | ||
rm -rf bats-core-1.4.1 | ||
- name: Checkout code with submodules | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: true # Fetch all submodules | ||
fetch-depth: 0 # Fetch full history, required for submodules | ||
submodule-token: ${{ secrets.GITHUB_TOKEN }} # Ensure access to private submodules if needed | ||
|
||
- name: Run coverage script with Bash | ||
run: | | ||
chmod +x ./coverage.sh | ||
bash ./coverage.sh | ||
- name: Extract coverage percentage from index.js | ||
id: coverage | ||
shell: bash | ||
run: | | ||
coverage=$(grep -oP '(?<=covered":")[^"]+' ./coverage/test_smartmon.coverage/index.js | head -n 1) | ||
echo "Extracted coverage percentage: $coverage" | ||
echo "::set-output name=coverage::$coverage" | ||
- name: Print Current Working Directory | ||
run: pwd | ||
|
||
- name: Configure Git Safe Directory | ||
run: | | ||
git config --global --add safe.directory "$(pwd)" | ||
- name: Update README.md with coverage badge | ||
run: | | ||
sed -i 's|https:\/\/img\.shields\.io\/badge\/Coverage-[0-9]*\(\.[0-9]*\)\?%25-brightgreen|https:\/\/img\.shields\.io\/badge\/Coverage-65.2%25-brightgreen|g' README.md | ||
git config --global user.name 'github-actions[bot]' | ||
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | ||
git add README.md # Ensure README.md is staged | ||
git commit -m "Update coverage badge" | ||
git push origin ${GITHUB_REF#refs/heads/} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.swp | ||
*.swo | ||
*.tmp | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[submodule "test/bats"] | ||
path = test/bats | ||
url = https://github.com/bats-core/bats-core.git | ||
[submodule "test/test_helper/bats-support"] | ||
path = test/test_helper/bats-support | ||
url = https://github.com/bats-core/bats-support.git | ||
[submodule "test/test_helper/bats-assert"] | ||
path = test/test_helper/bats-assert | ||
url = https://github.com/bats-core/bats-assert.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env bash | ||
|
||
SRC_DIR="./src" | ||
TEST_DIR="./test" | ||
COVERAGE_DIR="./coverage" | ||
|
||
# Function to create the coverage directory | ||
create_coverage_dir() { | ||
mkdir -p "$COVERAGE_DIR" | ||
} | ||
|
||
# Function to run kcov with bats tests | ||
run_kcov() { | ||
local test_file; test_file="$1" | ||
local src_file; src_file="$2" | ||
local coverage_file; coverage_file="$COVERAGE_DIR/$(basename "$test_file" .bats).coverage" | ||
|
||
if ! kcov --bash-dont-parse-binary-dir --include-path="$SRC_DIR" "$coverage_file" bats -t "$test_file"; then | ||
printf "Error: kcov failed for %s\n" "$test_file" >&2 | ||
return 1 | ||
fi | ||
} | ||
|
||
# Main function | ||
main() { | ||
create_coverage_dir | ||
|
||
local test_file; test_file="$TEST_DIR/test_smartmon.bats" | ||
local src_file; src_file="$SRC_DIR/smartmon.sh" | ||
|
||
if [[ ! -f "$test_file" ]]; then | ||
printf "Error: Test file %s does not exist\n" "$test_file" >&2 | ||
return 1 | ||
fi | ||
|
||
if [[ ! -f "$src_file" ]]; then | ||
printf "Error: Source file %s does not exist\n" "$src_file" >&2 | ||
return 1 | ||
fi | ||
|
||
if ! run_kcov "$test_file" "$src_file"; then | ||
printf "Error: Failed to run kcov for %s\n" "$test_file" >&2 | ||
return 1 | ||
fi | ||
|
||
printf "Coverage report generated in %s\n" "$COVERAGE_DIR" | ||
} | ||
|
||
main "$@" |
Oops, something went wrong.