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

Added CI #16

Merged
merged 18 commits into from
Jan 8, 2025
45 changes: 45 additions & 0 deletions .github/workflows/elixir-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Elixir CI

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

permissions:
contents: read

jobs:
build:
name: Build and test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0
with:
elixir-version: "1.17.3" # [Required] Define the Elixir version
otp-version: "27.1.2" # [Required] Define the Erlang/OTP version
- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-

- name: Setup project
run: mix setup
- name: Check formatting
run: mix format --check-formatted
- name: Check credo
run: mix credo
- name: Check prettier
run: (cd assets && npx prettier . --check)
- name: Run tests
run: mix test
4 changes: 4 additions & 0 deletions lib/live_debugger.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule LiveDebugger do
@moduledoc """
Debugger for LiveView applications.
"""

use Phoenix.Component

attr(:redirect_url, :string, required: true, doc: "The URL of the debugger, e.g. `/dbg`")
Expand Down
4 changes: 4 additions & 0 deletions lib/live_debugger/components/tooltip.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule LiveDebugger.Components.Tooltip do
@moduledoc """
This module provides a Tooltip component.
"""

use LiveDebuggerWeb, :component

@doc """
Expand Down
4 changes: 4 additions & 0 deletions lib/live_debugger/components/tree.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule LiveDebugger.Components.Tree do
@moduledoc """
Tree component which show nested tree of live view and live components.
"""

use LiveDebuggerWeb, :component

alias LiveDebugger.Components.Collapsible
Expand Down
1 change: 0 additions & 1 deletion lib/live_debugger/layout.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ defmodule LiveDebugger.Layout do
"""
end

# TODO: Remove this and the conditional on Phoenix v1.7+
@compile {:no_warn_undefined, Phoenix.VerifiedRoutes}

defp asset_path(conn, asset) when asset in [:css, :js] do
Expand Down
21 changes: 7 additions & 14 deletions lib/live_debugger/live_views/socket_dashboard_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@ defmodule LiveDebugger.LiveViews.SocketDashboardLive do
def render(assigns) do
~H"""
<.loading_variant :if={@debugged_pid.status == :loading} />

<div class="w-full flex flex-row">
<.live_component
:if={@debugged_pid.status == :ok}
id="sidebar"
module={LiveDebugger.LiveComponents.Sidebar}
pid={@debugged_pid.result}
socket_id={@socket_id}
/>
<div class="flex items-center justify-center w-full h-screen">
<.not_found_component :if={@debugged_pid.status == :not_found} />
<.error_component :if={@debugged_pid.status == :error} />
</div>
</div>
<.not_found_component :if={@debugged_pid.status == :not_found} />
<.error_component :if={@debugged_pid.status == :error} />
<.container :if={@debugged_pid.status == :ok} max_width="full">
<div>Monitored socket: <span class="text-blue-500">{@socket_id}</span></div>
<div>Debugged PID: <span class="text-blue-500">{inspect(@debugged_pid.result)}</span></div>
</.container>
"""
end

Expand Down Expand Up @@ -124,6 +116,7 @@ defmodule LiveDebugger.LiveViews.SocketDashboardLive do
defp assign_async_debugged_pid(socket) do
socket_id = socket.assigns.socket_id

