Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to gh actions #33

Merged
merged 29 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cef029f
Add basic gh actions config
jerith Jul 30, 2024
40ad4cc
Try a looser OTP version
jerith Jul 30, 2024
8b7efad
Apparently old OTP needs old ubuntu
jerith Jul 30, 2024
9fdf675
Use a runner that actually still exists
jerith Jul 30, 2024
3c025a7
Add postgres and rabbitmq to build
jerith Jul 30, 2024
9493e83
Fix service container ports
jerith Jul 30, 2024
98a20a1
Move lints into a separate step and allow them to fail for now
jerith Jul 30, 2024
c7e8c42
Remove travis config
jerith Jul 30, 2024
53a372e
Build and test with newer elixir
jerith Jul 30, 2024
8e4a6fd
Override dependency to fix build
jerith Jul 30, 2024
9d94a96
Update deps to work with new Elixir/OTP
jerith Jul 30, 2024
430b45b
Drop old Elixir/OTP versions while fixing new ones
jerith Jul 30, 2024
7a34175
Fix prometheus_process_collector build
jerith Jul 30, 2024
00b3ccf
Try compile grumpy dependency on its own to avoid breaking others
jerith Jul 30, 2024
75e4f33
Merge branch 'develop' into switch-to-gh-actions
jerith Jul 30, 2024
a39857a
Fix formatting and enable lints again
jerith Jul 30, 2024
dd332c6
Add docker build
jerith Jul 30, 2024
3357143
Merge branch 'develop' into switch-to-gh-actions
jerith Jul 30, 2024
aec3128
Remove prometheus_process_collector
jerith Jul 30, 2024
ce1aa9a
Update Dockerfile to Elixir 1.17
jerith Jul 30, 2024
b0012a3
Update amqp
jerith Jul 30, 2024
e5a445b
Use OTP 26 for rabbit_common/amqp
jerith Jul 30, 2024
4bc7e67
Update some Phoenix things, replace :crypto.hmac
jerith Jul 30, 2024
1343e4a
Update credo
jerith Jul 30, 2024
a1f7a4b
Fix some credo warnings
jerith Jul 30, 2024
7bd43e2
Fix some more credo warnings
jerith Jul 30, 2024
f3ef552
use Mix.Config -> import Config
jerith Jul 30, 2024
81d62f7
Fix various deprecation warnings
jerith Jul 30, 2024
1974c20
Update runtime base image as well
jerith Jul 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Continuous integration
on:
push:
branches: ["*"]
tags: ["v*"]
pull_request:
branches: ["develop"]

jobs:
test:
# runs-on: ubuntu-latest
runs-on: ubuntu-20.04

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
rabbitmq:
image: rabbitmq:3.8
env:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
ports:
- 5672:5672

strategy:
matrix:
include:
# NOTE: One of the dependecies (rabbit_common) is incompatible with OTP 27.
- elixir-version: "1.17"
otp-version: "26"

steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
id: beam
with:
elixir-version: ${{ matrix.elixir-version }}
otp-version: ${{ matrix.otp-version }}

- name: Fetch deps
run: |
mix deps.get

- name: Run tests
run: |
# This is basically `mix test` with coverage enabled.
mix coveralls.json

- name: Lints
run: |
mix format --check-formatted
# This will mention FIXME and TODO comments without failing, any
# other issue fails the build.
mix credo
72 changes: 0 additions & 72 deletions .travis.yml

This file was deleted.

5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM elixir:1.9 as elixir
# NOTE: One of the dependecies (rabbit_common) is incompatible with OTP 27.
FROM elixir:1.17-otp-26 as elixir
ENV MIX_ENV="prod"
COPY lib lib
COPY config config
Expand All @@ -10,7 +11,7 @@ RUN mix deps.get
RUN mix deps.compile
RUN mix compile

FROM elixir:1.9-alpine
FROM elixir:1.17-otp-26-alpine
ENV MIX_ENV="prod"
RUN mix local.hex --force
RUN mix local.rebar --force
Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
use Mix.Config
import Config

# Configures the endpoint
config :turn_junebug_expressway, TurnJunebugExpresswayWeb.Endpoint,
Expand Down
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# For development, we disable any cache and enable
# debugging and code reloading.
Expand Down
2 changes: 1 addition & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# For production, we often load configuration from external
# sources, such as your system environment. For this reason,
Expand Down
2 changes: 1 addition & 1 deletion config/prod.secret.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# In this file, we keep production configuration that
# you'll likely want to automate and keep away from
Expand Down
4 changes: 2 additions & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# We don't run a server during test. If one is required,
# you can enable the server option below.
Expand All @@ -11,7 +11,7 @@ config :turn_junebug_expressway,
rapidpro_client: TurnJunebugExpressway.Backends.ClientMock

# Print only warnings and errors during test
config :logger, level: :warn
config :logger, level: :warning

config :tesla, adapter: Tesla.Mock

Expand Down
10 changes: 4 additions & 6 deletions lib/turn_junebug_expressway/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ defmodule TurnJunebugExpressway.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec

