Skip to content

Commit

Permalink
Merge branch 'switch-to-gh-actions' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed Jul 31, 2024
2 parents ae08aab + 1974c20 commit 7f78ff6
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 153 deletions.
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

0 comments on commit 7f78ff6

Please sign in to comment.