-
Notifications
You must be signed in to change notification settings - Fork 1
103 lines (92 loc) · 3.65 KB
/
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
name: CI and CD
on:
push:
# Allow manual triggering
workflow_dispatch:
jobs:
# Name of the job
rspec-test:
runs-on: ubuntu-latest
env:
MAIL_USERNAME: ${{ secrets.MAIL_USERNAME }}
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }}
# https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers
# Service containers to run with job `test`
services:
postgres:
# Docker Hub image
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_DB: test
# should not be empty
# https://stackoverflow.com/questions/60618118#answer-60618750
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
# Maps tcp port 5432 on service container to the host
ports: ["5432:5432"]
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Setup Ruby and bundle
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.4 # Not needed with a .ruby-version file
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Analyze code statically using Rubocop
run: bundle exec rubocop
- name: Run RSpec tests (PostgreSQL)
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
RAILS_ENV: test
# Don't run RSpec with . https://olivierlacan.com/posts/a-tiny-little-dot/
# Show rspec errors as GH annotations https://github.com/Drieam/rspec-github#usage
# Exclude specs tagged with "local_only"
run: |
cp config/database.ci.yml config/database.yml
bundle exec rails db:setup
bundle exec rspec --tag ~local_only spec/ --tag ~ui --format documentation --format RSpec::Github::Formatter
# Name of the job
deploy:
# Deploy the main branch
if: github.ref == 'refs/heads/main'
# test job must succeed before this job is started
needs: rspec-test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
# https://github.com/marketplace/actions/deploy-to-heroku
- name: Deploy main to Heroku
uses: akhileshns/[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "bookkeeper-red-main" #Must be unique in Heroku
heroku_email: "[email protected]"
# https://github.com/marketplace/actions/deploy-to-heroku#procfile-passing
procfile: |
web: bin/rails server -p ${PORT:-5000} -e $RAILS_ENV
release: bin/rails db:migrate; bin/rails assets:precompile
deploy-dev:
# Deploy the dev branch
if: github.ref == 'refs/heads/dev'
# test job must succeed before this job is started
needs: rspec-test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
# https://github.com/marketplace/actions/deploy-to-heroku
- name: Deploy dev to Heroku
uses: akhileshns/[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "bookkeeper-red-dev" #Must be unique in Heroku
heroku_email: "[email protected]"
# https://github.com/marketplace/actions/deploy-to-heroku#procfile-passing
procfile: |
web: bin/rails server -p ${PORT:-5000} -e $RAILS_ENV
release: bin/rails db:migrate; bin/rails assets:precompile