-
Notifications
You must be signed in to change notification settings - Fork 116
160 lines (154 loc) · 5.48 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
name: CI
on:
pull_request:
push:
branches: [main]
env:
RAILS_ENV: test
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
PARALLEL_TEST_FIRST_IS_1: true
jobs:
linters:
name: Linters
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Label PR
if: github.event.pull_request
uses: actions/labeler@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Code Analysis
run: bundle exec rake code:analysis
tests:
name: Tests
permissions:
contents: write
runs-on: ubuntu-latest
timeout-minutes: 20
services:
db:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
fail-fast: false
matrix:
# Set N number of parallel jobs you want to run tests on.
# Use higher number if you have slow tests to split them on more parallel jobs.
# Remember to update ci_node_index below to 0..N-1
ci_node_total: [1]
# set N-1 indexes for parallel jobs
# When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc
ci_node_index: [0]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set ENV for codeclimate (pull_request)
run: |
git fetch --no-tags --prune --depth=1 origin refs/heads/$GITHUB_HEAD_REF:refs/remotes/origin/$GITHUB_HEAD_REF
echo "GIT_BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
echo "GIT_COMMIT_SHA=$(git rev-parse origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV
if: github.event_name == 'pull_request'
- name: Set ENV for api docs
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: echo "OPENAPI=true" >> $GITHUB_ENV
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Setup Code Climate test-reporter
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
- name: Setup Database
run: bundle exec rake parallel:load_schema
- name: Check for untracked changes in schema.rb
uses: rootstrap/check_untracked_changes@v1
with:
path: "./db/schema.rb"
- name: Get CPU info
id: cpu_info
run: echo "cpu_cores=$(nproc)" >> $GITHUB_ENV
- name: Run Tests
env:
KNAPSACK_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
KNAPSACK_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
PARALLEL_TESTS_CONCURRENCY: ${{ env.cpu_cores }}
OPENAPI: ${{ env.OPENAPI }}
run: bundle exec parallel_rspec -n $PARALLEL_TESTS_CONCURRENCY -e './bin/parallel_tests'
- name: Check for missing annotations
run: bundle exec annotate
- name: Check for untracked changes in app and spec directories
uses: rootstrap/check_untracked_changes@v1
with:
path: "./app/ ./spec/"
- name: Report to CodeClimate
run: ./cc-test-reporter format-coverage --output "coverage/coverage.${{ matrix.ci_node_index }}.json"
- name: Upload partial coverage
uses: actions/upload-artifact@v2
with:
name: coverage
path: "coverage/coverage.${{ matrix.ci_node_index }}.json"
- name: Merge API docs
env:
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: bundle exec ./bin/merge-api-docs.rb
- name: Upload partial api docs
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v2
with:
name: api_docs
path: "tmp/openapi${{ matrix.ci_node_index }}.yaml"
merge_results:
name: Merge Results
runs-on: ubuntu-latest
needs: tests
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set ENV for codeclimate (pull_request)
run: |
git fetch --no-tags --prune --depth=1 origin refs/heads/$GITHUB_HEAD_REF:refs/remotes/origin/$GITHUB_HEAD_REF
echo "GIT_BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
echo "GIT_COMMIT_SHA=$(git rev-parse origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: download api docs
uses: actions/download-artifact@v2
with:
name: api_docs
path: tmp/
- name: Merge API docs
env:
MOVE_TMP_FILES: true
run: bundle exec ./bin/merge-api-docs.rb
- name: Commit api docs
run: |
git config --global user.name 'GitHub Bot'
git config --global user.email 'github_bot@users.noreply.github.com'
git add "doc/openapi.yaml"
git commit -m "Update API Docs" || echo "No changes to commit"
git push origin main