-
Notifications
You must be signed in to change notification settings - Fork 5
/
.gitlab-ci.yml
161 lines (148 loc) · 3.36 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
image: registry.gitlab.com/soapbox-pub/rebased/ci
variables: &global_variables
POSTGRES_DB: pleroma_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
DB_HOST: postgres
DB_PORT: 5432
MIX_ENV: test
# Needed for Dokku deployment.
# https://github.com/dokku/dokku/issues/2514#issuecomment-616775470
GIT_DEPTH: 0
cache: &cache
key:
files:
- mix.lock
paths:
- deps
- _build
policy: pull
stages:
- deps
- test
- deploy
deps:
stage: deps
script:
- mix deps.get
- mix deps.compile
cache:
<<: *cache
policy: pull-push
only:
changes:
- mix.lock
openapi:
stage: test
only:
changes:
- ".gitlab-ci.yml"
- "lib/pleroma/web/api_spec/**/*.ex"
- "lib/pleroma/web/api_spec.ex"
artifacts:
paths:
- spec.json
script:
- mix pleroma.openapi_spec spec.json
test:
stage: test
only:
changes: &elixir-changes
- ".gitlab-ci.yml"
- "**/*.ex"
- "**/*.exs"
- "mix.lock"
services: &db-services
- name: postgres:13-alpine
alias: postgres
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
before_script: &db-setup
- mix ecto.create
- mix ecto.migrate
script:
- mix test --cover --preload-modules
coverage: '/^Line total: ([^ ]*%)$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
test-erratic:
stage: test
allow_failure: true
only:
changes: *elixir-changes
services: *db-services
before_script: *db-setup
script:
- mix test --only=erratic
lint:
stage: test
only:
changes: *elixir-changes
script:
- mix format --check-formatted
# analysis:
# stage: test
# only:
# changes: *elixir-changes
# script:
# - mix credo --strict --only=warnings,todo,fixme,consistency,readability
cycles:
stage: test
only:
changes: *elixir-changes
script:
- mix xref graph --format cycles --label compile | awk '{print $0} END{exit ($0 != "No cycles found")}'
# Deploy with Dokku
# https://github.com/dokku/gitlab-ci
# https://github.com/dokku/ci-docker-image
review:
image: dokku/ci-docker-image
stage: test
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://rebased-$CI_COMMIT_REF_SLUG.dokku.soapbox.pub
only:
- branches
except:
- develop
variables:
GIT_REMOTE_URL: ssh://dokku@$DOKKU_HOST/rebased-$CI_COMMIT_REF_SLUG
GIT_PUSH_FLAGS: --force
script: dokku-deploy
allow_failure: true
release:
stage: deploy
variables:
MIX_ENV: prod
PLEROMA_BUILD_BRANCH: $CI_COMMIT_REF_NAME
script:
- mix deps.get
- mkdir release
- mix release --path release
artifacts:
name: "rebased-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
paths:
- release/*
cache: {}
only:
refs:
- develop
changes: *elixir-changes
docker:
stage: deploy
image: docker:20.10.17
cache: {}
services:
- docker:20.10.17-dind
tags:
- dind
# https://medium.com/devops-with-valentine/how-to-build-a-docker-image-and-push-it-to-the-gitlab-container-registry-from-a-gitlab-ci-pipeline-acac0d1f26df
script:
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- docker build -t $CI_REGISTRY_IMAGE .
- docker push $CI_REGISTRY_IMAGE
only:
refs:
- develop