Skip to content

Commit c459493

Browse files
kfischer-okarinRedmine Patch Meetup
authored andcommitted
Add workflows for unit tests
1 parent 6dd457b commit c459493

File tree

6 files changed

+128
-0
lines changed

6 files changed

+128
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
set -x
4+
5+
bundle install --path vendor/bundle --without minimagick
6+
bundle update
7+
bundle exec rake db:create db:migrate
8+
bundle exec rake test

.github/workflows/test.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- master
7+
- development
8+
9+
jobs:
10+
test-with-mysql:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
ruby: [2.3, 2.4, 2.5, 2.6]
15+
db_version: [5.7]
16+
runs-on: ubuntu-latest
17+
container:
18+
image: ruby:${{ matrix.ruby }}
19+
services:
20+
db:
21+
image: mysql:${{ matrix.db_version }}
22+
env:
23+
MYSQL_ROOT_PASSWORD: password
24+
ports:
25+
- 3306:3306
26+
steps:
27+
- uses: actions/checkout@v2
28+
- name: Config Database for MySQL
29+
run: cp ./config/database.mysql.yml ./config/database.yml
30+
- name: Cache gems
31+
uses: actions/cache@v2
32+
with:
33+
path: vendor/bundle
34+
key: ${{ matrix.ruby }}-mysql-${{ hashFiles('**/Gemfile') }}
35+
restore-keys: |
36+
${{ matrix.ruby }}-mysql-
37+
${{ matrix.ruby }}-
38+
- name: Install & run tests
39+
run: ./.github/actions/install-and-run-tests.sh
40+
env:
41+
DB_HOST: db
42+
test-with-postgres:
43+
strategy:
44+
fail-fast: false
45+
matrix:
46+
ruby: [2.3, 2.4, 2.5, 2.6]
47+
db_version: [9.5]
48+
runs-on: ubuntu-latest
49+
container:
50+
image: ruby:${{ matrix.ruby }}
51+
services:
52+
db:
53+
image: postgres:${{ matrix.db_version }}
54+
env:
55+
LANG: C.UTF-8
56+
POSTGRES_INITDB_ARGS: --locale=C.UTF-8
57+
POSTGRES_PASSWORD: postgres
58+
ports:
59+
- 5432:5432
60+
# needed because the postgres container does not provide a healthcheck
61+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
62+
steps:
63+
- uses: actions/checkout@v2
64+
- name: Config Database for Postgres
65+
run: cp ./config/database.postgres.yml ./config/database.yml
66+
- name: Cache gems
67+
uses: actions/cache@v2
68+
with:
69+
path: vendor/bundle
70+
key: ${{ matrix.ruby }}-postgres-${{ hashFiles('**/Gemfile') }}
71+
restore-keys: |
72+
${{ matrix.ruby }}-postgres-
73+
${{ matrix.ruby }}-
74+
- name: Install & run tests
75+
run: ./.github/actions/install-and-run-tests.sh
76+
env:
77+
DB_HOST: db
78+
test-with-sqlite:
79+
strategy:
80+
fail-fast: false
81+
matrix:
82+
ruby: [2.3, 2.4, 2.5, 2.6]
83+
runs-on: ubuntu-latest
84+
container:
85+
image: ruby:${{ matrix.ruby }}
86+
steps:
87+
- uses: actions/checkout@v2
88+
- name: Config Database for SQLite
89+
run: cp ./config/database.sqlite.yml ./config/database.yml
90+
- name: Cache gems
91+
uses: actions/cache@v2
92+
with:
93+
path: vendor/bundle
94+
key: ${{ matrix.ruby }}-sqlite-${{ hashFiles('**/Gemfile') }}
95+
restore-keys: |
96+
${{ matrix.ruby }}-sqlite-
97+
${{ matrix.ruby }}-
98+
- name: Install & run tests
99+
run: ./.github/actions/install-and-run-tests.sh

config/database.mysql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
default: &default
22
adapter: mysql2
33
host: <%= ENV.fetch('DB_HOST', '127.0.0.1') %>
4+
port: <%= ENV.fetch('DB_PORT', '3306') %>
45
username: root
56
password: password
67

config/database.postgres.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ default: &default
22
adapter: postgresql
33
encoding: utf8
44
host: <%= ENV.fetch('DB_HOST', 'localhost') %>
5+
port: <%= ENV.fetch('DB_PORT', '5432') %>
56
username: postgres
67
password: postgres
78

config/database.sqlite.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Default setup is given for MySQL 5.7.7 or later.
2+
# Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end.
3+
# Line indentation must be 2 spaces (no tabs).
4+
5+
default: &default
6+
adapter: sqlite3
7+
8+
production:
9+
<<: *default
10+
database: db/redmine_production.sqlite3
11+
12+
development:
13+
<<: *default
14+
database: db/redmine_development.sqlite3
15+
16+
test:
17+
<<: *default
18+
database: db/redmine_test.sqlite3

docker-compose.postgres.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
environment:
1010
LANG: C.UTF-8
1111
POSTGRES_INITDB_ARGS: --locale=C.UTF-8
12+
POSTGRES_PASSWORD: postgres
1213

1314
volumes:
1415
postgres_data:

0 commit comments

Comments
 (0)