Skip to content

Commit

Permalink
Merge pull request #1 from JasterV/chore/setup-ci
Browse files Browse the repository at this point in the history
chore: setup CI
  • Loading branch information
JasterV authored Mar 29, 2024
2 parents db92dc2 + fd7849d commit 426323e
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 9 deletions.
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 2
updates:
# Specifying multiple directories for a single package ecosystem
# is a work in progress: https://github.com/dependabot/dependabot-core/issues/2178
- package-ecosystem: mix
directory: "/"
schedule:
interval: weekly
allow:
- dependency-type: direct

- package-ecosystem: npm
directory: "/assets"
schedule:
interval: weekly
allow:
- dependency-type: direct

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: weekly
79 changes: 79 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: CI

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

permissions:
contents: read

env:
MIX_ENV: test

jobs:
ci:
name: Run CI on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
runs-on: ubuntu-latest
strategy:
matrix:
otp: ["26.0"]
elixir: ["1.16.0"]

steps:
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{matrix.elixir}}
otp-version: ${{matrix.otp}}

- name: Checkout code
uses: actions/checkout@v4

# Step: Define how to cache deps. Restores existing cache if present.
- name: Cache deps
id: cache-deps
uses: actions/cache@v4
env:
cache-name: cache-deps
with:
path: deps
key: ${{ runner.os }}-${{matrix.otp}}-${{matrix.elixir}}-${{ env.cache-name }}-${{ hashFiles('./**/mix.lock') }}
restore-keys: |
${{ runner.os }}-${{matrix.otp}}-${{matrix.elixir}}-${{ env.cache-name }}-
# 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 }}-${{matrix.otp}}-${{matrix.elixir}}-${{ env.cache-name }}-${{ hashFiles('./**/mix.lock') }}
restore-keys: |
${{ runner.os }}-${{matrix.otp}}-${{matrix.elixir}}-${{ env.cache-name }}
${{ runner.os }}-${{matrix.otp}}-${{matrix.elixir}}-
- 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: Check that the checked in code has already been formatted.
# This step fails if something was found unformatted.
- name: Check Formatting
run: mix format --check-formatted

# Step: Execute Credo
- name: Run Credo
run: mix credo

# Step: Execute the tests.
- name: Run tests
run: mix test
2 changes: 1 addition & 1 deletion lib/intisync/puid.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Intisync.Puid do
@doc """
@moduledoc """
Generate Probably unique identifiers
"""
use Puid
Expand Down
4 changes: 4 additions & 0 deletions lib/intisync/session_pubsub.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule Intisync.SessionPubSub do
@moduledoc """
Provides function to publish/subscribe to IntiSync.PubSub topics
"""

def broadcast!(session_id, topic, event, payload) do
topic = "#{topic}:#{event}:#{session_id}"
payload = %{payload: payload, topic: topic}
Expand Down
17 changes: 11 additions & 6 deletions lib/intisync/session_server.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
defmodule Intisync.SessionServer do
alias Intisync.SessionPubSub
@moduledoc """
Contains the business logic of a session.
It is the source of truth of the session state.
"""
use GenServer

alias Intisync.SessionPubSub

def init(session_id) do
{:ok,
%{
Expand Down Expand Up @@ -47,8 +52,8 @@ defmodule Intisync.SessionServer do
GenServer.call(pid, {:get_devices})
end

def is_full?(pid) do
GenServer.call(pid, {:is_full?})
def full?(pid) do
GenServer.call(pid, {:full?})
end

def handle_call({:get_id}, _from, state) do
Expand All @@ -59,10 +64,10 @@ defmodule Intisync.SessionServer do
{:reply, state.devices, state}
end

def handle_call({:is_full?}, _from, state) do
is_full? = state.remote_connection_status == :connected
def handle_call({:full?}, _from, state) do
full? = state.remote_connection_status == :connected

{:reply, is_full?, state}
{:reply, full?, state}
end

def handle_call({:device_connected, index, device}, _from, state) do
Expand Down
3 changes: 3 additions & 0 deletions lib/intisync/sessions_supervisor.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule Intisync.SessionsSupervisor do
@moduledoc """
DynamicSupervisor responsible to manage SessionServers
"""
use DynamicSupervisor

alias Intisync.SessionServer
Expand Down
3 changes: 3 additions & 0 deletions lib/intisync_web/channels/live_view_monitor.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule IntisyncWeb.LiveViewMonitor do
@moduledoc """
Monitors LiveView processes and calls their `unmount` functions when they die
"""
use GenServer

def start_link(init_arg) do
Expand Down
3 changes: 3 additions & 0 deletions lib/intisync_web/components/device_card_component.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule IntisyncWeb.DeviceCardComponent do
@moduledoc """
Renders a device card
"""
use Phoenix.Component
import IntisyncWeb.CoreComponents

Expand Down
2 changes: 1 addition & 1 deletion lib/intisync_web/live/remote_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ defmodule IntisyncWeb.RemoteLive do
{:error, :not_found}

pid ->
if SessionServer.is_full?(pid) do
if SessionServer.full?(pid) do
{:error, :unauthorized}
else
{:ok, pid}
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ defmodule Intisync.MixProject do
{:jason, "~> 1.2"},
{:dns_cluster, "~> 0.1.1"},
{:bandit, "~> 1.2"},
{:puid, "~> 2.1"}
{:puid, "~> 2.1"},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false}
]
end

Expand Down
2 changes: 2 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
%{
"bandit": {:hex, :bandit, "1.4.1", "6ff703b33a967bc20b41ed3840a4c58e62abe62b4cc598cff7429af78e174990", [:mix], [{:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "5bbc0a4c185358b7d566a3b7b32806723ae139a8704cdc841ad787b677adcb9a"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"castore": {:hex, :castore, "1.0.6", "ffc42f110ebfdafab0ea159cd43d31365fa0af0ce4a02ecebf1707ae619ee727", [:mix], [], "hexpm", "374c6e7ca752296be3d6780a6d5b922854ffcc74123da90f2f328996b962d33a"},
"credo": {:hex, :credo, "1.7.5", "643213503b1c766ec0496d828c90c424471ea54da77c8a168c725686377b9545", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f799e9b5cd1891577d8c773d245668aa74a2fcd15eb277f51a0131690ebfb3fd"},
"dns_cluster": {:hex, :dns_cluster, "0.1.3", "0bc20a2c88ed6cc494f2964075c359f8c2d00e1bf25518a6a6c7fd277c9b0c66", [:mix], [], "hexpm", "46cb7c4a1b3e52c7ad4cbe33ca5079fbde4840dedeafca2baf77996c2da1bc33"},
"esbuild": {:hex, :esbuild, "0.8.1", "0cbf919f0eccb136d2eeef0df49c4acf55336de864e63594adcea3814f3edf41", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "25fc876a67c13cb0a776e7b5d7974851556baeda2085296c14ab48555ea7560f"},
"file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"},
Expand Down

0 comments on commit 426323e

Please sign in to comment.