# credo:disable-for-lines:9
socket
|> assign(:debugged_pid, %{status: :loading})
|> start_async(:fetch_debugged_pid, fn ->
Expand Down
4 changes: 4 additions & 0 deletions lib/live_debugger/services/channel_state_scraper.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule LiveDebugger.Services.ChannelStateScraper do
@moduledoc """
This module provides functions that performs operation on state of LiveView channel.
"""

alias LiveDebugger.Services.TreeNode
alias LiveDebugger.Services.LiveViewScraper

Expand Down
2 changes: 2 additions & 0 deletions lib/live_debugger/services/live_view_scraper.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule LiveDebugger.Services.LiveViewScraper do
@moduledoc false

@callback channel_state_from_pid(pid :: pid()) :: {:ok, map()} | {:error, term()}
@callback pid_by_socket_id(socket_id :: String.t()) :: pid() | nil
@callback pids() :: [pid()]
Expand Down
12 changes: 12 additions & 0 deletions lib/live_debugger/services/module_discovery.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule LiveDebugger.Services.ModuleDiscovery do
@moduledoc """
This module provides functions to discover LiveViews and LiveComponents in the current application.
"""

@live_view_behaviour Phoenix.LiveView
@live_component_behaviour Phoenix.LiveComponent

Expand All @@ -18,6 +22,7 @@ defmodule LiveDebugger.Services.ModuleDiscovery do
loaded_modules
|> Enum.map(fn {module, _} -> module end)
|> Enum.filter(&loaded?/1)
|> Enum.reject(&debugger?/1)
|> Enum.filter(&behaviour?(&1, behaviour))
end

Expand All @@ -27,4 +32,11 @@ defmodule LiveDebugger.Services.ModuleDiscovery do
module_behaviours = module.module_info(:attributes)[:behaviour] || []
Enum.member?(module_behaviours, behaviour_to_find)
end

defp debugger?(module) do
stringified_module = Atom.to_string(module)

String.starts_with?(stringified_module, "LiveDebugger.") or
String.starts_with?(stringified_module, "Elixir.LiveDebugger.")
end
end
2 changes: 1 addition & 1 deletion lib/live_debugger/services/tree_node.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule LiveDebugger.Services.TreeNode do
@doc """
@moduledoc """
This module provides functions to work with the tree of LiveView and LiveComponent nodes (TreeNodes).
"""
alias LiveDebugger.Services.TreeNode.LiveView, as: LiveViewNode
Expand Down
2 changes: 2 additions & 0 deletions lib/live_debugger/services/tree_node/live_component.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule LiveDebugger.Services.TreeNode.LiveComponent do
@moduledoc false

defstruct [:id, :cid, :module, :assigns, :children]

@type cid() :: integer() | nil
Expand Down
4 changes: 4 additions & 0 deletions lib/live_debugger/utils/callbacks.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule LiveDebugger.Utils.Callbacks do
@moduledoc """
This module provides functions to generate a list of callbacks for LiveViews and LiveComponents.
"""

alias LiveDebugger.Services.ModuleDiscovery

@common_callbacks [
Expand Down
4 changes: 4 additions & 0 deletions lib/live_debugger_web.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule LiveDebuggerWeb do
@moduledoc false

def live_view do
quote do
use Phoenix.LiveView,
Expand Down Expand Up @@ -51,6 +53,8 @@ defmodule LiveDebuggerWeb do
end

defmodule LiveDebuggerWeb.Helpers do
@moduledoc false

def ok(socket), do: {:ok, socket}
def noreply(socket), do: {:noreply, socket}
end
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ defmodule LiveDebugger.MixProject do
[
setup: ["deps.get", "cmd --cd assets npm install", "assets.setup", "assets.build"],
dev: "run --no-halt dev.exs",
"js.format": ["cmd --cd assets prettier . --write"],
"assets.setup": ["esbuild.install --if-missing", "tailwind.install --if-missing"],
"assets.build": ["esbuild default --minify", "tailwind live_debugger --minify"]
]
Expand All @@ -49,7 +48,8 @@ defmodule LiveDebugger.MixProject do
{:phoenix_live_reload, "~> 1.5", only: :dev},
{:esbuild, "~> 0.7", only: :dev},
{:tailwind, "~> 0.2", only: :dev},
{:mox, "~> 1.2", only: :test}
{:mox, "~> 1.2", only: :test},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false}
]
end
end
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.6.1", "9e01b93d72ddc21d8c576a704949e86ee6cde7d11270a1d3073787876527a48f", [:mix], [{:hpax, "~> 1.0", [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", "5a904bf010ea24b67979835e0507688e31ac873d4ffc8ed0e5413e8d77455031"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"castore": {:hex, :castore, "1.0.10", "43bbeeac820f16c89f79721af1b3e092399b3a1ecc8df1a472738fd853574911", [:mix], [], "hexpm", "1b0b7ea14d889d9ea21202c43a4fa015eb913021cb535e8ed91946f4b77a8848"},
"credo": {:hex, :credo, "1.7.11", "d3e805f7ddf6c9c854fd36f089649d7cf6ba74c42bc3795d587814e3c9847102", [: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", "56826b4306843253a66e47ae45e98e7d284ee1f95d53d1612bb483f88a8cf219"},
"decimal": {:hex, :decimal, "2.2.0", "df3d06bb9517e302b1bd265c1e7f16cda51547ad9d99892049340841f3e15836", [:mix], [], "hexpm", "af8daf87384b51b7e611fb1a1f2c4d4876b65ef968fa8bd3adf44cff401c7f21"},
"ecto": {:hex, :ecto, "3.12.5", "4a312960ce612e17337e7cefcf9be45b95a3be6b36b6f94dfb3d8c361d631866", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6eb18e80bef8bb57e17f5a7f068a1719fbda384d40fc37acb8eb8aeca493b6ea"},
"esbuild": {:hex, :esbuild, "0.8.2", "5f379dfa383ef482b738e7771daf238b2d1cfb0222bef9d3b20d4c8f06c7a7ac", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "558a8a08ed78eb820efbfda1de196569d8bfa9b51e8371a1934fbb31345feda7"},
Expand Down
11 changes: 6 additions & 5 deletions test/services/module_discovery_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ defmodule LiveDebugger.Services.ModuleDiscoveryTest do
Macro.Env.location(__ENV__)
)

assert %{
live_views: [LiveDebuggerTest.TestView],
live_components: [LiveDebuggerTest.TestComponent]
} =
ModuleDiscovery.find_live_modules()
%{live_views: live_views, live_components: live_components} =
ModuleDiscovery.find_live_modules()

assert Enum.any?(live_views, &(&1 == LiveDebuggerTest.TestView))
assert Enum.any?(live_components, &(&1 == LiveDebuggerTest.TestComponent))
refute Enum.any?(live_views, &(&1 == LiveDebuggerTest.OtherModule))
end
end

Expand Down
2 changes: 2 additions & 0 deletions test/support/process_case.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule LiveDebugger.ProcessCase do
@moduledoc false

use ExUnit.CaseTemplate

import Mox
Expand Down
Loading