Python tests #327
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: 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/[email protected] | |
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/[email protected] | |
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 }}\"}" |