Skip to content

Python tests

Python tests #319

Workflow file for this run

name: Python tests
on:
workflow_run:
workflows: [ 'Linting' ]
types:
- completed
jobs:
build:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.10']
redis-version: [6]
environment: tests
steps:
- name: Get PR information
uses: potiuk/get-workflow-origin@v1_5
if: ${{ github.event.workflow_run.event == 'pull_request' }}
id: source-run-info
with:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
- uses: actions/checkout@v3
if: ${{ github.event.workflow_run.event == 'pull_request' }}
with:
ref: ${{ steps.source-run-info.outputs.mergeCommitSha }}
- uses: actions/checkout@v3
if: ${{ github.event.workflow_run.event != 'pull_request' }}
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
requirements.txt
tests_requirements.txt
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r tests_requirements.txt
cd resources/HTML
python setup.py install
- name: Setup Redis ${{ matrix.redis-version }}
uses: supercharge/redis-github-action@1.4.0
with:
redis-version: ${{ matrix.redis-version }}
- name: Test with pytest
run: |
export PYTHONPATH="$PWD":$PYTHONPATH
export VIRTUAL_ENV="$PWD"
export TESTS_RESOURCES_DIR="$PWD"/tests/resources
export YANGCATALOG_CONFIG_PATH="$TESTS_RESOURCES_DIR"/test.conf
sed -i "s|<TESTS_RESOURCES_DIR>|${TESTS_RESOURCES_DIR}|g" "$YANGCATALOG_CONFIG_PATH"
coverage run -am pytest
coverage xml
- name: Coverage report PR
if: ${{ github.repository == 'YangCatalog/module-compilation' && github.event.workflow_run.event == 'pull_request' }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
override_commit: ${{ steps.source-run-info.outputs.mergeCommitSha }}
override_pr: ${{ steps.source-run-info.outputs.pullRequestNumber }}
files: ./coverage.xml
fail_ci_if_error: true
verbose: true
- name: Coverage report
if: ${{ github.repository == 'YangCatalog/module-compilation' && github.event.workflow_run.event != 'pull_request'}}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
fail_ci_if_error: true
verbose: true
- uses: LouisBrunner/checks-action@v1.5.0
if: always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ github.event.workflow_run.head_sha }}
name: Tests
conclusion: ${{ job.status }}
output: "{\"summary\":\"Workflow run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}"