Skip to content

Commit

Permalink
blend env var
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Apr 8, 2024
1 parent ca7b7e5 commit 0fede58
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
mix_test:
name: mix test (Elixir ${{matrix.elixir}} | Erlang/OTP ${{matrix.otp}})
runs-on: ubuntu-latest
env:
BLEND: ${{ matrix.blend }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -49,9 +51,6 @@ jobs:
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: Set lock file from blend
if: matrix.blend
run: cp blend/${{matrix.blend}}.mix.lock mix.lock
- name: Update deps
if: matrix.update_deps
run: mix deps.update --all
Expand All @@ -62,7 +61,9 @@ jobs:
path: |
deps
_build
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
blend/deps
blend/_build
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ matrix.blend }}-${{ hashFiles('mix.lock', 'blend/*.mix.lock') }}
- name: Install Dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
run: |
Expand Down
22 changes: 22 additions & 0 deletions blend/premix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file is autogenerated by blend package.
#
# Run `mix blend.premix` to update it's contents after
# each blend package version update.

maybe_put_env = fn varname, value ->
System.put_env(varname, System.get_env(varname, value))
end

existing_blend = fn name ->
Code.eval_file("blend.exs")
|> elem(0)
|> Map.fetch!(String.to_atom(name))
end

blend = System.get_env("BLEND")

if blend && String.length(blend) > 0 && existing_blend.(blend) do
maybe_put_env.("MIX_LOCKFILE", "blend/#{blend}.mix.lock")
maybe_put_env.("MIX_DEPS_PATH", "blend/deps/#{blend}")
maybe_put_env.("MIX_BUILD_ROOT", "blend/_build/#{blend}")
end
11 changes: 11 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Code.compile_file("blend/premix.exs")

defmodule Surface.MixProject do
use Mix.Project

Expand All @@ -17,6 +19,7 @@ defmodule Surface.MixProject do
docs: docs(),
package: package()
]
|> Keyword.merge(maybe_lockfile_option())
end

# Run "mix help compile.app" to learn about applications.
Expand Down Expand Up @@ -81,4 +84,12 @@ defmodule Surface.MixProject do
defp catalogues do
["priv/catalogue"]
end

def maybe_lockfile_option do
case System.get_env("MIX_LOCKFILE") do
nil -> []
"" -> []
lockfile -> [lockfile: lockfile]
end
end
end

0 comments on commit 0fede58

Please sign in to comment.