Python tests #887
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 | |
environment: tests | |
strategy: | |
matrix: | |
python-version: ['3.10'] | |
redis-version: [6] | |
opensearch-version: [2.7.0] | |
max-parallel: 1 | |
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 | |
./setup.py install | |
- name: Setup Redis ${{ matrix.redis-version }} | |
uses: supercharge/[email protected] | |
with: | |
redis-version: ${{ matrix.redis-version }} | |
- name: Configure sysctl limits | |
run: | | |
sudo swapoff -a | |
sudo sysctl -w vm.swappiness=1 | |
sudo sysctl -w vm.max_map_count=262144 | |
- name: Setup OpenSearch ${{ matrix.opensearch-version }} | |
uses: ankane/setup-opensearch@v1 | |
with: | |
opensearch-version: ${{ matrix.opensearch-version }} | |
- name: Prepare environment | |
run: | | |
sudo apt-get update -y | |
sudo apt-get install -y pcregrep | |
export VAR=/var/yang | |
export TMP_DIR=$VAR/tmp | |
export TEST_REPO=$TMP_DIR/test/YangModels/yang | |
export BACKEND=$PWD | |
export PYTHONPATH=$PYTHONPATH:$BACKEND | |
export YANGCATALOG_CONFIG_PATH=$BACKEND/tests/resources/test.conf | |
sudo mkdir -p $VAR | |
sudo chown -R $(whoami):$(whoami) $VAR | |
./prepare_environment.sh | |
sed -i "s/yc-redis/localhost/" $BACKEND/tests/resources/test.conf | |
sed -i "s/yc-rabbit/localhost/" $BACKEND/tests/resources/test.conf | |
sed -i "s/username=rabbitmq/username=guest/" $BACKEND/tests/resources/test.conf | |
sed -i "s/rabbitmq-password=rabbitmq/rabbitmq-password=guest/" $BACKEND/tests/resources/test.conf | |
- name: Feed Redis | |
run: | | |
export BACKEND=$PWD | |
export YANGCATALOG_CONFIG_PATH=$BACKEND/tests/resources/test.conf | |
python feed_redis.py | |
- name: RabbitMQ in GitHub Actions | |
uses: Namoshek/[email protected] | |
with: | |
ports: "5672:5672" | |
- name: Test with pytest | |
env: | |
TOKEN: ${{ secrets.TOKEN }} | |
PYANG_PLUGINPATH: $PWD/opensearch_indexing/pyang_plugin | |
run: | | |
export TOKEN | |
export TEST_REPO=/var/yang/tmp/test/YangModels/yang | |
export BACKEND=$PWD | |
export YANGCATALOG_CONFIG_PATH=$BACKEND/tests/resources/test.conf | |
celery -A tests.test_celery_app:celery_app worker -l INFO & | |
coverage run -am pytest | |
coverage xml | |
- name: Coverage report PR | |
if: ${{ github.repository == 'YangCatalog/backend' && 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/backend' && 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 }}\"}" |