Skip to content

Commit 6003e01

Browse files
committed
ci: port running of integration tests with MySQL from TravisCI to GitHub Actions
Part of #1154
1 parent b1fa791 commit 6003e01

File tree

6 files changed

+97
-152
lines changed

6 files changed

+97
-152
lines changed

Diff for: .github/workflows/integration-tests-mysql.yml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Integration Tests (MySQL)
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
8+
permissions:
9+
# NOTE: actions/upload-artifact makes no use of permissions
10+
# See https://github.com/actions/upload-artifact/issues/197#issuecomment-832279436
11+
contents: read # for "git clone"
12+
13+
defaults:
14+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaultsrun
15+
run:
16+
# Enable fail-fast behavior using set -eo pipefail
17+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
18+
shell: bash
19+
20+
jobs:
21+
run-integration-tests:
22+
name: Integration Tests
23+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on
24+
runs-on: ubuntu-20.04
25+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idservices
26+
services:
27+
db:
28+
# https://hub.docker.com/_/mysql
29+
# https://github.com/docker-library/mysql/blob/429047ac5e28d59d40a2ac84a189c9d25310f060/5.7/Dockerfile
30+
# NOTE: it's better to have the same as in infra/docker/postgres.yml
31+
image: mysql:5.7.20
32+
env:
33+
# NOTE: it's better to have credentials the same as in infra/docker/prod.yml and src/main/resources/application-travis.properties
34+
# the generated root password will be printed to stdout (GENERATED ROOT PASSWORD: ...)
35+
MYSQL_RANDOM_ROOT_PASSWORD: 'true'
36+
MYSQL_USER: mystamps
37+
MYSQL_PASSWORD: secret
38+
# the user specified above will be granted superuser access automatically
39+
MYSQL_DATABASE: mystamps
40+
options: >-
41+
--health-cmd "mysqladmin ping --user mystamps --password=secret"
42+
--health-start-period 1s
43+
--health-interval 1s
44+
--health-retries 10
45+
--health-timeout 5s
46+
# https://docs.github.com/en/actions/using-containerized-services/about-service-containers#mapping-docker-host-and-service-container-ports
47+
ports:
48+
# <host port>:<container port>
49+
- '3306:3306'
50+
steps:
51+
- name: Clone source code
52+
uses: actions/[email protected] # https://github.com/actions/checkout
53+
with:
54+
# Whether to configure the token or SSH key with the local git config. Default: true
55+
persist-credentials: false
56+
- name: Install JDK
57+
uses: actions/[email protected] # https://github.com/actions/setup-java
58+
with:
59+
distribution: 'adopt' # https://github.com/actions/setup-java#supported-distributions
60+
java-version: '8' # https://github.com/actions/setup-java#supported-version-syntax
61+
cache: 'maven' # https://github.com/actions/setup-java#caching-packages-dependencies
62+
# This is a workaround for github action limitation: we can't specify command for the service (--character-set-server=utf8)
63+
# and have to modify database manually. See also:
64+
# https://github.com/actions/runner/discussions/1872 and https://github.com/orgs/community/discussions/26688
65+
# @todo #1154 Set charset of MySQL container by providing a custom my.cnf
66+
- name: Change character set on database
67+
run: >-
68+
docker exec ${{ job.services.db.id }} \
69+
mysql \
70+
--user mystamps \
71+
--password=secret \
72+
--execute 'ALTER DATABASE mystamps CHARACTER SET utf8'
73+
- name: Run integration tests
74+
env:
75+
SPRING_PROFILES_ACTIVE: travis
76+
run: |
77+
mkdir -p /tmp/uploads /tmp/preview
78+
cp src/main/resources/test/test.png /tmp/uploads/1.png
79+
./src/main/scripts/execute-command.sh integration-tests
80+
- name: Save RobotFramework reports
81+
if: ${{ failure() }}
82+
uses: actions/[email protected] # https://github.com/actions/upload-artifact
83+
with:
84+
name: robotframework-reports
85+
path: target/robotframework-reports/

Diff for: .travis.yml

+4-40
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ dist: xenial
22
language: java
33

