-
Notifications
You must be signed in to change notification settings - Fork 32
197 lines (194 loc) · 5.92 KB
/
ci.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: CI
on:
workflow_dispatch:
push:
branches:
- master
pull_request:
branches:
- master
types: [opened, reopened, synchronize]
jobs:
static-analysis:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Validate commit message format
uses: wagoid/commitlint-github-action@v4
with:
configFile: './.commitlint.yml'
- name: Setup Ruby and install gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
rubygems: latest
bundler: latest
- name: Rubocop
run: bundle exec rubocop --parallel
- name: Brakeman
run: bundle exec brakeman
- name: ShellCheck
uses: ludeeus/[email protected]
with:
ignore: vendor
check_together: true
development-build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up the environment
run: |
cp .env.example .env
pipx install podman-compose==1.0.6
- name: Build using podman-compose
run: podman-compose build
- name: Build using docker-compose
run: docker compose build
unit-tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: insights
POSTGRES_DB: insights
POSTGRES_PASSWORD: insights
ports: ["5432:5432"]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Ruby and install gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
rubygems: latest
bundler: latest
- name: Setup database
env:
RAILS_ENV: test
ACG_CONFIG: ./github-ci.json
DATABASE_SERVICE_NAME: postgres
POSTGRES_SERVICE_HOST: localhost
POSTGRESQL_USER: insights
POSTGRESQL_PASSWORD: insights
POSTGRESQL_TEST_DATABASE: insights
run: |
bin/rails db:setup;
bundle exec rails db -p < db/cyndi_setup_test.sql;
- name: Run zeitwerk check
env:
RAILS_ENV: test
ACG_CONFIG: ./github-ci.json
DATABASE_SERVICE_NAME: postgres
POSTGRES_SERVICE_HOST: localhost
POSTGRESQL_USER: insights
POSTGRESQL_PASSWORD: insights
POSTGRESQL_TEST_DATABASE: insights
run: bin/rails zeitwerk:check
- name: Validate the OpenAPIv2 schema
env:
RAILS_ENV: test
SWAGGER_DRY_RUN: false
ACG_CONFIG: ./github-ci.json
DATABASE_SERVICE_NAME: postgres
POSTGRES_SERVICE_HOST: localhost
POSTGRESQL_USER: insights
POSTGRESQL_PASSWORD: insights
POSTGRESQL_TEST_DATABASE: insights
SPEC_OPTS: "--color --tty --format documentation"
run: |
bundle exec rails db -p < db/cyndi_setup_test.sql;
cp swagger/v2/openapi.json openapi.old.json
bin/rake rswag:specs:swaggerize
symbols=( '"' '[' '{' )
for symbol in "${symbols[@]}"; do
NEW=$(cat swagger/v2/openapi.json | tr -cd "${symbol}" | wc -c)
OLD=$(cat openapi.old.json | tr -cd "${symbol}" | wc -c)
rm -rf coverage
if [[ "${OLD}" != "${NEW}" ]]; then
echo 'OpenAPI Spec needs to be updated:'
echo '$ bin/rake rswag:specs:swaggerize'
diff -s -u --minimal openapi.old.json swagger/v2/openapi.json
rm openapi.old.json
exit 1
fi
done
diff <(echo 'null') <(curl -s 'https://validator.swagger.io/validator/debug' -H 'accept: application/json' -H 'Content-Type: application/json' -d @openapi.old.json | jq '.schemaValidationMessages')
if [[ $? != 0 ]]; then
rm openapi.old.json
exit 1
fi
rm openapi.old.json
exit 0
- name: Run RSpec tests
env:
HOSTNAME: rails
RAILS_ENV: test
ACG_CONFIG: ./github-ci.json
DATABASE_SERVICE_NAME: postgres
POSTGRES_SERVICE_HOST: localhost
POSTGRESQL_USER: insights
POSTGRESQL_PASSWORD: insights
POSTGRESQL_TEST_DATABASE: insights
SPEC_OPTS: "--color --tty --format documentation"
RUBY_YJIT_ENABLE: 1
run: bin/rake spec
- name: Upload code coverage from RSpec
uses: codecov/[email protected]
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
version: v9.0.4
- name: Run minitest tests
env:
HOSTNAME: rails
RAILS_ENV: test
ACG_CONFIG: ./github-ci.json
DATABASE_SERVICE_NAME: postgres
POSTGRES_SERVICE_HOST: localhost
POSTGRESQL_USER: insights
POSTGRESQL_PASSWORD: insights
POSTGRESQL_TEST_DATABASE: insights
RUBY_YJIT_ENABLE: 1
run: bin/rake test
- name: Upload code coverage from minitest
uses: codecov/[email protected]
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
version: v9.0.4
migration-robustness:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: insights
POSTGRES_DB: insights
POSTGRES_PASSWORD: insights
ports: ["5432:5432"]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Ruby and install gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
rubygems: latest
bundler: latest
- name: Setup database and run migrations
env:
RAILS_ENV: test
ACG_CONFIG: ./github-ci.json
DATABASE_SERVICE_NAME: postgres
POSTGRES_SERVICE_HOST: localhost
POSTGRESQL_USER: insights
POSTGRESQL_PASSWORD: insights
POSTGRESQL_TEST_DATABASE: insights
run: bin/rails db:create db:migrate
- name: Check if migrations altered the schema.rb
run: "! git diff --unified=0 -- db/schema.rb | grep ^+ActiveRecord"