-
Notifications
You must be signed in to change notification settings - Fork 260
178 lines (156 loc) · 6.02 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: "Tests"
on:
push:
branches:
- master
- 'release/**'
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- master
- 'release/**'
env:
CACHE_NAME_PREFIX: v1
jobs:
run_pytest:
name: Run pytest
needs: calculate_matrix
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix: ${{fromJSON(needs.calculate_matrix.outputs.matrix)}}
env:
LOG_DIR: pytest_logs
collect_analytics: false
TEST_WITH_CPU: ${{ matrix.ml_backend == 'segment_anything_model' }}
steps:
- uses: hmarr/debug-action@v2.1.0
- name: Free Disk Space
if: matrix.ml_backend == 'mmdetection-3'
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: true
android: false
dotnet: false
haskell: false
large-packages: false
docker-images: false
swap-storage: false
- name: Extract branch name on direct push to a branch
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/')
run: |
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
- name: Extract branch name on 'pull_request'
if: github.event_name == 'pull_request'
run: |
echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v3
with:
ref: "${{ env.GITHUB_SHA }}"
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.7'
- uses: actions/cache@v3
name: Configure pip cache
id: pip-cache
with:
path: ~/.cache/pip
key: ${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-test.txt') }}
restore-keys: |
${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-pip-
- name: Install dependencies
run: |
sudo apt-get clean
sudo apt-get update
sudo apt-get install virtualenv libsasl2-dev python3-dev libldap2-dev libssl-dev
pip install -U pip==20.2
pip install -r requirements-test.txt
pip install -r requirements.txt
pip install -e .
- name: Check pytest version
run: pytest --version
- name: Build the stack
env:
DOCKER_BUILDKIT: 1
run: docker-compose -f label_studio_ml/examples/${{ matrix.ml_backend }}/docker-compose.yml up -d
- name: Wait for stack
timeout-minutes: 10
run: |
while [ "$(curl -s -o /dev/null -L -w ''%{http_code}'' "http://localhost:9090/health")" != "200" ]; do
echo "=> Waiting for service to become available" && sleep 2s
done
- name: Run general functional tests
run: |
cd label_studio_ml/
pytest --ignore-glob='**/logs/*' --ignore-glob='**/data/*' --cov=. --cov-report=xml
- name: Pull the logs
if: always()
env:
DOCKER_BUILDKIT: 1
run: docker-compose -f label_studio_ml/examples/${{ matrix.ml_backend }}/docker-compose.yml logs
- name: "Upload cloud coverage to Codecov"
uses: codecov/codecov-action@v3.1.4
with:
name: codecov
files: ./label_studio_ml/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
calculate_matrix:
name: "Calculate test matrix"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: hmarr/debug-action@v2.1.0
- name: Extract branch name on direct push to a branch
if: github.event_name == 'push'
run: |
echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
echo "BASE_BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
echo "BASE_REF_NAME=${{ github.sha }}^" >> $GITHUB_ENV
- name: Extract branch name on 'pull_request'
if: github.event_name == 'pull_request'
run: |
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
echo "BASE_BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
echo "BASE_REF_NAME=${{ github.event.pull_request.base.sha }}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v3
with:
ref: "${{ env.GITHUB_SHA }}"
fetch-depth: 0
- name: Build matrix
id: set-matrix
shell: bash
env:
BASE_REF_NAME: ${{ env.BASE_REF_NAME }}
run: |
set -xuo pipefail
set +e
CHANGED=$(git diff --name-only HEAD.."${BASE_REF_NAME}" -- label_studio_ml/ | xargs -L1 dirname | uniq | cut -d'/' -f2-)
CHANGED_EXAMPLES=$(echo "$CHANGED" | grep examples )
set -e
ALL_EXAMPLES=$(ls -1d label_studio_ml/examples/*/ | cut -d'/' -f3- | cut -d'/' -f1)
if [[ $GITHUB_REF == 'refs/heads/master' || $GITHUB_REF =~ ^refs/heads/release/.* ]]; then
echo "All in matrix because we are on master or a release branch"
echo "matrix={\"ml_backend\":[$(echo "$ALL_EXAMPLES" | xargs | sed -e 's/ /\",\"/g' -e 's/^/\"/' -e 's/$/\"/')]}" >> $GITHUB_OUTPUT
elif [[ $(echo "$CHANGED" | grep -c -v ^$) == $(echo "$CHANGED_EXAMPLES" | grep -c -v ^$) ]]; then
echo "Finding examples to test"
if [[ $(echo "$CHANGED" | grep -c -v ^$) == 0 ]]; then
echo "matrix={\"ml_backend\":[]}" >> $GITHUB_OUTPUT
else
echo "matrix={\"ml_backend\":[$(echo "$CHANGED_EXAMPLES" | cut -d'/' -f2- | xargs | sed -e 's/ /\",\"/g' -e 's/^/\"/' -e 's/$/\"/')]}" >> $GITHUB_OUTPUT
fi
else
echo "All in matrix"
echo "matrix={\"ml_backend\":[$(echo "$ALL_EXAMPLES" | xargs | sed -e 's/ /\",\"/g' -e 's/^/\"/' -e 's/$/\"/')]}" >> $GITHUB_OUTPUT
fi