Skip to content

Commit 01923eb

Browse files
authored
Add GHA CI (#158)
Adds linting and tests to CI along with adding the changelog to docs, and the changes below. * Fix doc redefinition * Fix formatting * Fix missing backtick
1 parent 2790a45 commit 01923eb

File tree

6 files changed

+126
-24
lines changed

6 files changed

+126
-24
lines changed

.github/workflows/ci.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Linting & Tests
2+
3+
# Define workflow that runs when changes are pushed to the
4+
# `master` branch or pushed to a PR branch that targets the `master`
5+
# branch.
6+
on:
7+
push:
8+
branches: [ "master" ]
9+
pull_request:
10+
branches: [ "master" ]
11+
12+
# Sets the ENV `MIX_ENV` to `test` for running tests
13+
env:
14+
MIX_ENV: test
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
test:
21+
runs-on: ubuntu-22.04
22+
name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
23+
strategy:
24+
# Specify the OTP and Elixir versions to use when building
25+
# and running the workflow steps.
26+
matrix:
27+
otp: ['25.0.4', '27.2'] # Define the OTP version [required]
28+
elixir: ['1.14.1', '1.18.4'] # Define the elixir version [required]
29+
exclude:
30+
- otp: '27.2'
31+
elixir: '1.14.1'
32+
steps:
33+
# Step: Setup Elixir + Erlang image as the base.
34+
- name: Set up Elixir
35+
uses: erlef/setup-beam@v1
36+
with:
37+
otp-version: ${{matrix.otp}}
38+
elixir-version: ${{matrix.elixir}}
39+
40+
# Step: Check out the code.
41+
- name: Checkout code
42+
uses: actions/checkout@v4
43+
44+
# Step: Define how to cache deps. Restores existing cache if present.
45+
- name: Cache deps
46+
id: cache-deps
47+
uses: actions/cache@v4
48+
env:
49+
cache-name: cache-elixir-deps
50+
with:
51+
path: deps
52+
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
53+
restore-keys: |
54+
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ env.cache-name }}
55+
56+
# Step: Define how to cache the `_build` directory. After the first run,
57+
# this speeds up test runs. This includes not re-compiling our deps every run.
58+
- name: Cache compiled build
59+
id: cache-build
60+
uses: actions/cache@v4
61+
env:
62+
cache-name: cache-compiled-build
63+
with:
64+
path: _build
65+
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
66+
restore-keys: |
67+
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ env.cache-name }}-
68+
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-
69+
70+
# Step: Conditionally bust the cache when job is re-run.
71+
# Sometimes, we may have issues with incremental builds that are fixed by
72+
# doing a full recompile. In order to not waste dev time on such trivial
73+
# issues (while also reaping the time savings of incremental builds for
74+
# *most* day-to-day development), force a full recompile only on builds
75+
# that are retried.
76+
- name: Clean to rule out incremental build as a source of flakiness
77+
if: github.run_attempt != '1'
78+
run: |
79+
mix deps.clean --all
80+
mix clean
81+
shell: sh
82+
83+
# Step: Download project dependencies. If unchanged, uses
84+
# the cached version.
85+
- name: Install dependencies
86+
run: mix deps.get
87+
88+
# Step: Compile the project treating any warnings as errors.
89+
# Customize this step if a different behavior is desired.
90+
- name: Compiles without warnings
91+
run: mix compile --warnings-as-errors
92+
93+
# Step: Check that the checked in code has already been formatted.
94+
# This step fails if something was found unformatted.
95+
# Customize this step as desired.
96+
- name: Check Formatting
97+
run: mix format --check-formatted
98+
99+
# Step: Execute the tests.
100+
- name: Run tests
101+
run: mix test

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
# 1.28.0
22

3+
### Enhancements
4+
35
* Allow `auto_start_producers` and `allow_topic_auto_creation` to be configurable for brod clients. If configuration of either of these values is desired, update your producer or consumer configs.
46

7+
* Configures CI to run on pull request.
8+
9+
### Fixes
10+
11+
* Stops compiler warnings on duplicate doc definitions
12+
* Fix doc formatting and typos
13+
514
# 1.27.2
615

716
* Relax `:retry` requirement

