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

add coverage and move test running to separate workflow yml #47

Merged
merged 1 commit into from
Oct 11, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ on:
workflow_dispatch:

jobs:
build-linux:
name: Lint and Test
run_tests:
uses: ./.github/workflows/reusable_run_tests.yml

bump_version:
needs: run_tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: 3.9
Expand Down Expand Up @@ -70,35 +74,12 @@ jobs:
if: ${{ startsWith(github.ref, 'refs/heads/main') }}
env:
CURRENT_VERSION: ${{ steps.get-version.outputs.current_version }}
# True if the version already has a 'rc' pre-release identifier
BUMP_RC: ${{ contains(steps.get-version.outputs.current_version, 'rc') }}
# True if the version already has a 'alpha' pre-release identifier
BUMP_A: ${{ contains(steps.get-version.outputs.current_version, 'a') }}
# True if the version already has a 'beta' pre-release identifier
BUMP_B: ${{ contains(steps.get-version.outputs.current_version, 'b') }}
# Remove rc* from end of version string
# Remove rc* from the end of version string
# The ${string%%substring} syntax below deletes the longest match of $substring from back of $string.
run: |
if [ "$BUMP_RC" = true ]; then
poetry version ${CURRENT_VERSION%%rc*}
elif [ "$BUMP_B" = true ]; then
poetry version ${CURRENT_VERSION%%b*}
elif [ "$BUMP_A" = true ]; then
poetry version ${CURRENT_VERSION%%a*}
fi
poetry version ${CURRENT_VERSION%%rc*}
echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV
echo "venue=ops" >> $GITHUB_ENV

- name: Install ncompare
run: poetry install

- name: Lint
run: |
poetry run ruff ncompare

- name: Test with pytest
run: |
poetry run pytest

- name: Commit Version Bump
# If building develop, a release branch, or main then we commit the version bump back to the repo
Expand Down Expand Up @@ -149,4 +130,4 @@ jobs:
env:
POETRY_PYPI_TOKEN_PYPI: ${{secrets.POETRY_PYPI_TOKEN_PYPI}}
run: |
poetry publish
poetry publish
12 changes: 12 additions & 0 deletions .github/workflows/pull-request-received.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Receive PR

# read-only repo token
# no access to secrets
on:
pull_request:
# Sequence of patterns matched against refs/heads
branches: [ feature/**, issue/**, issues/** ]

jobs:
build_and_test:
uses: ./.github/workflows/reusable_run_tests.yml
37 changes: 0 additions & 37 deletions .github/workflows/pull_request.yml

This file was deleted.

65 changes: 65 additions & 0 deletions .github/workflows/reusable_run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This workflow will install Python dependencies, run tests,
# and report test results and code coverage as artifacts. It will
# be called by the workflow that runs tests against new PRs and as
# a first step in the workflow that publishes new Docker images.

name: A reusable workflow to build and run the unit test suite

on:
workflow_call:
workflow_dispatch:

jobs:
build_and_test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Set up Poetry
uses: abatilo/[email protected]
with:
poetry-version: 1.3.2

- name: Install ncompare
run: poetry install

- name: Lint
run: |
poetry run ruff ncompare

- name: Run tests with coverage
run: |
poetry run coverage run -m pytest >& test_results.txt

- name: Generate coverage report
if: ${{ always() }}
run: |
poetry run coverage report -m >& coverage_report.txt
poetry run coverage html --dir htmlcov

- name: Archive test results
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: test result
path: test_results.txt

- name: Archive code coverage report (plain text)
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: code coverage report (plain text)
path: coverage_report.txt

- name: Archive code coverage report (HTML)
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: code coverage report (HTML)
path: htmlcov/*
80 changes: 72 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pytest = "^7.4.2"
ruff = ">=0.0.291,<0.0.293"
black = "^23.9.1"
mypy = "^1.5.1"
coverage = "^7.3.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down