Skip to content

Commit be90c74

Browse files
committed
Adding unit test and github flows
1 parent 7bbcdb2 commit be90c74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+505
-3
lines changed

.github/workflows/pr-ci.yaml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Jellyfish CI
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
env:
8+
MIX_ENV: test
9+
SHELL: /usr/bin/bash
10+
11+
jobs:
12+
setup:
13+
name: Setup
14+
runs-on: ubuntu-24.04
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Setup BEAM
19+
uses: erlef/setup-beam@v1
20+
with:
21+
otp-version: 28
22+
elixir-version: 1.19.1
23+
24+
- name: Cache
25+
uses: actions/cache@v4
26+
with:
27+
path: |
28+
_build
29+
deps
30+
key: |
31+
jellyfish-${{ hashFiles('mix.lock') }}-2025-12-17
32+
restore-keys: |
33+
jellyfish-
34+
35+
- name: Install Elixir dependencies
36+
run: mix do deps.get + compile --warnings-as-errors
37+
38+
test:
39+
name: Test
40+
needs: setup
41+
runs-on: ubuntu-24.04
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v4
45+
46+
- name: Setup BEAM
47+
uses: erlef/setup-beam@v1
48+
with:
49+
otp-version: 28
50+
elixir-version: 1.19.1
51+
52+
- name: Cache
53+
uses: actions/cache@v4
54+
with:
55+
path: |
56+
_build
57+
deps
58+
key: |
59+
jellyfish-${{ hashFiles('mix.lock') }}-2025-12-17
60+
restore-keys: |
61+
jellyfish-
62+
63+
- name: Run tests
64+
run: mix test --warnings-as-errors
65+
66+
analysis:
67+
name: Static Analysis
68+
needs: setup
69+
runs-on: ubuntu-24.04
70+
steps:
71+
- name: Checkout code
72+
uses: actions/checkout@v4
73+
74+
- name: Setup BEAM
75+
uses: erlef/setup-beam@v1
76+
with:
77+
otp-version: 28
78+
elixir-version: 1.19.1
79+
80+
- name: Cache
81+
uses: actions/cache@v4
82+
with:
83+
path: |
84+
_build
85+
deps
86+
key: |
87+
jellyfish-${{ hashFiles('mix.lock') }}-2025-12-17
88+
restore-keys: |
89+
jellyfish-
90+
91+
- name: Install Elixir dependencies
92+
run: mix do deps.get + compile --warnings-as-errors
93+
94+
- name: Run mix deps.unlock
95+
run: mix deps.unlock --check-unused
96+
97+
- name: Ex Doc
98+
run: mix docs --failed
99+
100+
- name: Formatted
101+
run: mix format --check-formatted

lib/jellyfish/cache.ex

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
defmodule Jellyfish.Cache do
2+
@moduledoc """
3+
Provides process-dictionary-based caching for hot upgrade operations.
4+
5+
This module manages ephemeral state during the build process to track which
6+
applications and dependencies have been processed for appup generation and copying.
7+
The cache is scoped to the current Mix process and does not persist across builds.
8+
9+
## Use Cases
10+
11+
- **Deduplication**: Ensures appup files are generated only once per dependency
12+
- **Version Tracking**: Stores application version information for use across build tasks
13+
- **Build Coordination**: Coordinates state between `GenAppup` and `CopyAppup` tasks
14+
"""
15+
16+
### ==========================================================================
17+
### Public APIs
18+
### ==========================================================================
19+
20+
@doc """
21+
Checks if this is the first time generating appup files for a library.
22+
23+
This function uses a boolean flag to track whether appup generation has been
24+
triggered for a specific library. The first call returns `true` and sets the
25+
flag to `false`, ensuring subsequent calls return `false`.
26+
"""
27+
@spec first_run_gen_appup?(atom()) :: boolean()
28+
def first_run_gen_appup?(lib), do: first_run?("libraries-gen-appup", lib)
29+
30+
@doc """
31+
Checks if this is the first time copying appup files for a library.
32+
33+
Similar to `first_run_gen_appup?/1`, but tracks the copy operation separately.
34+
This allows the build process to coordinate generation and copying as distinct phases.
35+
"""
36+
@spec first_run_copy_appup?(atom()) :: boolean()
37+
def first_run_copy_appup?(lib), do: first_run?("libraries-copy-appup", lib)
38+
39+
@doc """
40+
Stores application version information in the process cache.
41+
42+
The version is stored as a map with a `:version` key, allowing for future
43+
extension with additional metadata if needed.
44+
"""
45+
@spec store_app_version(atom() | String.t(), String.t()) :: %{version: String.t()}
46+
def store_app_version(app, version) do
47+
Process.put(app, %{version: version})
48+
end
49+
50+
@doc """
51+
Retrieves application information from the cache.
52+
53+
Returns the data previously stored via `store_app_version/2`, or `nil` if
54+
no data exists for the given application.
55+
"""
56+
@spec get_app(atom() | String.t()) :: %{version: String.t()} | nil
57+
def get_app(app), do: Process.get(app)
58+
59+
### ==========================================================================
60+
### Private functions
61+
### ==========================================================================
62+
defp first_run?(term, lib) do
63+
# Retrieve the flag, defaulting to true if not set
64+
data = Process.get({term, lib}, true)
65+
66+
# If this is the first run (true), mark it as false for next time
67+
if data do
68+
Process.put({term, lib}, false)
69+
end
70+
71+
# Return the original value
72+
data
73+
end
74+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule Jellyfish.Releases.Appups do
1+
defmodule Jellyfish.Releases.Appup do
22
@moduledoc """
33
Generate appup files for hot upgrades
44

lib/jellyfish/tasks/compile/gen_appup.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Mix.Tasks.Compile.GenAppup do
77
use Mix.Task.Compiler
88

99
alias Jellyfish.Cache
10-
alias Jellyfish.Releases.Appups
10+
alias Jellyfish.Releases.Appup
1111

1212
@recursive true
1313

@@ -147,7 +147,7 @@ defmodule Mix.Tasks.Compile.GenAppup do
147147
end
148148
end
149149

150-
case Appups.make(app, v1, v2, v1_path, v2_path, _transforms = []) do
150+
case Appup.make(app, v1, v2, v1_path, v2_path, _transforms = []) do
151151
{:error, _} = err ->
152152
err
153153

0 commit comments

Comments
 (0)