Adding github action and docs #2
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 Tests | |
on: | |
pull_request: | |
# Run when PR is submitted to main branch | |
branches: [ main ] | |
push: | |
branches: | |
# Run when code is pushed to main branch | |
- main | |
schedule: | |
# Run every weekday at 2am | |
- cron: "0 2 * * 1-5" | |
workflow_dispatch: | |
# Run when manually triggered | |
permissions: | |
actions: read | |
contents: read | |
pull-requests: write | |
jobs: | |
test: | |
name: Unit Tests and Coverage | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/[email protected] | |
- name: Set up Python | |
uses: actions/[email protected] | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install poetry | |
poetry install | |
- name: Run tests | |
run: poetry run pytest | |
- name: Check Coverage | |
run: | | |
poetry run coverage run -m pytest | |
poetry run coverage xml | |
echo "COVERAGE_PERCENT=$(poetry run coverage report --format=total | awk '{print $NF}' | tr -d '%')" >> $GITHUB_ENV | |
- name: Python Coverage | |
uses: orgoro/[email protected] | |
# only if pull request or push | |
if: github.event_name == 'pull_request' | |
with: | |
# local path to a coverage xml file like the output of pytest --cov | |
coverageFile: "coverage.xml" | |
# github token | |
token: ${{ secrets.GITHUB_TOKEN }} | |
# the coverage threshold for average over all files [0,1] | |
thresholdAll: 0.7 | |
- name: Dynamic Badges | |
uses: Schneegans/[email protected] | |
with: | |
# Your secret with the gist scope | |
auth: ${{ secrets.GIST_SECRET }} | |
# The ID of the gist to use | |
gistID: 8e54c78cf86c9b23df72f9f987282266 | |
# The *.json or *.svg filename of the badge data | |
filename: template-python-project-coverage.json | |
# The left text of the badge | |
label: Coverage | |
# The right text of the badge | |
message: ${{ env.COVERAGE_PERCENT }} % | |
valColorRange: ${{ env.COVERAGE_PERCENT }} | |
maxColorRange: 100 | |
minColorRange: 0 | |
forceUpdate: true | |