-
Notifications
You must be signed in to change notification settings - Fork 16
103 lines (85 loc) · 4.33 KB
/
run-unit-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
name: Run CNaaS-NMS unit tests
on:
push:
workflow_dispatch:
pull_request:
jobs:
free-disk-space:
runs-on: ubuntu-latest
steps:
- name: Free Disk Space (Ubuntu)
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: false
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: false
swap-storage: false
docker-tests:
name: "Run unit tests in docker"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "Set environment variables"
run: |
echo "GITREPO_TEMPLATES=git://gitops.sunet.se/cnaas-lab-templates" >> $GITHUB_ENV
echo "GITREPO_SETTINGS=git://gitops.sunet.se/cnaas-lab-settings" >> $GITHUB_ENV
echo "GITREPO_ETC=https://github.com/indy-independence/cnaas-nms-lab-etc.git" >> $GITHUB_ENV
echo "USERNAME_DHCP_BOOT=admin" >> $GITHUB_ENV
echo "PASSWORD_DHCP_BOOT=abc123abc123" >> $GITHUB_ENV
echo "USERNAME_DISCOVERED=admin" >> $GITHUB_ENV
echo "PASSWORD_DISCOVERED=abc123abc123" >> $GITHUB_ENV
echo "USERNAME_INIT=admin" >> $GITHUB_ENV
echo "PASSWORD_INIT=abc123abc123" >> $GITHUB_ENV
echo "USERNAME_MANAGED=admin" >> $GITHUB_ENV
echo "PASSWORD_MANAGED=abc123abc123" >> $GITHUB_ENV
echo "NO_EQUIPMENTTEST=1" >> $GITHUB_ENV
echo "PYTEST_POSTGRES_EXTERNAL=1" >> $GITHUB_ENV
echo "PYTEST_REDIS_EXTERNAL=1" >> $GITHUB_ENV
echo "JWT_AUTH_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJpYXQiOjE1NzEwNTk2MTgsIm5iZiI6MTU3MTA1OTYxOCwianRpIjoiNTQ2MDk2YTUtZTNmOS00NzFlLWE2NTctZWFlYTZkNzA4NmVhIiwic3ViIjoiYWRtaW4iLCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.Sfffg9oZg_Kmoq7Oe8IoTcbuagpP6nuUXOQzqJpgDfqDq_GM_4zGzt7XxByD4G0q8g4gZGHQnV14TpDer2hJXw" >> $GITHUB_ENV
echo "JWT_SECRET_KEY=unittestsharedsecret" >> $GITHUB_ENV
# - name: Create code coverage dir
# run: mkdir -p docker/coverage/
#
- uses: satackey/[email protected]
# Ignore the failure of a step and avoid terminating the job.
continue-on-error: true
- name: Get branch name (merge)
if: github.event_name != 'pull_request'
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Get branch name (pull request)
if: github.event_name == 'pull_request'
shell: bash
run: echo "BRANCH_NAME=pr/$(echo ${GITHUB_REF#refs/pull/} | cut -d '/' -f1)" >> $GITHUB_ENV
- name: Get repo URL
shell: bash
run: echo "CNAAS_REPO=$(echo ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY})" >> $GITHUB_ENV
- name: Print branch name
run: echo ${{ env.BRANCH_NAME }} at ${{ env.CNAAS_REPO }}
- name: Build docker
run: docker-compose -f docker/docker-compose_test.yaml build --build-arg GITREPO_BASE=${{ env.CNAAS_REPO }} --build-arg BUILDBRANCH=${{ env.BRANCH_NAME }}
- name: Start docker
run: docker-compose -f docker/docker-compose_test.yaml up -d
- name: Install API certificates
run: |
docker cp ./docker/jwt-cert/public.pem docker_cnaas_api_1:/opt/cnaas/jwtcert/public.pem
docker-compose -f docker/docker-compose_test.yaml exec -u root -T cnaas_api /bin/chown -R www-data:www-data /opt/cnaas/jwtcert/
docker-compose -f docker/docker-compose_test.yaml exec -u root -T cnaas_api /opt/cnaas/createca.sh
- name: Check running containers
run: docker ps -a
- name: Check API running version
run: curl -ks --connect-timeout 5 --max-time 10 --retry 10 --retry-delay 5 --retry-max-time 120 https://localhost/api/v1.0/system/version
- name: Fix permissions for code coverage
run: docker-compose -f docker/docker-compose_test.yaml exec -u root -T cnaas_api chown -R www-data:www-data /opt/cnaas/venv/cnaas-nms/src/
- name: Run unit tests in container
run: docker-compose -f docker/docker-compose_test.yaml exec -u www-data -T cnaas_api /opt/cnaas/pytest.sh
- name: Check logs
if: always()
run: docker logs docker_cnaas_api_1