-
Notifications
You must be signed in to change notification settings - Fork 1
176 lines (147 loc) · 4.61 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
name: CI/CD
on:
pull_request:
push:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: ${{ github.ref_name != 'main' }}
jobs:
scan_ruby:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true
- name: Scan for common Rails security vulnerabilities using static analysis
run: bin/brakeman --no-pager
lint:
runs-on: ubuntu-latest
needs: scan_ruby
permissions:
actions: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: "yarn"
- name: Install JavaScript dependencies
run: yarn install --immutable
- name: Restore ESLint cache
uses: actions/cache/restore@v4.1.0
with:
path: .cache/eslint
key: eslint-main-cache
- name: Run ESLint
run: yarn eslint-ci
- name: Remove ESLint cache
if: github.event_name == 'push'
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.event.repository.full_name }}
run: |
gh api --method DELETE /repos/{owner}/{repo}/actions/caches?key=eslint-main-cache ||
echo "ESLint cache not found"
- name: Save ESLint cache
if: github.event_name == 'push'
uses: actions/cache/save@v4.1.0
with:
path: .cache/eslint
key: eslint-main-cache
- name: Restore prettier cache
uses: actions/cache/restore@v4.1.0
with:
path: .cache/prettier
key: prettier-main-cache
- name: Run prettier
run: yarn prettier-ci
- name: Remove prettier cache
if: github.event_name == 'push'
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.event.repository.full_name }}
run: |
gh api --method DELETE /repos/{owner}/{repo}/actions/caches?key=prettier-main-cache ||
echo "Prettier cache not found"
- name: Save prettier cache
if: github.event_name == 'push'
uses: actions/cache/save@v4.1.0
with:
path: .cache/prettier
key: prettier-main-cache
- name: Run RuboCop
run: yarn rubocop-ci
- name: Run Syntax Tree
run: yarn stree
- name: Run Slim-Lint
run: yarn slim-lint
- name: Run zeitwerk check
run: bin/rails zeitwerk:check
test:
runs-on: ubuntu-latest
needs: [scan_ruby, lint]
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Install packages
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y google-chrome-stable curl libjemalloc2 libvips postgresql-client libpq-dev
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true
- name: Precompile assets
run: bin/bundle exec rake assets:precompile
- name: Run tests
env:
RAILS_ENV: test
DATABASE_URL: postgres://postgres:postgres@localhost:5432
CI: true
run: |
bin/rails db:test:prepare
bin/rspec
- name: Keep screenshots from failed system tests
uses: actions/upload-artifact@v4
if: failure()
with:
name: screenshots
path: ${{ github.workspace }}/tmp/capybara
if-no-files-found: ignore
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
needs: [scan_ruby, lint, test]
permissions:
deployments: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to Render
uses: JorgeLNJunior/render-deploy@v1.4.4
with:
service_id: ${{ secrets.RENDER_SERVICE_ID }}
api_key: ${{ secrets.RENDER_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_deployment: true
wait_deploy: true