-
-
Notifications
You must be signed in to change notification settings - Fork 71
180 lines (162 loc) · 4.52 KB
/
ci-cd.yml
File metadata and controls
180 lines (162 loc) · 4.52 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
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
name: ci-cd
on:
push:
branches:
- develop
pull_request:
branches:
- develop
env:
RAILS_ENV: test
permissions:
actions: write
contents: read
issues: read
pull-requests: read
jobs:
erb_lint:
name: ERB checking
runs-on: ubuntu-latest
strategy:
matrix:
ruby_version: [3.1, 3.2]
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -yqq libmagickwand-dev
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- run: bundle exec erb_lint --lint-all
rubocop:
name: Rubocop checking
runs-on: ubuntu-latest
strategy:
matrix:
ruby_version: [3.1, 3.2]
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -yqq libmagickwand-dev
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- run: bundle exec rubocop
typescript:
name: TypeScript type checking
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v1
with:
node-version: 22
- run: npm install
- run: tsc
tests:
name: Ruby on Rails tests
runs-on: ubuntu-latest
needs:
- erb_lint
- rubocop
- typescript
strategy:
matrix:
ruby_version: [3.1, 3.2]
test_type: [test, test:system]
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_HOST: '%'
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_DATABASE: 'qpixel_test'
ports:
- 3306:3306
redis:
image: redis:8.0
ports:
- 6379:6379
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup dependencies
run: |
sudo apt-get -qq update
sudo apt-get -yqq install libmariadb-dev libmagickwand-dev
- name: Setup Firefox
if: ${{ matrix.test_type == 'test:system' }}
uses: browser-actions/setup-firefox@v1.5.4
- name: Check Firefox setup
if: ${{ matrix.test_type == 'test:system' }}
run: firefox --version
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- name: Prepare for testing
run: |
cp config/database.sample.yml config/database.yml
cp config/storage.sample.yml config/storage.yml
bundle exec rails db:create
bundle exec rails db:schema:load
bundle exec rails db:migrate
bundle exec rails test:prepare
- run: bundle exec rails ${{ matrix.test_type }}
- name: Upload screenshots
if: ${{ matrix.test_type == 'test:system' }}
uses: actions/upload-artifact@v4
with:
name: screenshots-${{ matrix.ruby_version }}
path: tmp/screenshots
if-no-files-found: ignore
- uses: codecov/codecov-action@v5
if: ${{ matrix.ruby_version == 3.2 && matrix.test_type == 'test' && github.actor != 'dependabot[bot]' }}
with:
directory: coverage
fail_ci_if_error: true
report_type: coverage
token: ${{ secrets.CODECOV_TOKEN }}
deploy:
name: Dev server deployment
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' && github.actor != 'dependabot[bot]' }}
needs:
- erb_lint
- rubocop
- typescript
- tests
env:
SSH_IP: ${{ secrets.DEV_SSH_IP }}
SSH_KEY: ${{ secrets.DEV_SSH_KEY }}
SSH_PORT: ${{ secrets.DEV_SSH_PORT }}
SSH_USER: ${{ secrets.DEV_SSH_USER }}
steps:
- name: Check SSH version
run: ssh -V
- name: Import key
run: |
mkdir -p ~/.ssh
echo "$SSH_KEY" > ~/.ssh/deploy.key
chmod 0700 ~/.ssh/deploy.key
- name: Deploy
run: |
ssh -o 'StrictHostKeyChecking no' \
-o 'KbdInteractiveAuthentication no' \
-o 'PasswordAuthentication no' \
-p "$SSH_PORT" \
-i ~/.ssh/deploy.key \
"$SSH_USER"@"$SSH_IP" \
"sudo su -l qpixel /var/apps/deploy-dev"