-
Notifications
You must be signed in to change notification settings - Fork 2
136 lines (112 loc) · 4.22 KB
/
test.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
136
name: Run Test Suite
on:
pull_request:
branches:
- main
# push:
# branches:
# - main
# - add-ci-tests
jobs:
export_variables:
runs-on: ubuntu-latest
outputs:
primary_image: ${{ steps.compute_container_registry_name.outputs.CR_NAME }}/postgres_primary:${{ steps.calculate_primary_sha.outputs.PRIMARY_SHA }}
replica_image: ${{ steps.compute_container_registry_name.outputs.CR_NAME }}/postgres_replica:${{ steps.calculate_replica_sha.outputs.REPLICA_SHA }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Compute container registry name
id: compute_container_registry_name
run: echo "CR_NAME=$(echo ghcr.io/${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Calculate SHA256 for postgres_primary.dockerfile
id: calculate_primary_sha
run: echo "PRIMARY_SHA=$(sha256sum postgres_primary.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_OUTPUT
- name: Calculate SHA256 for postgres_replica.dockerfile
id: calculate_replica_sha
run: echo "REPLICA_SHA=$(sha256sum postgres_replica.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_OUTPUT
prebuild:
needs: export_variables
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and tag primary Docker image
run: docker build -f postgres_primary.dockerfile -t ${{ needs.export_variables.outputs.primary_image }} .
- name: Build and tag replica Docker image
run: docker build -f postgres_replica.dockerfile -t ${{ needs.export_variables.outputs.replica_image }} .
- name: Push primary Docker image
run: docker push ${{ needs.export_variables.outputs.primary_image }}
- name: Push replica Docker image
run: docker push ${{ needs.export_variables.outputs.replica_image }}
rspec:
needs: [export_variables, prebuild]
runs-on: ubuntu-latest
strategy:
matrix:
# ruby: [3.2.5, 3.3.5]
# rails: ['~> 7.0.0', '~> 7.1.0', '~> 8.0.0']
ruby: [3.2.5]
rails: ['~> 7.0.0']
name: Ruby ${{ matrix.ruby }} / ActiveRecord ${{ matrix.rails }}
services:
postgres_primary:
image: ${{ needs.export_variables.outputs.primary_image }}
ports:
- 5432:5432
env:
POSTGRES_DB: postgres_primary_test
POSTGRES_USER: postgres_primary_test
POSTGRES_PASSWORD: postgres_primary_test
POSTGRES_HOST_AUTH_METHOD: "scram-sha-256\nhost replication all 0.0.0.0/0 md5"
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256"
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres_replica:
image: ${{ needs.export_variables.outputs.replica_image }}
ports:
- 5433:5432
env:
PGUSER: replicator
PGPASSWORD: replicator
PGPORT: 5433
PRIMARY_DATABASE_HOST: postgres_primary
PRIMARY_DATABASE_PORT: 5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
env:
RAILS_VERSION: ${{ matrix.rails }}
run: |
gem install bundler -v 2.5.13
bundle install
- name: Run RSpec tests
env:
PG_PRIMARY_USER: postgres_primary_test
PG_PRIMARY_PASSWORD: postgres_primary_test
PG_PRIMARY_HOST: postgres_primary
PG_PRIMARY_PORT: 5432
PG_REPLICA_USER: postgres_primary_test
PG_REPLICA_PASSWORD: postgres_primary_test
PG_REPLICA_HOST: postgres_replica
PG_REPLICA_PORT: 5433
run: bundle exec rspec --format progress