forked from irishchessunion/icu_www_app
-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (96 loc) · 3.27 KB
/
Copy pathci.yml
File metadata and controls
112 lines (96 loc) · 3.27 KB
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
name: CI
on:
pull_request:
branches:
- '**'
jobs:
test:
name: Run Tests (Rails ${{ matrix.rails_version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- rails_version: "7.1"
gemfile: "Gemfile"
- rails_version: "7.2"
gemfile: "Gemfile.next"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Copy example config files
run: |
cp config/examples/secrets.yml config/secrets.yml
cp config/examples/database-docker.yml config/database.yml
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.rails_version }}-${{ hashFiles('**/Gemfile.lock', '**/Gemfile.next.lock') }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.rails_version }}-
${{ runner.os }}-buildx-
- name: Build Docker images
run: |
docker compose build --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg BUNDLE_GEMFILE=${{ matrix.gemfile }}
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
- name: Start services
run: |
docker compose up -d db redis
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
- name: Wait for database to be ready
run: |
echo "Waiting for database to be ready..."
for i in {1..30}; do
if docker compose exec -T db mysqladmin ping -h localhost --silent; then
echo "Database is ready!"
break
fi
echo "Waiting for database... ($i/30)"
sleep 2
done
- name: Wait for Redis to be ready
run: |
echo "Waiting for Redis to be ready..."
for i in {1..30}; do
if docker compose exec -T redis redis-cli ping | grep -q PONG; then
echo "Redis is ready!"
break
fi
echo "Waiting for Redis... ($i/30)"
sleep 2
done
- name: Create and prepare test database
run: |
docker compose run --rm -e RAILS_ENV=test -e BUNDLE_GEMFILE=${{ matrix.gemfile }} web bin/rails db:create db:test:prepare
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
- name: Run RSpec tests
run: |
docker compose run --rm -e RAILS_ENV=test -e BUNDLE_GEMFILE=${{ matrix.gemfile }} web bundle exec rspec --format progress
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
- name: Show test logs on failure
if: failure()
run: |
echo "=== Database service logs ==="
docker compose logs db
echo "=== Redis service logs ==="
docker compose logs redis
- name: Upload test screenshots
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-screenshots-rails-${{ matrix.rails_version }}
path: tmp/screenshots/
if-no-files-found: ignore
- name: Cleanup
if: always()
run: |
docker compose down -v