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

Combine coverage before upload #235

Closed
wants to merge 1 commit into from
Closed
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
42 changes: 35 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ jobs:
shell: bash
run: |
if [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
build_helpers/run-ci.sh
build_helpers/run-ci.sh requirements lint tests
else
sudo -E build_helpers/run-ci.sh
sudo -E build_helpers/run-ci.sh requirements lint tests
fi
env:
PYTEST_ADDOPTS: --color=yes
Expand All @@ -119,26 +119,54 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: Unit Test Results (${{ matrix.os }} ${{ matrix.python-version }} ${{ matrix.python-arch }})
path: ./junit/test-results.xml
path: ./reports/junit/*

- name: Upload Coverage Results
if: always()
uses: actions/upload-artifact@v3
with:
name: Coverage Results (${{ matrix.os }} ${{ matrix.python-version }} ${{ matrix.python-arch }})
path: ./coverage.xml
path: ./reports/coverage/*

tests_done:
name: Tests done
runs-on: ubuntu-latest
needs: [test]

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Select python
uses: actions/setup-python@v4

- name: Download all coverage reports
uses: actions/download-artifact@v3
with:
path: reports/coverage

- name: Move coverage data to the root folder
run: find reports/coverage -type f -exec mv '{}' reports/coverage/ \;

- name: Combine coverage
shell: bash
run: |
if [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
build_helpers/run-ci.sh requirements coverage
else
sudo -E build_helpers/run-ci.sh requirements coverage
fi

- name: Upload Coverage to codecov
if: always()
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
flags: ${{ steps.os.outputs.name }},py${{ matrix.python-version }},${{ matrix.python-arch }}
files: ./reports/coverage/coverage.xml

publish:
name: publish
needs:
- test
- tests_done
runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ nosetests.xml
coverage.xml
*.cover
.hypothesis/
reports/

# Translations
*.mo
Expand Down Expand Up @@ -114,4 +115,4 @@ ENV/
# Vagrant test files
build-scripts/.vagrant
tests/integration/.vagrant/
tests/integration/artifact.zip
tests/integration/artifact.zip
62 changes: 50 additions & 12 deletions build_helpers/lib.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash


lib::setup::smb_server() {
lib::server::start() {
if [ x"${GITHUB_ACTIONS}" = "xtrue" ]; then
echo "::group::Setting up SMB Server"
fi
Expand Down Expand Up @@ -29,38 +28,60 @@ lib::setup::smb_server() {
export SMB_USER=smbuser
export SMB_PASSWORD=smbpass

docker stop smbserver || true
docker rm smbserver || true

docker run \
--detach \
--rm \
--name smbserver \
--publish ${SMB_PORT}:445 \
--volume $( pwd )/build_helpers:/app:z \
--volume $(pwd)/build_helpers:/app:z \
--workdir /app \
debian:12 \
/bin/bash \
/app/samba-setup.sh \
${SMB_SHARE} \
${SMB_USER} \
${SMB_PASSWORD}
fi

if [ x"${GITHUB_ACTIONS}" = "xtrue" ]; then
echo "::endgroup::"
fi
}

lib::server::stop() {
if [ x"${GITHUB_ACTIONS}" = "xtrue" ]; then
echo "::group::Setting up SMB Server"
fi

if [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
echo "Running on Windows, cannot stop server"
elif [ "$(uname)" == "Darwin" ]; then
echo "Running on macOS, no Docker available in CI, skipping integration tests"
else
docker stop smbserver || true
docker rm smbserver || true
fi

if [ x"${GITHUB_ACTIONS}" = "xtrue" ]; then
echo "::endgroup::"
fi
}

lib::setup::python_requirements() {
lib::requirements::install() {
if [ x"${GITHUB_ACTIONS}" = "xtrue" ]; then
echo "::group::Installing Python Requirements"
fi

echo "Installing smbprotocol"
# Getting the version is important so that pip prioritises our local dist
python -m pip install build
PACKAGE_VERSION="$( python -c "import build.util; print(build.util.project_wheel_metadata('.').get('Version'))" )"
PACKAGE_VERSION="$(python -c "import build.util; print(build.util.project_wheel_metadata('.').get('Version'))")"

if [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
DIST_LINK_PATH="$( echo "${PWD}/dist" | sed -e 's/^\///' -e 's/\//\\/g' -e 's/^./\0:/' )"
DIST_LINK_PATH="$(echo "${PWD}/dist" | sed -e 's/^\///' -e 's/\//\\/g' -e 's/^./\0:/')"
else
DIST_LINK_PATH="${PWD}/dist"
fi
Expand Down Expand Up @@ -100,15 +121,32 @@ lib::tests::run() {
python ./build_helpers/check-smb.py
fi

python -m pytest \
python_version=$(python -c 'import platform; print(platform.python_version())')
platform=$(python -c 'import platform; print(platform.platform())')

python -m coverage run \
--rcfile=tests/.coveragerc \
-m pytest \
--verbose \
--junitxml junit/test-results.xml \
--cov smbclient \
--cov smbprotocol \
--cov-report xml \
--cov-report term-missing
--junitxml reports/junit/python-${python_version}-${platform}.xml

if [ x"${GITHUB_ACTIONS}" = "xtrue" ]; then
echo "::endgroup::"
fi
}

lib::coverage::erase() {
coverage erase --rcfile=tests/.coveragerc
}

lib::coverage::combine() {
if [ x"${GITHUB_ACTIONS}" = "xtrue" ]; then
echo "::group::Combining coverage"
python -m coverage combine --rcfile=tests/.coveragerc
python -m coverage xml --rcfile=tests/.coveragerc -o reports/coverage/coverage.xml -i
echo "::endgroup::"
else
python -m coverage combine --rcfile=tests/.coveragerc
python -m coverage report --rcfile=tests/.coveragerc -m
fi
}
28 changes: 24 additions & 4 deletions build_helpers/run-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,27 @@ fi

source ./build_helpers/lib.sh

lib::setup::smb_server
lib::setup::python_requirements
lib::sanity::run
lib::tests::run
if [[ "$#" == 0 ]]; then
set "$@" requirements lint tests coverage
fi

while [[ "$#" > 0 ]]; do
case "$1" in
"requirements")
lib::requirements::install
;;
"lint")
lib::sanity::run
;;
"tests")
lib::coverage::erase
lib::server::start
lib::tests::run
lib::server::stop
;;
"coverage")
lib::coverage::combine
;;
esac
shift
done
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ exclude = '''
| \.mypy_cache
| \.tox
| \.venv
| venv
| _build
| buck-out
| build
Expand All @@ -75,7 +76,9 @@ deps =
-r{toxinidir}/requirements-dev.txt

commands =
python -m pytest -v --cov smbclient --cov smbprotocol --cov-report term-missing
python -m coverage run --rcfile=tests/.coveragerc -m pytest -v
python -m coverage combine --rcfile=tests/.coveragerc
python -m coverage report --rcfile=tests/.coveragerc -m

passenv =
SMB_*
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage
black == 23.3.0
build
cryptography >= 2.0
Expand Down
8 changes: 8 additions & 0 deletions tests/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[run]
branch = True
omit = tests/*
parallel = true
data_file = reports/coverage/.coverage
source =
smbprotocol
smbclient
Loading