Skip to content

Commit 53da43d

Browse files
kfischer-okarinRedmine Patch Meetup
authored and
Redmine Patch Meetup
committed
Add workflows for unit tests
1 parent fe67890 commit 53da43d

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

.github/actions/test-with-db.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
database=$1
6+
7+
cp ./config/database.$database.yml ./config/database.yml
8+
bundle install --path vendor/bundle --without minimagick
9+
bundle update
10+
bundle exec rake db:create db:migrate
11+
bundle exec rake test

.github/workflows/test.yml

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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: Cache gems
29+
uses: actions/cache@v2
30+
with:
31+
path: vendor/bundle
32+
key: ${{ matrix.ruby }}-mysql-${{ hashFiles('**/Gemfile') }}
33+
restore-keys: |
34+
${{ matrix.ruby }}-mysql-
35+
${{ matrix.ruby }}-
36+
- name: Install & run tests
37+
run: ./.github/actions/test-with-db.sh mysql
38+
env:
39+
DB_HOST: db
40+
test-with-postgres:
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
ruby: [2.3, 2.4, 2.5, 2.6]
45+
db_version: [9.5]
46+
runs-on: ubuntu-latest
47+
container:
48+
image: ruby:${{ matrix.ruby }}
49+
services:
50+
db:
51+
image: postgres:${{ matrix.db_version }}
52+
env:
53+
LANG: C.UTF-8
54+
POSTGRES_INITDB_ARGS: --locale=C.UTF-8
55+
POSTGRES_PASSWORD: postgres
56+
ports:
57+
- 5432:5432
58+
# needed because the postgres container does not provide a healthcheck
59+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
60+
steps:
61+
- uses: actions/checkout@v2
62+
- name: Cache gems
63+
uses: actions/cache@v2
64+
with:
65+
path: vendor/bundle
66+
key: ${{ matrix.ruby }}-postgres-${{ hashFiles('**/Gemfile') }}
67+
restore-keys: |
68+
${{ matrix.ruby }}-postgres-
69+
${{ matrix.ruby }}-
70+
- name: Install & run tests
71+
run: ./.github/actions/test-with-db.sh postgres
72+
env:
73+
DB_HOST: db
74+
test-with-sqlite:
75+
strategy:
76+
fail-fast: false
77+
matrix:
78+
ruby: [2.3, 2.4, 2.5, 2.6]
79+
runs-on: ubuntu-latest
80+
container:
81+
image: ruby:${{ matrix.ruby }}
82+
steps:
83+
- uses: actions/checkout@v2
84+
- name: Cache gems
85+
uses: actions/cache@v2
86+
with:
87+
path: vendor/bundle
88+
key: ${{ matrix.ruby }}-sqlite-${{ hashFiles('**/Gemfile') }}
89+
restore-keys: |
90+
${{ matrix.ruby }}-sqlite-
91+
${{ matrix.ruby }}-
92+
- name: Install & run tests
93+
run: ./.github/actions/test-with-db.sh sqlite

config/database.sqlite.yml

+18
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

0 commit comments

Comments
 (0)