-
Notifications
You must be signed in to change notification settings - Fork 4
156 lines (129 loc) · 5.34 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
# CI setup for Packrat
#
# Lints and Tests code for pull requests
# Builds after tests pass on push/merge to master or develop branch
name: CI
on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup node version
uses: actions/setup-node@v3
with:
node-version: 18.9.0
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Install E2E dependencies
run: cd e2e && yarn install --frozen-lockfile && cd ..
- name: Check for lint errors
run: yarn lint
test:
runs-on: ubuntu-latest
services:
# MariaDB service for test database
mariadb:
image: mariadb:10.5
env:
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: Packrat
ports:
- "3306:3306"
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup test DB
run: mysql -h 127.0.0.1 -v -P 3306 -u root --password=test -e 'CREATE DATABASE IF NOT EXISTS Packrat'
- name: Setup test DB Schema
run: mysql -h 127.0.0.1 -v -P 3306 -u root --password=test --database=Packrat < server/db/sql/scripts/Packrat.SCHEMA.sql
- name: Setup test DB Proc
run: mysql -h 127.0.0.1 -v -P 3306 -u root --password=test --database=Packrat < server/db/sql/scripts/Packrat.PROC.sql
- name: Setup test DB Data
run: mysql -h 127.0.0.1 -v -P 3306 -u root --password=test --database=Packrat < server/db/sql/scripts/Packrat.DATA.sql
- name: Setup node version
uses: actions/setup-node@v3
with:
node-version: 18.9.0
- name: Install git
run: sudo apt-add-repository ppa:git-core/ppa && sudo apt-get update && sudo apt-get install git
# Install dependencies in CI mode
- name: Install dependencies
run: yarn install --frozen-lockfile
# Install E2E dependencies in CI mode
- name: Install E2E dependencies
run: cd e2e && yarn install --frozen-lockfile && cd ..
# Run tests using test DB
- name: Run Tests
run: yarn test
env:
PACKRAT_EDAN_AUTH_KEY: ${{ secrets.PACKRAT_EDAN_AUTH_KEY }}
PACKRAT_DATABASE_URL: mysql://root:[email protected]:3306/Packrat
build:
# Only run this step on pull_request or push to specified branches (PR merge counts as push too)
if: ${{github.event_name == 'pull_request' || github.event_name == 'push'}}
runs-on: ubuntu-latest
needs: test
env: # Ideally this will be stored in github secrets and will be accessed via ${{ secrets.* }}
PACKRAT_PROXY_PORT: 80
PACKRAT_CLIENT_PORT: 3000
PACKRAT_SERVER_PORT: 4000
PACKRAT_DB_PORT: 3306
MYSQL_ROOT_PASSWORD: packrat
REACT_APP_PACKRAT_SERVER_ENDPOINT: http://packrat-server
PACKRAT_SOLR_PORT: 8983
PACKRAT_SOLR_HOST: packrat-solr
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get current package version
id: packrat-version
uses: martinbeentjes/[email protected]
# Runs commands pre-build
# Ideally .env will be created from secrets ${{ secrets.DEV/PROD_ENV }} > .env
- name: Prepare build
run: touch .env.dev && touch .env.prod
- name: Build Dev images
if: ${{!contains(github.ref, 'master')}}
run: docker-compose --env-file .env.dev -f ./conf/docker/docker-compose.dev.yml build
- name: Build Prod images
if: contains(github.ref, 'master')
run: docker-compose --env-file .env.prod -f ./conf/docker/docker-compose.prod.yml build
# Prepares tag for docker images
- name: Prepare image tag
id: prepare-tag
if: ${{contains(github.ref, 'develop') || contains(github.ref, 'master')}}
run: |
if [ ${{ contains(github.ref, 'master') }} = true ]; then stage="prod"; else stage="dev"; fi
version=${{ steps.packrat-version.outputs.current-version }}
commit=${GITHUB_SHA:0:7}
echo "::set-output name=tag::$stage-$version-$commit"
# Tags images with "stage-env-version-commit-sha" eg. dev-1.0.0-abcd123
- name: Tag images
if: ${{contains(github.ref, 'develop') || contains(github.ref, 'master')}}
run: |
echo Tagging with ${{ steps.prepare-tag.outputs.tag }}
docker tag packrat-server:latest packrat-server:${{ steps.prepare-tag.outputs.tag }}
docker tag packrat-client:latest packrat-client:${{ steps.prepare-tag.outputs.tag }}
docker tag packrat-proxy:latest packrat-proxy:${{ steps.prepare-tag.outputs.tag }}
# Runs commands post-build
- name: Build cleanup
if: ${{contains(github.ref, 'develop') || contains(github.ref, 'master')}}
run: |
echo Cleaning up redundant tags
docker rmi packrat-server:latest packrat-client:latest packrat-proxy:latest
docker images
# Pushes built images to container registry
- name: Push images
if: ${{contains(github.ref, 'develop') || contains(github.ref, 'master')}}
run: echo Pushing images to container registry...