-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (127 loc) · 4.32 KB
/
backend_ci_cd.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
name: Backend CI/CD
on:
push:
paths:
- 'backend/**'
- '.github/workflows/backend*'
workflow_dispatch:
jobs:
tests:
name: Run backend tests
runs-on: ubuntu-20.04
env:
DATABASE_NAME: fora_test
DATABASE_PASSWORD: postgres
DATABASE_USER: postgres
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
RAILS_ENV: test
BACKEND_URL: http://localhost:4000/sub-path/backend
FRONTEND_URL: http://localhost:4000/sub-path
FRONTEND_API_SECRET: SECRET
SECRET_KEY_BASE: SECRET
JWT_SECRET: SECRET
services:
postgres:
image: postgis/postgis:14-master
ports:
- 5432:5432
env:
POSTGRES_USER: ${{ env.DATABASE_USER }}
POSTGRES_PASSWORD: ${{ env.DATABASE_PASSWORD }}
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout️
uses: actions/checkout@v2
- name: Install PostgreSQL client
run: |
sudo apt update
sudo bash -c "echo deb https://apt-archive.postgresql.org/pub/repos/apt bionic-pgdg main >> /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -yqq install libpq-dev postgresql-client-14
- name: Install ruby + gems
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.2
bundler-cache: true
working-directory: backend
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ hashFiles('yarn.lock') }}
working-directory: backend
- name: Install Node Dependencies
if: steps.cache.outputs.cache-hit != 'true'
working-directory: backend
run: yarn install --frozen-lockfile
- name: Setup database
working-directory: backend
run: |
bundle exec rails db:create
bundler exec rails db:schema:load
- name: Run tests
working-directory: backend
run: bundle exec rspec spec --fail-fast
ruby_linter:
name: Run backend rubocop
runs-on: ubuntu-20.04
steps:
- name: Checkout️
uses: actions/checkout@v2
- name: Install ruby + gems
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.2
bundler-cache: true
working-directory: backend
- name: Run RuboCop
working-directory: backend
run: bin/rails standard
security:
name: Run backend security
runs-on: ubuntu-20.04
steps:
- name: Checkout️
uses: actions/checkout@v2
- name: Install ruby + gems
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.2
bundler-cache: true
working-directory: backend
- name: Run Brakeman
working-directory: backend
run: bundle exec brakeman
- name: Run Bundle Audit
working-directory: backend
run: bundle exec bundle-audit check --update
deploy:
name: Deploy backend app
# if: (github.head_ref || github.ref_name) == 'main' || (github.head_ref || github.ref_name) == 'staging'
if: (github.head_ref || github.ref_name) == 'staging'
runs-on: ubuntu-20.04
needs: [ruby_linter, security, tests]
steps:
- name: Checkout code
uses: actions/checkout@v1
- name: Install ruby + gems
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.2
bundler-cache: true
working-directory: backend
- name: Extract branch name
shell: bash
run: |
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
echo "##[set-output name=branch-upper;]$(echo ${GITHUB_REF#refs/heads/} | tr a-z A-Z )"
id: extract_branch
- name: Deploy using capistrano
uses: miloserdow/capistrano-deploy@master
with:
working-directory: backend
target: ${{ steps.extract_branch.outputs.branch == 'main' && 'production' || steps.extract_branch.outputs.branch }}
deploy_key: ${{ secrets.DEPLOY_KEY_PASSWORD }}
enc_rsa_key_val: ${{ secrets.DEPLOY_ENC_KEY }}