-
Notifications
You must be signed in to change notification settings - Fork 11
142 lines (124 loc) · 4.83 KB
/
tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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 }}\"}"