lib/kaffe/config/consumer.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ defmodule Kaffe.Config.Consumer do
6464
option, [`auto.offset.reset`](https://kafka.apache.org/documentation/#newconsumerconfigs). Valid values for
6565
this option are:
6666
67-
* `:reset_to_earliest` Reset to the earliest available offset.
68-
* `:reset_to_latest` Reset to the latest offset.
69-
* `:reset_by_subscriber` The subscriber receives the `OffsetOutOfRange` error.
67+
* `:reset_to_earliest` Reset to the earliest available offset.
68+
* `:reset_to_latest` Reset to the latest offset.
69+
* `:reset_by_subscriber` The subscriber receives the `OffsetOutOfRange` error.
7070
7171
More information in the [Brod consumer](https://github.com/klarna/brod/blob/master/src/brod_consumer.erl).
7272
7373
* `:worker_allocation_strategy` Controls how workers are allocated with respect to consumed topics and partitions.
7474
75-
* `:worker_per_partition` The default (for backward compatibilty) and allocates a single worker per partition
75+
* `:worker_per_partition` The default (for backward compatibilty) and allocates a single worker per partition
7676
across topics. This is useful for managing concurrent processing of messages that may be received from any
7777
consumed topic.
7878
79-
* `:worker_per_topic_partition` This strategy allocates a worker per topic partition. This means there will be
79+
* `:worker_per_topic_partition` This strategy allocates a worker per topic partition. This means there will be
8080
a worker for every topic partition consumed. Unless you need to control concurrency across topics, you should
8181
use this strategy.
8282
"""

lib/kaffe/config/producer.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ defmodule Kaffe.Config.Producer do
3333
* -1: If it is -1 the broker will block until the message is committed by all in sync replicas before acking.
3434
3535
* `:ack_timeout` Maximum time in milliseconds the broker can await the receipt of the number of
36-
acknowledgements in `required_acks'. The timeout is not an exact limit on the request time. Defaults to 1000.
36+
acknowledgements in `required_acks`. The timeout is not an exact limit on the request time. Defaults to 1000.
3737
See `brod` for more details.
3838
3939
* `:partition_buffer_limit` How many requests (per-partition) can be buffered without blocking the caller.

lib/kaffe/producer.ex

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ defmodule Kaffe.Producer do
6161
6262
`messages` must be a list of type `message()` or `message_object()`
6363
64+
Alternatively, synchronously produce the given `key`/`value` to the first Kafka topic.
65+
66+
This is a simpler way to produce if you've only given Producer a single topic
67+
for production and don't want to specify the topic for each call.
68+
6469
Returns:
6570
6671
* `:ok` on successfully producing each message
@@ -70,17 +75,6 @@ defmodule Kaffe.Producer do
7075
produce_list(topic, message_list, global_partition_strategy())
7176
end
7277

73-
@doc """
74-
Synchronously produce the given `key`/`value` to the first Kafka topic.
75-
76-
This is a simpler way to produce if you've only given Producer a single topic
77-
for production and don't want to specify the topic for each call.
78-
79-
Returns:
80-
81-
* `:ok` on successfully producing the message
82-
* `{:error, reason}` for any error
83-
"""
8478
def produce_sync(key, value) do
8579
topic = config().topics |> List.first()
8680
produce_value(topic, key, value)
@@ -89,7 +83,9 @@ defmodule Kaffe.Producer do
8983
@doc """
9084
Synchronously produce the `message_list` to `topic`/`partition`
9185
92-
`message_list` must be a list of type `message()` or `message_type()`
86+
`message_list` must be a list of type `message()` or `message_object()`
87+
88+
Alternatively, synchronously produce the `key`/`value` to `topic`
9389
9490
Returns:
9591
@@ -100,11 +96,6 @@ defmodule Kaffe.Producer do
10096
produce_list(topic, message_list, fn _, _, _, _ -> partition end)
10197
end
10298

103-
@doc """
104-
Synchronously produce the `key`/`value` to `topic`
105-
106-
See `produce_sync/2` for returns.
107-
"""
10899
def produce_sync(topic, key, value) do
109100
produce_value(topic, key, value)
110101
end

mix.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ defmodule Kaffe.Mixfile do
6363
[
6464
extras: [
6565
"README.md": [title: "Overview"],
66-
"LICENSE.md": [title: "License"]
66+
"LICENSE.md": [title: "License"],
67+
"CHANGELOG.md": [title: "Changelog"]
6768
],
6869
main: "readme",
6970
source_url: @source_url,

0 commit comments

Comments
 (0)