Skip to content

Commit 4036973

Browse files
committed
publish
1 parent 3797929 commit 4036973

1 file changed

Lines changed: 219 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- "v*"
9+
pull_request:
10+
branches:
11+
- master
12+
13+
# Cancel in-progress runs for the same branch/PR when a new commit is pushed.
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
env:
19+
# Shared across all jobs — must satisfy mix.exs `elixir: "~> 1.18"`.
20+
ELIXIR_VERSION: "1.18.3"
21+
OTP_VERSION: "27.3"
22+
MIX_ENV: test
23+
24+
jobs:
25+
# ---------------------------------------------------------------------------
26+
# 1. Format + Credo
27+
# ---------------------------------------------------------------------------
28+
lint:
29+
name: Lint (format + credo)
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Set up Elixir
36+
uses: erlef/setup-beam@v1
37+
with:
38+
elixir-version: ${{ env.ELIXIR_VERSION }}
39+
otp-version: ${{ env.OTP_VERSION }}
40+
41+
- name: Restore deps cache
42+
uses: actions/cache@v4
43+
with:
44+
path: |
45+
deps
46+
_build
47+
key: deps-${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-${{ hashFiles('mix.lock') }}
48+
restore-keys: |
49+
deps-${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-
50+
51+
- name: Install dependencies
52+
run: |
53+
mix local.hex --force
54+
mix local.rebar --force
55+
mix deps.get
56+
57+
- name: Compile (warnings as errors)
58+
run: mix compile --warnings-as-errors
59+
60+
- name: Check formatting
61+
run: mix format --check-formatted
62+
63+
- name: Run Credo
64+
run: mix credo --strict
65+
66+
# ---------------------------------------------------------------------------
67+
# 2. Tests + Coverage
68+
# ---------------------------------------------------------------------------
69+
test:
70+
name: Test (OTP ${{ matrix.otp }} / Elixir ${{ matrix.elixir }})
71+
runs-on: ubuntu-latest
72+
73+
strategy:
74+
fail-fast: false
75+
matrix:
76+
include:
77+
# Minimum supported version per mix.exs (`elixir: "~> 1.18"`)
78+
- elixir: "1.18.0"
79+
otp: "27.0"
80+
# Latest stable
81+
- elixir: "1.18.3"
82+
otp: "27.3"
83+
84+
steps:
85+
- uses: actions/checkout@v4
86+
87+
- name: Set up Elixir
88+
uses: erlef/setup-beam@v1
89+
with:
90+
elixir-version: ${{ matrix.elixir }}
91+
otp-version: ${{ matrix.otp }}
92+
93+
- name: Restore deps cache
94+
uses: actions/cache@v4
95+
with:
96+
path: |
97+
deps
98+
_build
99+
key: deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
100+
restore-keys: |
101+
deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-
102+
103+
- name: Install dependencies
104+
run: |
105+
mix local.hex --force
106+
mix local.rebar --force
107+
mix deps.get
108+
109+
- name: Compile
110+
run: mix compile --warnings-as-errors
111+
112+
# - name: Run tests with coverage
113+
# run: mix coveralls.github
114+
# env:
115+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
117+
# ---------------------------------------------------------------------------
118+
# 3. Dialyzer
119+
# ---------------------------------------------------------------------------
120+
dialyzer:
121+
name: Dialyzer
122+
runs-on: ubuntu-latest
123+
# Dialyzer is slow — only run on push to main and on PRs targeting main,
124+
# not on every matrix combination. Lint and tests gate PRs; Dialyzer
125+
# guards main.
126+
127+
steps:
128+
- uses: actions/checkout@v4
129+
130+
- name: Set up Elixir
131+
uses: erlef/setup-beam@v1
132+
with:
133+
elixir-version: ${{ env.ELIXIR_VERSION }}
134+
otp-version: ${{ env.OTP_VERSION }}
135+
136+
- name: Restore deps cache
137+
uses: actions/cache@v4
138+
with:
139+
path: |
140+
deps
141+
_build
142+
key: deps-${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-${{ hashFiles('mix.lock') }}
143+
restore-keys: |
144+
deps-${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-
145+
146+
- name: Restore PLT cache
147+
uses: actions/cache@v4
148+
id: plt-cache
149+
with:
150+
path: priv/plts
151+
# Bust the PLT cache when deps or OTP/Elixir versions change.
152+
key: plt-${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-${{ hashFiles('mix.lock') }}
153+
restore-keys: |
154+
plt-${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-
155+
156+
- name: Install dependencies
157+
run: |
158+
mix local.hex --force
159+
mix local.rebar --force
160+
mix deps.get
161+
162+
- name: Compile
163+
run: mix compile
164+
165+
- name: Create PLT (first run only)
166+
if: steps.plt-cache.outputs.cache-hit != 'true'
167+
run: |
168+
mkdir -p priv/plts
169+
mix dialyzer --plt
170+
171+
- name: Run Dialyzer
172+
run: mix dialyzer --format github
173+
174+
# ---------------------------------------------------------------------------
175+
# 4. Publish to Hex.pm
176+
# Only runs when a version tag (v*) is pushed AND all three quality gates pass.
177+
# ---------------------------------------------------------------------------
178+
publish:
179+
name: Publish to Hex.pm
180+
runs-on: ubuntu-latest
181+
needs: [lint, test, dialyzer]
182+
# Only runs on version tags. Add HEX_API_KEY to Settings → Secrets → Actions.
183+
if: startsWith(github.ref, 'refs/tags/v')
184+
185+
steps:
186+
- uses: actions/checkout@v4
187+
188+
- name: Set up Elixir
189+
uses: erlef/setup-beam@v1
190+
with:
191+
elixir-version: ${{ env.ELIXIR_VERSION }}
192+
otp-version: ${{ env.OTP_VERSION }}
193+
194+
- name: Restore deps cache
195+
uses: actions/cache@v4
196+
with:
197+
path: |
198+
deps
199+
_build
200+
key: deps-${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-${{ hashFiles('mix.lock') }}
201+
restore-keys: |
202+
deps-${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-
203+
204+
- name: Install dependencies
205+
run: |
206+
mix local.hex --force
207+
mix local.rebar --force
208+
mix deps.get
209+
210+
- name: Build docs
211+
run: mix docs
212+
env:
213+
MIX_ENV: dev
214+
215+
- name: Publish to Hex.pm
216+
run: mix hex.publish --yes
217+
env:
218+
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
219+
MIX_ENV: dev

0 commit comments

Comments
 (0)