Skip to content
Open
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ $(call verify-golang-versions,Dockerfile)

$(call add-crd-gen,kueueoperator,./pkg/apis/kueueoperator/v1,./manifests/,./manifests/)

.PHONY: coverage
coverage: ## Run unit tests with coverage and upload to Codecov
hack/codecov.sh

.PHONY: test-e2e
test-e2e: ginkgo
${GINKGO} --keep-going --flake-attempts=3 --label-filter="!disruptive" -v ./test/e2e/...
Expand Down
33 changes: 33 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
coverage:
status:
project:
default:
target: auto
threshold: 1%
base: auto
patch:
default:
target: 80%
threshold: 1%
base: auto

comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: false

ignore:
- "vendor/"
- "upstream/"
- "bindata/"
- "**/*_test.go"
- "test/"
- "hack/"
- "pkg/generated/"
- "**/zz_generated.*.go"
- "cmd/"
- "bundle/"
- "manifests/"

github_checks:
annotations: true
46 changes: 46 additions & 0 deletions hack/codecov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
set -euo pipefail

echo "Running unit tests with coverage..."

# Generate coverage report using the same test scope as current `make test`
# This aligns with GO_TEST_PACKAGES=./pkg/... in the Makefile
go test -mod=vendor -race -coverprofile=coverage.out -covermode=atomic ./pkg/...

echo "Coverage report generated: coverage.out"

# Only upload to Codecov if token is provided (for CI environments)
if [[ -n "${CODECOV_TOKEN:-}" ]]; then
echo "Uploading coverage to Codecov..."

# Download Codecov CLI (more reliable than codecov-action in Prow)
# Detect platform and download appropriate binary
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
linux*)
CODECOV_URL="https://cli.codecov.io/latest/linux/codecov"
;;
darwin*)
CODECOV_URL="https://cli.codecov.io/latest/macos/codecov"
;;
*)
echo "Unsupported OS: $OS"
exit 1
;;
esac

curl -Os "$CODECOV_URL"
chmod +x codecov

# Upload with unit-tests flag for proper categorization
./codecov upload-process \
--token "${CODECOV_TOKEN}" \
--slug "openshift/kueue-operator" \
--flag unit-tests \
--file coverage.out \
--branch "${PULL_BASE_REF:-main}"

echo "Coverage uploaded successfully!"
else
echo "CODECOV_TOKEN not provided, skipping upload (local development)"
fi