-
Notifications
You must be signed in to change notification settings - Fork 11
213 lines (205 loc) · 7.63 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: CI
on: push
jobs:
changes:
name: Filter jobs based on changes
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.filter.outputs.backend }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
backend:
- 'rails/**'
- if: steps.changes.outputs.backend == 'true'
run: echo ${{ steps.changes.outputs.backend }}
test:
name: Run tests
runs-on: ubuntu-latest
#if: ${{ needs.changes.outputs.backend == 'true' }}
strategy:
matrix:
include:
- test_suite: spec_without_webdriver
env: test
- test_suite: spec_with_webdriver
env: test
- test_suite: cucumber_without_javascript
env: cucumber
- test_suite: cucumber_javascript
env: cucumber
- test_suite: cucumber_search
env: cucumber
services:
# Label used to access the service container
database:
image: mariadb:10.10
ports:
- 3306:3306 # Map TCP port from service container to runner host
env:
MARIADB_USER: actions
MARIADB_PASSWORD: password123
MARIADB_ROOT_PASSWORD: password123
MARIADB_DATABASE: ${{ github.event.repository.name }}_test
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: yes # Allow the container to be started with a blank password for the root user
solr:
image: concordconsortium/docker-solr-portal
ports:
- 8981:8983
env:
TEST_SOLR_PORT: 8981
env:
RAILS_ENV: ${{ matrix.env }}
CHROMEDRIVER_VERSION: '114.0.5735.90'
defaults:
run:
working-directory: ./rails/
steps:
- uses: actions/checkout@v3
- name: Print $RAILS_ENV
run: echo $RAILS_ENV
- uses: ruby/setup-ruby@v1
name: Setup Ruby
with:
bundler-cache: true # use Actions cache to significantly speed up subsequent runs
working-directory: ./rails/
- uses: actions/setup-node@v4
with:
node-version: '18.18.0'
# Install ChromeDriver (wiping out whatever version was previously installed on Actions Runner)
- name: Install ChromeDriver
uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: ${{ env.CHROMEDRIVER_VERSION }}
# Remove existing Google Chrome as ChromeDriver will default to it (setup-chrome installs under /opt/hostedtoolcache/setup-chrome/)
- name: Remove Existing Google Chrome (so ChromeDriver doesn't use it instead of manually installed version)
run: sudo apt-get remove google-chrome-stable
# Install Google Chrome browser (that matches ChromeDriver version from previous Actions step)
- name: Install Google Chrome
id: install-chrome
uses: browser-actions/setup-chrome@v1
with:
chrome-version: ${{ env.CHROMEDRIVER_VERSION }}
- run: cp -v ./config/database.github_actions.yml ./config/database.yml
- run: cp -v ./config/app_environment_variables.sample.rb ./config/app_environment_variables.rb
- run: cp -v ./config/settings.sample.yml ./config/settings.yml
# See: https://github.com/concord-consortium/rigse/blob/master/rails/script/travis_before_script#L17-L20
- run: bundle exec rake db:create
env:
RAILS_ENV: test
- run: bundle exec rake db:create
env:
RAILS_ENV: cucumber
- run: bundle exec rake db:schema:load
- run: bundle exec rake db:migrate
- run: bundle exec rake db:test:prepare
- run: bundle exec rake db:feature_test:prepare
- run: bundle exec rake app:setup:create_default_data
env:
RAILS_ENV: cucumber
- name: Install react-components dependencies
working-directory: ./rails/react-components/
run: npm ci
- name: Build react-components (before assets:precompile!)
working-directory: ./rails/react-components/
run: npm run build
- run: bundle exec rake assets:precompile
name: Precompile assets
env:
RAILS_GROUPS: assets
- run: bundle exec rake ci:${{ matrix.test_suite }}
name: Run Rake ci:${{ matrix.test_suite }} task
test-react-components:
name: Run react-components tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./rails/react-components/
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: '18.18.0'
- name: Install react-components dependencies
working-directory: ./rails/react-components/
run: npm ci
- name: Lint react-components
working-directory: ./rails/react-components/
run: npm run lint
- name: Build react-components
working-directory: ./rails/react-components/
run: npm run build
- name: Test react-components
working-directory: ./rails/react-components/
run: npm run test
build:
name: Build Docker image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# See: https://github.com/docker/login-action#github-container-registry
- name: Login to GitHub Container Registry (GHCR)
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
## See: https://github.com/docker/login-action#docker-hub
#- name: Login to Docker Hub
# uses: docker/login-action@v2
# if: ${{ secrets.DOCKER_HUB_USERNAME != '' && secrets.DOCKER_HUB_TOKEN != '' && env.DOCKER_HUB_IMAGE }}
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Extract metadata for Docker image tagging
id: docker_metadata
uses: docker/metadata-action@v4
with:
images: |-
${{ env.REGISTRY }}/${{ github.repository }}
# "refs/tags/v1.2.3" --> "1.2.3" (drop "v" prefix just like official Docker Hub images)
tags: |-
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=pr
type=sha,prefix=git-
- name: Build & push Docker image
uses: docker/build-push-action@v4
with:
#context: '{{defaultContext}}:rails'
context: ./rails/
push: ${{ env.ACT != 'true' }} # Don't attempt to publish a GitHub package when running Actions locally using "act"
# Use GitHub Actions cache (see https://docs.docker.com/build/building/cache/backends/gha/#using-dockerbuild-push-action)
cache-from: type=gha
cache-to: type=gha,mode=max
labels: ${{ steps.docker_metadata.outputs.labels }}
tags: ${{ steps.docker_metadata.outputs.tags }}
build-args: |-
CC_PORTAL_VERSION=${{ github.ref_name }}
deploy:
name: Deploy application
needs: build
runs-on: ubuntu-latest
if: false
steps:
- name: Deploy to AWS CloudFormation
uses: aws-actions/aws-cloudformation-github-deploy@6901756
with:
name: learn-ecs-staging
template: ./configs/cloudformation/stack_template.yml
parameter-overrides: >-
PortalDockerImage=TODO,