-
Notifications
You must be signed in to change notification settings - Fork 36
263 lines (215 loc) · 7.4 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: CI
on:
workflow_dispatch:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
release:
types: [published]
env:
REGISTRY: ghcr.io
IMAGE_NAME_RUNTIME: ${{ github.repository }}/runtime
jobs:
test:
name: "Test backpex"
runs-on: ubuntu-latest
strategy:
matrix:
elixir: ["1.17", "1.16"]
erlang: ["27.1", "26.2"]
exclude:
- elixir: "1.16"
erlang: "27.1"
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: erlef/setup-beam@5304e04ea2b355f03681464e683d92e3b2f18451 # v1
with:
otp-version: ${{ matrix.erlang }}
elixir-version: ${{ matrix.elixir }}
- name: Restore the deps and _build cache
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4
id: restore-cache
env:
MIX_LOCK_HASH: ${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.erlang }}-build-deps-mixlockhash-${{ env.MIX_LOCK_HASH }}
restore-keys: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.erlang }}-build-deps-
- name: Install dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
run: mix deps.get
- name: Compile dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
run: mix deps.compile
- name: Run tests
run: mix test
- name: Check formatting
run: mix format --check-formatted
- name: Compile with warnings as errors
run: mix compile --warnings-as-errors --force
- name: Credo
run: mix credo
- name: Sobelow
run: mix sobelow --config
- name: Deps Unused
run: mix deps.unlock --check-unused
- name: Deps Audit
continue-on-error: true
run: mix deps.audit
- name: Gettext Check
run: mix gettext.extract --check-up-to-date
publish:
needs: test
if: github.event_name == 'release'
name: "Publish package on hex.pm"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: erlef/setup-beam@5304e04ea2b355f03681464e683d92e3b2f18451 # v1
id: beam
with:
version-file: .tool-versions
version-type: strict
- name: Install dependencies
run: |
mix local.hex --force --if-missing
mix local.rebar --force --if-missing
mix deps.get
- name: Publish package on hex.pm
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
run: mix hex.publish --yes
test-demo:
name: "Test (Demo)"
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine@sha256:d898b0b78a2627cb4ee63464a14efc9d296884f1b28c841b0ab7d7c42f1fffdf
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- "5432:5432"
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup beam
uses: erlef/setup-beam@5304e04ea2b355f03681464e683d92e3b2f18451 # v1
id: beam
with:
version-file: .tool-versions
version-type: strict
- name: Setup node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
node-version: 20
cache: 'yarn'
cache-dependency-path: demo/yarn.lock
- name: Restore the deps and _build cache
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4
id: restore-cache
env:
OTP_VERSION: ${{ steps.beam.outputs.otp-version }}
ELIXIR_VERSION: ${{ steps.beam.outputs.elixir-version }}
MIX_LOCK_HASH: ${{ hashFiles(format('{0}{1}', github.workspace, '/demo/mix.lock')) }}
with:
path: |
demo/deps
demo/_build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-build-deps-demo-mixlockhash-${{ env.MIX_LOCK_HASH }}
restore-keys: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-build-deps-demo-
- name: Install dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
working-directory: demo
run: mix deps.get
- name: Compile dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
working-directory: demo
run: mix deps.compile
- name: Compile with warnings as errors
working-directory: demo
run: mix compile --warnings-as-errors --force
- name: Install node dependencies
working-directory: demo
run: yarn install --pure-lockfile
- name: lint:mix
working-directory: demo
run: yarn lint:mix
- name: lint:credo
working-directory: demo
run: yarn lint:credo
- name: lint:sobelow
working-directory: demo
run: yarn lint:sobelow
- name: lint:style
working-directory: demo
run: yarn lint:style
- name: lint:standard
working-directory: demo
run: yarn lint:standard
- name: lint:deps-unused
working-directory: demo
run: yarn lint:deps-unused
- name: lint:gettext
working-directory: demo
run: yarn lint:gettext
- name: Run test
working-directory: demo
env:
DB_HOSTNAME: localhost
DB_USERNAME: postgres
DB_PASSWORD: postgres
DB_DATABASE: test
run: yarn test
- name: Deps audit
working-directory: demo
continue-on-error: true
run: mix deps.audit
build-runtime:
name: "Build and push image (Demo)"
runs-on: ubuntu-latest
needs: [test-demo]
if: github.event_name == 'push'
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3
- name: Log in to the container registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_RUNTIME }}
- name: Build container
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME_RUNTIME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME_RUNTIME }}:buildcache,mode=max
target: runtime
build-args: |
MIX_ENV=prod