forked from pupilfirst/pupilfirst
-
Notifications
You must be signed in to change notification settings - Fork 0
172 lines (162 loc) · 5.45 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
name: Continuous Integration
on:
push:
branches: [master]
paths-ignore:
- "docs/**"
pull_request:
branches: [master]
paths-ignore:
- "docs/**"
workflow_dispatch:
env:
PF_IMAGE_NAME: pupilfirst
PF_VERSION: "2024.2"
YARN_CHECKSUM_BEHAVIOR: ignore
jobs:
tests:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"
services:
postgres:
image: postgres:11.7
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
env:
RAILS_ENV: test
RUBYOPT: "-W:no-deprecated -W:no-experimental"
JAVASCRIPT_DRIVER: headless_chrome
DB_HOST: localhost
DB_NAME_TEST: postgres
DB_USERNAME: postgres
DB_PASSWORD: postgres
CAPYBARA_MAX_WAIT_TIME: 5
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
SPEC_USER_TIME_ZONE: Etc/UTC
SPEC_RETRY_COUNT: 2
RECAPTCHA_V3_SITE_KEY: ignored
RECAPTCHA_V3_SECRET_KEY: ignored
RECAPTCHA_V2_SITE_KEY: ignored
RECAPTCHA_V2_SECRET_KEY: ignored
steps:
- name: Install libvips
run: |
sudo apt-get update
sudo apt-get install -y libvips
- uses: actions/checkout@v2
- name: Use Ruby 3.2
uses: ruby/setup-ruby@v1
- name: Set branch name & commit SHA in env
uses: actions/github-script@v3
with:
script: |
console.log(`Event: ${context.eventName}`);
let branchName = "";
if (context.eventName === "push") {
// Pushes have a '/ref/heads/' prefixed to the branch name.
branchName = process.env.GITHUB_REF.replace("refs/heads/", "");
} else {
branchName = process.env.GITHUB_HEAD_REF;
}
console.log(`Setting GIT_BRANCH=${branchName}`);
core.exportVariable("GIT_BRANCH", branchName);
console.log(`Setting GIT_COMMIT_SHA=${context.sha}`);
core.exportVariable("GIT_COMMIT_SHA", context.sha);
- name: Restore Bundle
uses: actions/cache@master
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Bundle
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Rubocop
run: bundle exec rubocop
- name: Setup Database
run: |
bundle exec rake db:schema:load
- name: Restore Lerna
uses: actions/cache@master
with:
path: |
node_modules
app/frontend/packages/*/node_modules
key: ${{ runner.os }}-lerna-${{ hashFiles('**/yarn.lock') }}
- name: Yarn Install
run: yarn install
- name: Generate locales.json
run: bundle exec i18n export
- name: Compile ReScript files
run: yarn run re:build
- name: Specs (On master branch)
if: env.GIT_BRANCH == 'master'
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
COVERAGE=true bundle exec rspec -fd
./cc-test-reporter after-build -t simplecov --exit-code $?
- name: Specs (On non-master branches)
if: env.GIT_BRANCH != 'master'
run: bundle exec rspec -fd
- uses: actions/upload-artifact@v3
if: failure()
with:
name: Logs
path: |
tmp/capybara
log/test.log
dockerhub-master:
needs: tests
environment: Production
name: Build & Push to Dockerhub
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Github Short SHA
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build image
run: docker build . --file Dockerfile --tag $PF_IMAGE_NAME
- name: Push image
run: |
PF_IMAGE_ID=${{ secrets.DOCKER_HUB_USERNAME }}/$PF_IMAGE_NAME
PF_IMAGE_ID=$(echo $PF_IMAGE_ID | tr '[A-Z]' '[a-z]')
echo PF_IMAGE_ID=$PF_IMAGE_ID
echo PF_VERSION=$PF_VERSION
docker tag $PF_IMAGE_NAME $PF_IMAGE_ID:latest
docker tag $PF_IMAGE_NAME $PF_IMAGE_ID:$PF_VERSION
docker tag $PF_IMAGE_NAME $PF_IMAGE_ID:$PF_VERSION.$SHORT_SHA
docker push $PF_IMAGE_ID --all-tags
deploy_to_digital_ocean:
needs: dockerhub-master
name: DigitalOcean App Platform deployment
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
env:
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
steps:
- name: Deploy to DigitalOcean
uses: digitalocean/[email protected]
if: "${{ env.DIGITALOCEAN_ACCESS_TOKEN != '' && vars.ENABLE_AUTO_DEPLOY == 'true' }}"
with:
app_name: pupilfirst
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}