44
env:
5-
matrix:
6-
- SPRING_PROFILES_ACTIVE=travis
75
global:
86
- MAVEN_OPTS='-Xss256k'
97
- secure: "fBav56BzY+A+Vs1g9YSfo1oLDCO1rFrXl49lJkOA5/XpnsKEEs4lI2RcOzz0wiJKXFNgcliiAJWoYMI8Esqz+lkyFWan4ij5Co0UzJcytDuY+2o+jaqwx45DuDYPogABzT+hWjLCxQLLG46gUkChzT8kcvOOn6JxC7Ff8q5MnoM="
@@ -12,45 +10,14 @@ env:
1210
# See https://travis-ci.community/t/log-are-truncated-when-my-script-exits-abnormally/5878
1311
before_script:
1412
- trap 'travis_terminate 1' ERR;
15-
if [ "$SPRING_PROFILES_ACTIVE" = 'travis' ]; then
16-
mysql -u root -e 'CREATE DATABASE mystamps CHARACTER SET utf8;';
17-
mkdir -p /tmp/uploads /tmp/preview;
18-
cp src/main/resources/test/test.png /tmp/uploads/1.png;
19-
pip install --user ansible==2.9.27;
20-
fi
21-
22-
script:
23-
- if [ "$SPRING_PROFILES_ACTIVE" = 'travis' ]; then
24-
./src/main/scripts/ci/check-build-and-verify.sh;
25-
fi
26-
# Travis CI may miss a part of the huge output if we'll exit immediately
27-
# See: https://github.com/travis-ci/travis-ci/issues/6018
28-
- sleep 5
29-
30-
after_failure:
31-
# In order to be able debug robot framework test flakes we need to have a report.
32-
# We encode it to a bzipped binary form and dump to console. It can be
33-
# examined later with the following commands:
34-
#
35-
# $ curl -sS https://api.travis-ci.com/v3/job/$JOB_ID/log.txt | sed -n '/^===== REPORT START/,/^===== REPORT END/p' | sed -e 1d -e '$d' -e 's/\r$//' | base64 -d | bzip2 -dc >target/robotframework-reports/output.xml
36-
# $ ./mvnw robotframework:rebot
37-
# $ open target/robotframework-reports/report.html
38-
#
39-
# NB: on macOS, replace base64 -d by base64 -D
40-
#
41-
- if fgrep -qs 'status="FAIL"' target/robotframework-reports/output.xml; then
42-
echo '===== REPORT START =====';
43-
bzip2 <target/robotframework-reports/output.xml | base64;
44-
echo '===== REPORT END =====';
45-
sleep 5;
46-
fi
13+
pip install --user ansible==2.9.27;
4714

4815
deploy:
4916
provider: script
5017
script: ./src/main/scripts/ci/deploy.sh
5118
on:
5219
branch: prod
53-
condition: '"$SPRING_PROFILES_ACTIVE" = "travis" && "$TRAVIS_PULL_REQUEST" = "false"'
20+
condition: '"$TRAVIS_PULL_REQUEST" = "false"'
5421
skip_cleanup: true
5522

5623
jdk:
@@ -60,12 +27,9 @@ cache:
6027
directories:
6128
- $HOME/.m2
6229

63-
services:
64-
- mysql
65-
6630
branches:
67-
except:
68-
- /^(re|old)_.*$/
31+
only:
32+
- prod
6933

7034
notifications:
7135
email:

Diff for: docs/external-dependencies.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
| ------- | ------------------------ | ----------------------------- | ---------------------------------------- |
55
| OS | Ubuntu 16.04.07 (Xenial) | Ubuntu 20.04.5 (Focal Fossa) | |
66
| JDK | OracleJDK 8u151 | Adopt OpenJDK 8u292 | OpenJDK 8u121-jre on Debian 8.11 (Jessy) |
7-
| MySQL | 5.7.27 | | 5.7.20 on Debian 8.11 (Jessy) |
7+
| MySQL | 5.7.27 | 5.7.20 on Debian 8.11 (Jessy) | 5.7.20 on Debian 8.11 (Jessy) |
88
| PostgreSQL | | 11.3 on Debian 9.13 (Stretch) | 11.3 on Debian 9.13 (Stretch) |
99
| Python | 2.7.12, 3.5.2 | 3.8.10 | |
1010
| bash | 4.3.14 | | |

Diff for: infra/docker/prod.yml

+3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ services:
2727
db:
2828
# https://hub.docker.com/_/mysql
2929
# https://github.com/docker-library/mysql/blob/429047ac5e28d59d40a2ac84a189c9d25310f060/5.7/Dockerfile
30+
# NOTE: it's better to have the same as in .github/workflows/integration-tests-mysql.yml
3031
image: mysql:5.7.20
3132
command: --character-set-server=utf8
3233
environment:
34+
# NOTE: it's better to have credentials the same as in .github/workflows/integration-tests-mysql.yml
35+
# and src/main/resources/application-travis.properties
3336
# the generated root password will be printed to stdout (GENERATED ROOT PASSWORD: ...)
3437
- MYSQL_RANDOM_ROOT_PASSWORD=true
3538
- MYSQL_USER=mystamps

Diff for: src/main/resources/application-travis.properties

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
spring.profiles: travis
2+
# @todo #1154 Rename profile "travis" to "mysql"
23

3-
# Details about MySQL configuration on Travis CI: https://docs.travis-ci.com/user/database-setup/#mysql
4+
# NOTE: it's better to have credentials the same as in infra/docker/prod.yml and .github/workflows/integration-tests-mysql.yml
45
spring.datasource.url: jdbc:mysql://localhost:3306/mystamps?logger=com.mysql.jdbc.log.Slf4JLogger&useSSL=false&logSlowQueries=true&slowQueryThresholdMillis=250&autoSlowLog=false&explainSlowQueries=true&characterEncoding=UTF-8
5-
spring.datasource.username: travis
6-
spring.datasource.password:
6+
spring.datasource.username: mystamps
7+
spring.datasource.password: secret
78
spring.datasource.driver-class-name: com.mysql.jdbc.Driver
89
spring.datasource.initialization-mode: NEVER
910

Diff for: src/main/scripts/ci/check-build-and-verify.sh

-108
This file was deleted.

0 commit comments

Comments
 (0)