-
Notifications
You must be signed in to change notification settings - Fork 2
256 lines (222 loc) · 8.14 KB
/
elixir-test.yml
File metadata and controls
256 lines (222 loc) · 8.14 KB
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
# Reusable Elixir Test Workflow
# Usage: uses: agentjido/github-actions/.github/workflows/elixir-test.yml@main
#
# Supports version matrix testing via otp_versions and elixir_versions inputs (JSON arrays)
name: Elixir Test
on:
workflow_call:
inputs:
otp_versions:
description: 'JSON array of OTP versions'
required: false
type: string
default: '["27", "28"]'
elixir_versions:
description: 'JSON array of Elixir versions'
required: false
type: string
default: '["1.18", "1.19"]'
experimental_compile_elixir_versions:
description: 'JSON array of optional exact compile-only Elixir versions that are allowed to fail'
required: false
type: string
default: '[]'
experimental_compile_otp_versions:
description: 'Optional JSON array of OTP versions for experimental compile-only checks; defaults to otp_versions'
required: false
type: string
default: ''
experimental_compile_otp_name:
description: 'Optional display label for experimental compile OTP versions; defaults to the exact OTP version'
required: false
type: string
default: ''
mix_env:
description: 'MIX_ENV for tests'
required: false
type: string
default: 'test'
test_command:
description: 'Command to run tests'
required: false
type: string
default: 'mix test'
postgres:
description: 'Enable PostgreSQL service'
required: false
type: boolean
default: false
postgres_image:
description: 'PostgreSQL Docker image'
required: false
type: string
default: 'postgres:16-alpine'
jobs:
test:
name: ${{ matrix.otp }} - ${{ matrix.elixir }}
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: read
strategy:
fail-fast: false
matrix:
otp: ${{ fromJson(inputs.otp_versions) }}
elixir: ${{ fromJson(inputs.elixir_versions) }}
env:
MIX_ENV: ${{ inputs.mix_env }}
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_db
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Start PostgreSQL
if: ${{ inputs.postgres }}
run: |
docker run -d \
--name postgres \
-e POSTGRES_USER=$POSTGRES_USER \
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
-e POSTGRES_DB=$POSTGRES_DB \
-p $POSTGRES_PORT:5432 \
--health-cmd="pg_isready -U postgres -d test_db" \
--health-interval=5s \
--health-timeout=3s \
--health-retries=20 \
${{ inputs.postgres_image }}
echo "Waiting for PostgreSQL to be ready..."
for i in {1..30}; do
if docker exec postgres pg_isready -U $POSTGRES_USER -d $POSTGRES_DB > /dev/null 2>&1; then
echo "PostgreSQL is ready after ${i}s"
break
fi
if [ $i -eq 30 ]; then
echo "PostgreSQL failed to start within 30 seconds"
docker logs postgres
exit 1
fi
sleep 1
done
- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- name: Restore Hex/Mix cache
uses: actions/cache@v5
with:
path: |
~/.hex
~/.mix
key: ${{ runner.os }}-beamtools-otp${{ matrix.otp }}-elixir${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-beamtools-otp${{ matrix.otp }}-elixir${{ matrix.elixir }}-
- name: Install Hex/Rebar
run: |
set -euo pipefail
mix local.hex --force
mix local.rebar --force
- name: Restore dependencies cache
uses: actions/cache@v5
id: deps-cache
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ inputs.mix_env }}-otp${{ matrix.otp }}-elixir${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
- name: Remove cached rebar3 build artifacts in deps
run: |
if [ -d deps ]; then
find deps -maxdepth 6 -type d \( -name _build -o -name .rebar3 \) -prune -exec rm -rf {} + || true
find deps -maxdepth 6 -type f -name rebar3.crashdump -delete || true
fi
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Compile project
run: mix compile --warnings-as-errors
- name: Setup database
if: ${{ inputs.postgres }}
run: mix ecto.setup
env:
DATABASE_URL: postgres://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.POSTGRES_HOST }}:${{ env.POSTGRES_PORT }}/${{ env.POSTGRES_DB }}
- name: Run tests
run: ${{ inputs.test_command }}
- name: Cleanup PostgreSQL
if: ${{ inputs.postgres && always() }}
run: docker stop postgres && docker rm postgres || true
experimental-compile:
# GitHub check rendering misformats conditional fallback expressions in reusable workflow job names.
name: ${{ matrix.otp }} - ${{ matrix.elixir }} (experimental compile)
if: ${{ inputs.experimental_compile_elixir_versions != '' && inputs.experimental_compile_elixir_versions != '[]' }}
runs-on: ubuntu-24.04
timeout-minutes: 15
continue-on-error: true
permissions:
contents: read
strategy:
fail-fast: false
matrix:
otp: ${{ fromJson(inputs.experimental_compile_otp_versions != '' && inputs.experimental_compile_otp_versions || inputs.otp_versions) }}
elixir: ${{ fromJson(inputs.experimental_compile_elixir_versions) }}
env:
MIX_ENV: ${{ inputs.mix_env }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
version-type: strict
- name: Restore Hex/Mix cache
uses: actions/cache@v5
with:
path: |
~/.hex
~/.mix
key: ${{ runner.os }}-beamtools-otp${{ matrix.otp }}-elixir${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-beamtools-otp${{ matrix.otp }}-elixir${{ matrix.elixir }}-
- name: Install Hex/Rebar
run: |
set -euo pipefail
mix local.hex --force
mix local.rebar --force
- name: Restore dependencies cache
uses: actions/cache@v5
id: deps-cache
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ inputs.mix_env }}-otp${{ matrix.otp }}-elixir${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
- name: Remove cached rebar3 build artifacts in deps
run: |
if [ -d deps ]; then
find deps -maxdepth 6 -type d \( -name _build -o -name .rebar3 \) -prune -exec rm -rf {} + || true
find deps -maxdepth 6 -type f -name rebar3.crashdump -delete || true
fi
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Compile project
run: mix compile --warnings-as-errors
- name: Experimental compile summary
if: always()
env:
EXPERIMENTAL_COMPILE_OTP_NAME: ${{ inputs.experimental_compile_otp_name }}
run: |
echo "### Experimental compile lane" >> "$GITHUB_STEP_SUMMARY"
echo "- Elixir: ${{ matrix.elixir }}" >> "$GITHUB_STEP_SUMMARY"
echo "- OTP: ${{ matrix.otp }}" >> "$GITHUB_STEP_SUMMARY"
if [ -n "$EXPERIMENTAL_COMPILE_OTP_NAME" ]; then
echo "- OTP label: $EXPERIMENTAL_COMPILE_OTP_NAME" >> "$GITHUB_STEP_SUMMARY"
fi
echo "- Blocking: no (job uses continue-on-error)" >> "$GITHUB_STEP_SUMMARY"