-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (137 loc) · 4.2 KB
/
ruby_app_pull_requests.yml
File metadata and controls
137 lines (137 loc) · 4.2 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
name: Pull Request
on:
workflow_call:
inputs:
DATABASE_ADAPTER:
description: 'Database adapter for Postgres/Rails services'
required: true
type: string
default: 'postgresql'
DATABASE_NAME:
description: 'Database name for Postgres/Rails services'
required: true
type: string
default: 'database_test'
DATABASE_USERNAME:
description: 'User for for Postgres/Rails services'
required: true
type: string
default: 'postgres'
DATABASE_HOST:
description: 'Database host for for Postgres/Rails services'
required: true
type: string
default: 'localhost'
SQL_PATH:
description: 'SQL path to import Postgres test step service'
required: true
type: string
default: 'db/structure.sql'
secrets:
DATABASE_PASSWORD:
description: 'Database password for Postgres/Rails services'
required: true
env:
DATABASE_ADAPTER: ${{ inputs.DATABASE_ADAPTER }}
DATABASE_NAME: ${{ inputs.DATABASE_NAME }}
DATABASE_USERNAME: ${{ inputs.DATABASE_USERNAME }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
DATABASE_HOST: ${{ inputs.DATABASE_HOST }}
SQL_PATH: ${{ inputs.SQL_PATH }}
jobs:
commitlint:
#
# ensures commit messages follow conventional commits
#
runs-on: ubuntu-latest
steps:
# checkout the commits to lint.
- uses: actions/checkout@v3
with:
fetch-depth: 0
# setup node, needed to lint commits.
- uses: actions/setup-node@v3
with:
node-version: 18
# Install needed libraries to lint commits.
- run: npm install --save-dev @commitlint/{config-conventional,cli}
# Lint the commits.
- run: npx commitlint --from=${{ github.event.pull_request.base.sha }}
test:
#
# ensure ruby standards and tests pass
#
runs-on: ubuntu-latest
services:
database:
image: postgres:12.3
env:
POSTGRES_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
ports:
- 5432:5432
redis:
image: redis:5.0.7
options: >-
--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 6379:6379
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.6
ports:
- 9200:9200
steps:
# Checkout ruby code to test.
- name: Checkout repo
uses: actions/checkout@v3
# Setup Ruby, by default uses .ruby-version file.
- name: Setup up Ruby
uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
with:
bundler-cache: true
# Install rails libraries.
- name: Install dependencies
run: bundle install
# Create database.
- name: Create database
run: psql -h $DATABASE_HOST -U $DATABASE_USERNAME -c 'CREATE DATABASE "${{ env.DATABASE_NAME }}";'
env:
PGPASSWORD: ${{ secrets.DATABASE_PASSWORD }}
# Setup database.
- name: Prepare test database
run: psql -h $DATABASE_HOST -U $DATABASE_USERNAME -d $DATABASE_NAME < $SQL_PATH
env:
PGPASSWORD: ${{ secrets.DATABASE_PASSWORD }}
- name: Run tests
run: bundle exec rspec spec
docker-build:
#
# ensures the docker image will build without pushing to the registry
# uses the git sha for the most recent commit for the version
#
runs-on: ubuntu-latest
steps:
# Checkout code to build.
- name: Checkout repo
uses: actions/checkout@v3
# Setup docker build arguments.
- name: Docker release meta
id: release
uses: docker/metadata-action@v4
with:
images: |
${{ github.repository }}
tags: |
type=sha
# Setup Docker builder to do build.
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
# Build the app.
- name: Build
uses: docker/build-push-action@v3
with:
push: false
context: .
file: Dockerfile
platforms: linux/amd64
tags: ${{ steps.release.outputs.tags }}