-
Notifications
You must be signed in to change notification settings - Fork 2
160 lines (128 loc) · 4.67 KB
/
pipeline.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: Rails boilerplate CI/CD Pipeline
# This workflow is triggered on pushes to the repository
on: push
env:
RUBY_VERSION: 3.1.2
NODE_VERSION: 18.8.0
PGHOST: localhost
PGUSER: postgres
RAILS_ENV: test
REDIS_HOST: localhost
REDIS_PORT: 6379
jobs:
ci:
runs-on: ubuntu-latest
# Service containers to run with container-job
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:11.5
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis
ports: ['6379:6379']
options: --entrypoint redis-server
steps:
# Downloads a copy of the code in your repository before running CI tests
- uses: actions/checkout@v3
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{env.NODE_VERSION}}
# Note: It is not recommended to cache node_modules, as it can break across Node versions and won't work with npm ci
- name: Cache node_modules
uses: actions/cache@v3
with:
path: node_modules
key: yarn-packages-{{ checksum "yarn.lock" }}
restore-keys: yarn-packages-
# installation and build then run test
- name: Install yarn packages
run: yarn install
- name: Build test env
run: |
gem install bundler
bundle install --jobs=4 --retry=3 --path vendor/bundle
bundle exec rails db:create
bundle exec rails db:migrate
- name: Run backend test
id: rspec
run: bundle exec rspec
continue-on-error: true
- name: Set message if success
if: steps.rspec.outcome == 'success'
run: echo "ci_message=Success" >> $GITHUB_ENV
- name: Set message if code backend fail
if: steps.rspec.outcome == 'failure'
run: echo "ci_message= Some test in backend fail" >> $GITHUB_ENV
- name: send telegram message on push
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
${{ github.actor }} created commit:
Commit message: ${{ github.event.commits[0].message }}
CI state: ${{ env.ci_message }}
Repository: ${{ github.repository }}
See changes: https://github.com/${{ github.repository }}/commit/${{github.sha}}
# Break CI pipeline when error occur
- name: Exit if fail
if: steps.rspec.outcome == 'failure' || steps.jest.outcome == 'failure'
run: exit 1
cd:
runs-on: ubuntu-latest
needs: ci
if: github.ref == 'refs/heads/develop' && success()
steps:
- uses: actions/checkout@v3
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- name: Setup file
run: |
echo ${{ secrets.MASTER_KEY }} > config/master.key
# scan all keyscan in github
- name: Setup known_hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Bundle install
run: bundle install --jobs=4 --retry=3 --path vendor/bundle
# More information, please visit here: https://github.com/marketplace/actions/capistrano-deploy
- name: Cap production deploy
uses: miloserdow/capistrano-deploy@master
with:
target: production
deploy_key: ${{ secrets.PASSWORD }}
enc_rsa_key_val: ${{ secrets.ENC_RSA_KEY_VAL }}
# Set message env for success or failure
- if: success()
run: echo "message=Congratulations on your successful release for staging" >> $GITHUB_ENV
- if: failure()
run: echo "message=Deploy failed, Please try again or deploy manually" >> $GITHUB_ENV
# Noti to slack for success or failure
- name: send telegram message on deploy
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
${{ github.actor }} created commit:
Commit message: ${{ github.event.commits[0].message }}
Repository: ${{ github.repository }}
CD State: ${{ env.message }}
See changes: https://github.com/${{ github.repository }}/commit/${{github.sha}}