testing #84
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
name: run pre commit tests | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest] | |
python-version: ['3.9'] | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v3 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: black | |
uses: psf/black@stable | |
with: | |
version: "22.6.0" | |
options: "--check --extend-exclude tests/escript/scripts/" | |
- name: Setup env | |
run: | | |
python -m pip install --upgrade pip | |
pip install virtualenv | |
- name: Install requirements | |
run: | | |
make dev | |
- name: Set environment variables | |
shell: bash | |
run: | | |
value="MOCK" | |
echo "CALM_DSL_TESTS=$value" >> $GITHUB_ENV | |
- name: Build test environment | |
run: | | |
source venv/bin/activate | |
cd tests/mock && make mock-db-location && make mock-db | |
- name: Run Tests and Calculate Coverage | |
id: pytest | |
run: | | |
source venv/bin/activate | |
echo -e "\npython_files = tests/unit/*" >> pytest.ini | |
echo -e "filterwarnings = ignore::DeprecationWarning" >> pytest.ini | |
set +e | |
pytest -m pre_commit > logs.txt | |
exit_code=$? | |
echo "PYTEST_EXIT_CODE=$exit_code" >> $GITHUB_ENV | |
set -e | |
coverage_percentage=$(coverage report -m | awk '/TOTAL/ {print $6}') | |
echo "COVERAGE_PERCENTAGE=$coverage_percentage" >> $GITHUB_ENV | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-logs | |
path: logs.txt | |
retention-days: 5 | |
- name: Check threshold coverage | |
run: | | |
if [ $PYTEST_EXIT_CODE -ne 0 ]; then | |
echo "Pytest failed check test-logs for details." | |
exit 1 | |
fi | |
coverage=$(echo "$COVERAGE_PERCENTAGE" | sed 's/%//') | |
if [ "$coverage" -lt 10 ]; then | |
echo "Code coverage is below the threshold (10%). Blocking PR." | |
exit 1 | |
fi | |
env: | |
CI: true |