# Metrics
TurnJunebugExpresswayWeb.PhoenixInstrumenter.setup()
TurnJunebugExpresswayWeb.PipelineInstrumenter.setup()
Expand All @@ -14,11 +12,11 @@ defmodule TurnJunebugExpressway.Application do
# Define workers and child supervisors to be supervised
children = [
# Start the endpoint when the application starts
supervisor(TurnJunebugExpresswayWeb.Endpoint, []),
TurnJunebugExpresswayWeb.Endpoint,
# Start your own worker by calling: TurnJunebugExpressway.Worker.start_link(arg1, arg2, arg3)
# worker(TurnJunebugExpressway.Worker, [arg1, arg2, arg3]),
worker(TurnJunebugExpressway.MessageEngine, []),
worker(TurnJunebugExpressway.HttpPushEngine, []),
# {TurnJunebugExpressway.Worker, [arg1, arg2, arg3]},
{TurnJunebugExpressway.MessageEngine, name: TurnJunebugExpressway.MessageEngine},
{TurnJunebugExpressway.HttpPushEngine, name: TurnJunebugExpressway.HttpPushEngine},
{Task.Supervisor, name: Task.ExpressSupervisor, restart: :transient}
]

Expand Down
3 changes: 1 addition & 2 deletions lib/turn_junebug_expressway/behaviours/client_behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ defmodule TurnJunebugExpressway.Behaviours.ClientBehaviour do
def format_error(body) when is_map(body) do
body
|> Map.keys()
|> Enum.map(fn key -> "#{key}: #{format_error(body[key])}" end)
|> Enum.join(", ")
|> Enum.map_join(", ", fn key -> "#{key}: #{format_error(body[key])}" end)
end

def format_error(body) do
Expand Down
14 changes: 8 additions & 6 deletions lib/turn_junebug_expressway_web/utils.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule TurnJunebugExpresswayWeb.Utils do
use Tesla

@turn_client Application.get_env(:turn_junebug_expressway, :turn_client)
@rapidpro_client Application.get_env(:turn_junebug_expressway, :rapidpro_client)
@turn_client Application.compile_env(:turn_junebug_expressway, :turn_client)
@rapidpro_client Application.compile_env(:turn_junebug_expressway, :rapidpro_client)

def get_env(section, key) do
Application.get_env(:turn_junebug_expressway, section)[key]
Expand All @@ -15,7 +15,8 @@ defmodule TurnJunebugExpresswayWeb.Utils do
|> Map.get("x-turn-hook-signature")

our_hmac =
:crypto.hmac(
:crypto.mac(
:hmac,
:sha256,
get_env(:turn, :hmac_secret),
conn.private[:raw_body]
Expand Down Expand Up @@ -112,7 +113,8 @@ defmodule TurnJunebugExpresswayWeb.Utils do
end

def forward_event(event) do
IO.inspect(event)
IO.puts("FORWARD_EVENT: #{inspect(event)}")

case event |> get_event_status do
{:ignore, _} ->
:ok
Expand Down Expand Up @@ -194,7 +196,7 @@ defmodule TurnJunebugExpresswayWeb.Utils do
end
end

def is_queue_stuck(rate, messages) do
def queue_stuck?(rate, messages) do
case {rate, messages} do
{rate, messages} when rate <= 0 and messages > 0 -> true
{_, _} -> false
Expand All @@ -209,7 +211,7 @@ defmodule TurnJunebugExpresswayWeb.Utils do

%{
"name" => "#{queue_name}",
"stuck" => is_queue_stuck(rate, messages),
"stuck" => queue_stuck?(rate, messages),
"messages" => messages
}
end
Expand Down
19 changes: 12 additions & 7 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ defmodule TurnJunebugExpressway.Mixfile do
[
app: :turn_junebug_expressway,
version: "0.0.18",
elixir: "~> 1.9",
elixir: "~> 1.17",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
compilers: [:gettext] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps(),
Expand Down Expand Up @@ -40,27 +40,32 @@ defmodule TurnJunebugExpressway.Mixfile do
# Type `mix help deps` for examples and options.
defp deps do
[
{:phoenix, "~> 1.4"},
{:phoenix_pubsub, "~> 1.1"},
{:phoenix, "~> 1.7"},
{:phoenix_view, "~> 2.0"},
{:phoenix_pubsub, "~> 2.0"},
{:ecto_sql, "~> 3.0"},
{:phoenix_ecto, "~> 4.0"},
{:postgrex, ">= 0.15.0"},
{:gettext, "~> 0.17.1"},
{:prometheus_phoenix, "~> 1.3.0"},
{:prometheus_plugs, "~> 1.1.5"},
{:prometheus_process_collector, "~> 1.6.0"},
# It looks like we don't actually need this.
# {:prometheus_process_collector, "~> 1.6.0"},
{:plug_cowboy, "~> 2.1"},
{:jason, "~> 1.1"},
{:amqp, "~> 1.3"},
{:amqp, "~> 3.3"},
{:timex, "~> 3.5"},
{:tesla, "~> 1.2"},
{:mock, "~> 0.3.2"},
{:mox, "~> 0.5", only: :test},
{:sentry, "~> 7.2"},

# We need to override this to make it compile with newer Elixir/OTP.
{:ssl_verify_fun, "~> 1.1.5", manager: :rebar3, override: true},

# Dev/test/build tools.
{:excoveralls, "~> 0.8", only: :test},
{:credo, "~> 0.9", only: [:dev, :test], runtime: false}
{:credo, "~> 1.7", only: [:dev, :test], runtime: false}
]
end

Expand Down
Loading
Loading