-
Notifications
You must be signed in to change notification settings - Fork 1
135 lines (117 loc) · 4.8 KB
/
integration-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
name: Integration Tests
on:
push:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_dispatch
workflow_dispatch:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
permissions:
# NOTE: actions/upload-artifact makes no use of permissions
# See https://github.com/actions/upload-artifact/issues/197#issuecomment-832279436
contents: read # for "git clone"
defaults:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaultsrun
run:
# Enable fail-fast behavior using set -eo pipefail
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
shell: bash
jobs:
run-integration-tests:
name: Integration Tests
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: ubuntu-20.04
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
strategy:
matrix:
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#example-adding-configurations
include:
# "docker-service-name" must match "services.$name" from docker-compose.yaml
# "database-service-name" must match "services.$name" from docker-compose.yaml
# "application-port" must match "services.$name.environment:PORT" from docker-compose.yaml
- docker-service-name: 'express-js'
database-service-name: 'mysql'
application-port: 3010
- docker-service-name: 'express-ts'
database-service-name: 'mysql'
application-port: 3020
- docker-service-name: 'chi'
database-service-name: 'mysql'
application-port: 3030
env:
# Prevent interference between builds by setting the project name to a unique value. Otherwise
# "docker compose down" has been stopping containers (especially database) from other builds.
# https://docs.docker.com/compose/project-name/
# https://docs.docker.com/compose/environment-variables/envvars/#compose_project_name
COMPOSE_PROJECT_NAME: ${{ matrix.docker-service-name }}
steps:
- name: Clone source code
uses: actions/[email protected] # https://github.com/actions/checkout
with:
# Whether to configure the token or SSH key with the local git config. Default: true
persist-credentials: false
- name: Install Hurl
run: |
DEB=hurl_4.2.0_amd64.deb
curl --location --no-progress-meter --remote-name https://github.com/Orange-OpenSource/hurl/releases/download/4.2.0/$DEB
sudo dpkg --install $DEB
- name: Show Hurl version
run: hurl --version
- name: Show docker version
run: docker version
- name: Show docker compose version
run: docker compose version
- name: Create directory for reports
run: mkdir tests-reports
- name: Start containers
working-directory: docker
run: >-
docker --debug compose up \
--build \
--detach \
--wait \
--quiet-pull \
${{ matrix.docker-service-name }}
- name: Show container statuses
if: always()
working-directory: docker
run: docker compose ps
- name: Run integration tests
run: >-
hurl \
--error-format long \
--report-html tests-reports \
--variable SERVER_URL=http://127.0.0.1:${{ matrix.application-port }} \
--test \
tests/crud.hurl
- name: Save application logs
if: failure()
working-directory: docker
run: >-
docker compose logs \
--no-log-prefix \
--timestamps \
${{ matrix.docker-service-name }} | tee ../tests-reports/application-logs.txt
- name: Save database logs
if: failure()
working-directory: docker
run: >-
docker compose logs \
--no-log-prefix \
--timestamps \
${{ matrix.database-service-name }} | tee ../tests-reports/database-logs.txt
- name: Save docker logs
if: failure()
run: journalctl --catalog --unit docker.service | tee tests-reports/docker-logs.txt
- name: Save report
if: failure()
uses: actions/[email protected] # https://github.com/actions/upload-artifact
with:
name: ${{ matrix.docker-service-name }}-report-and-logs
path: tests-reports/
- name: Stop containers
if: always()
working-directory: docker
run: >-
docker compose down \
--volumes \
--remove-orphans \
--rmi local