-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
148 lines (135 loc) · 3.33 KB
/
.gitlab-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
.base-rules:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
- if: '$CI_PIPELINE_SOURCE == "push"'
when: never
- if: $CI_COMMIT_TAG
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
- $RULES_CHANGES_PATH
- when: manual
allow_failure: true
.backend:
extends: .base-rules
variables:
RULES_CHANGES_PATH: "read4share/**/*"
.frontend:
extends: .base-rules
variables:
RULES_CHANGES_PATH: "read4share-frontend/**/*"
stages:
- setup
- build
- test
# - analyze
- deploy
install:
stage: setup
extends: .base-rules
before_script:
- cd `pwd`/read4share-frontend
script:
- npm ci # Install npm dependecies
cache:
untracked: true
policy: push
key: ${CI_COMMIT_SHORT_SHA}
paths:
- node_modules/
backend-build:
stage: build
extends: .backend
needs: ["install"]
before_script:
- cd `pwd`/read4share
- export GRADLE_USER_HOME=.gradle
# Inject variables in application.properties file
- echo "$DB_URL" >> src/main/resources/application.properties
- echo "$DB_USER" >> src/main/resources/application.properties
- echo "$DB_PSW" >> src/main/resources/application.properties
- echo "$JWT_KEY" >> src/main/resources/application.properties
script:
- gradle --build-cache assemble
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
backend-test:
stage: test
extends: .backend
needs: ["backend-build"]
before_script:
- cd `pwd`/read4share
- export GRADLE_USER_HOME=.gradle
# Create application.properties file for tests
- mkdir src/test/resources
- echo "$TEST_CONFIG" >> src/test/resources/application.properties
- echo "$JWT_KEY" >> src/test/resources/application.properties
script:
- echo "Running tests"
- gradle check
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- build
- .gradle
frontend-build:
stage: build
extends: .frontend
needs: ["install"]
before_script:
- cd `pwd`/read4share-frontend
script:
- npm run build --prod
cache:
untracked: true
key: ${CI_COMMIT_SHORT_SHA}
policy: pull
frontend-test:
stage: test
extends: .frontend
needs: ["frontend-build"]
before_script:
- cd `pwd`/read4share-frontend
- export CHROME_BIN=/usr/bin/chromium-browser
script:
- npm run test -- --no-watch --no-progress --browsers=ChromeHeadless
cache:
untracked: true
key: ${CI_COMMIT_SHORT_SHA}
policy: pull
#sonarqube:
# stage: analyze
# script:
# - echo "Running Sonarqube analysis"
# - gradle sonarqube -Dsonar.login="$SONAR_TOKEN"
# allow_failure: true
# only:
# - main # analyze only the main branch
docker-deployment:
stage: deploy
extends: .base-rules
before_script:
- cd `pwd`
# Inject variables in .env_backend file
- echo "$DB_URL" >> .env_backend
- echo "$DB_USER" >> .env_backend
- echo "$DB_PSW" >> .env_backend
- echo "$JWT_KEY" >> .env_backend
# Inject variables in .env_db file
- echo "$PSQL_USER" >> .env_db
- echo "$PSQL_PASSWORD" >> .env_db
- echo "$PSQL_DB" >> .env_db
Build backend jar
- cd `pwd`/read4share
- ./gradlew build -x test
- rm build/libs/*-plain.jar
- cd ..
script:
- echo "Running docker-compose..."
- docker-compose build