-
Notifications
You must be signed in to change notification settings - Fork 3
144 lines (127 loc) · 4.84 KB
/
Copy pathci.yml
File metadata and controls
144 lines (127 loc) · 4.84 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
name: Elixir CI
# Define workflow that runs when changes are pushed to the
# `main` branch or pushed to a PR branch that targets the `main`
# branch.
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Sets the ENV `MIX_ENV` to `test` for running tests
env:
MIX_ENV: test
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
# Specify the OTP and Elixir versions to use when building
# and running the workflow steps.
matrix:
include:
# minimum required versions
- otp: "27.2.4"
elixir: "1.17.3-otp-27"
- otp: "27.2.4"
elixir: "1.18.4-otp-27"
- otp: "28.3.1"
elixir: "1.18.4-otp-28"
- otp: "27.2.4"
elixir: "1.19.5-otp-27"
- otp: "28.3.1"
elixir: "1.19.5-otp-28"
- otp: "28.3.1"
elixir: "1.20.2-otp-28"
- otp: "29.0.1"
elixir: "1.20.2-otp-29"
lint: true
steps:
# Step: Setup Elixir + Erlang image as the base.
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
# Step: Check out the code.
- name: Checkout code
uses: actions/checkout@v5
# Step: Hash the lockfile in a step rather than with `hashFiles()` in a
# cache key. `hashFiles()` is evaluated while the step template is expanded
# and has started failing with "Fail to hash files under directory" even
# though the checkout has already populated the workspace. A step output is
# evaluated when the step runs, so it cannot fail that way.
- name: Hash the lockfile
id: lockfile
run: echo "hash=$(sha256sum mix.lock | cut -d ' ' -f 1)" >> "$GITHUB_OUTPUT"
# Step: Define how to cache deps. Restores existing cache if present.
# Cache keys include the OTP and Elixir versions so matrix entries
# never share BEAMs compiled by a different toolchain.
- name: Cache deps
id: cache-deps
uses: actions/cache@v4
env:
cache-name: cache-elixir-deps
with:
path: deps
key: ${{ runner.os }}-otp${{ matrix.otp }}-elixir${{ matrix.elixir }}-mix-deps-${{ steps.lockfile.outputs.hash }}
restore-keys: |
${{ runner.os }}-otp${{ matrix.otp }}-elixir${{ matrix.elixir }}-mix-deps-
# Step: Define how to cache the `_build` directory. After the first run,
# this speeds up tests runs a lot. This includes not re-compiling our
# project's downloaded deps every run.
- name: Cache compiled build
id: cache-build
uses: actions/cache@v4
env:
cache-name: cache-compiled-build
with:
path: _build
key: ${{ runner.os }}-otp${{ matrix.otp }}-elixir${{ matrix.elixir }}-mix-build-${{ steps.lockfile.outputs.hash }}
restore-keys: |
${{ runner.os }}-otp${{ matrix.otp }}-elixir${{ matrix.elixir }}-mix-build-
# Step: Download project dependencies. If unchanged, uses
# the cached version.
- name: Install dependencies
run: mix deps.get
# Step: Compile the project treating any warnings as errors.
- name: Compiles without warnings
run: mix compile --warnings-as-errors
# Step: Download the segmentation dictionaries the tests rely on.
- name: Download dictionaries
run: mix unicode.string.download.dictionaries
# Step: Check that the checked in code has already been formatted.
- name: Check Formatting
if: ${{ matrix.lint }}
run: mix format --check-formatted
# Step: Static code analysis.
- name: Run credo
if: ${{ matrix.lint }}
run: mix credo --strict
# Step: Execute the tests.
- name: Run tests
if: ${{ !matrix.lint }}
run: mix test
# Step: Execute the tests with coverage measurement on the lint entry.
- name: Run tests with coverage
if: ${{ matrix.lint }}
run: mix test --cover
# Step: Cache the dialyzer PLT. Keyed on the toolchain as well as the
# lockfile, since a PLT is tagged with the BEAM that built it. The
# restore-keys prefix lets a dependency bump reuse the previous PLT and
# update it incrementally rather than building one from scratch.
- name: Restore PLT cache
if: ${{ matrix.lint }}
uses: actions/cache@v4
with:
path: _build/test/dialyxir_*
key: plt-${{ matrix.elixir }}-${{ matrix.otp }}-${{ steps.lockfile.outputs.hash }}
restore-keys: |
plt-${{ matrix.elixir }}-${{ matrix.otp }}-
# Step: Execute dialyzer. Runs on the lint entry only; a single
# analysis per change is sufficient and avoids rebuilding a PLT for
# every toolchain in the matrix.
- name: Run dialyzer
if: ${{ matrix.lint }}
run: mix dialyzer