feat: Implement tarball caching
This commit is contained in:
parent
c9b685d9f1
commit
7170010c6b
4 changed files with 44 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -24,3 +24,5 @@ mash-*.tar
|
||||||
|
|
||||||
# Temporary files, for example, from tests.
|
# Temporary files, for example, from tests.
|
||||||
/tmp/
|
/tmp/
|
||||||
|
|
||||||
|
.mash-cache.tar.gz
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
test:
|
test:
|
||||||
image: "elixir:1.14.4"
|
image: "elixir:1.14.4"
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .mash-cache.tar.gz
|
||||||
script:
|
script:
|
||||||
- mix local.hex --force
|
- mix local.hex --force
|
||||||
- mix local.rebar --force
|
- mix local.rebar --force
|
||||||
|
|
16
.mash.exs
16
.mash.exs
|
@ -5,11 +5,25 @@ defmodule MashConfig do
|
||||||
|
|
||||||
def jobs do
|
def jobs do
|
||||||
[
|
[
|
||||||
|
%{
|
||||||
|
name: :restore_cache,
|
||||||
|
run: restore_cache()
|
||||||
|
},
|
||||||
%{
|
%{
|
||||||
name: :test,
|
name: :test,
|
||||||
|
needs: [:restore_cache],
|
||||||
run: mix("test")
|
run: mix("test")
|
||||||
},
|
},
|
||||||
%{name: :credo, run: mix("credo", ["--all"])},
|
%{
|
||||||
|
name: :credo,
|
||||||
|
needs: [:restore_cache],
|
||||||
|
run: mix("credo", ["--all"])
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
name: :save_cache,
|
||||||
|
needs: [:test],
|
||||||
|
run: save_cache()
|
||||||
|
}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,30 @@ defmodule Mash.Helpers do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def save_cache(name \\ ".mash-cache", files \\ ["deps", "_build"]) do
|
||||||
|
fn io_pid ->
|
||||||
|
cmd("tar", ["-czpf", "#{name}.tar.gz" | files], io_pid)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def restore_cache(name \\ ".mash-cache") do
|
||||||
|
fn io_pid ->
|
||||||
|
Process.group_leader(self(), io_pid)
|
||||||
|
|
||||||
|
path = "#{name}.tar.gz"
|
||||||
|
|
||||||
|
if File.exists?(path) do
|
||||||
|
cmd("tar", ["-xzf", "#{name}.tar.gz", "--atime-preserve"], io_pid)
|
||||||
|
else
|
||||||
|
IO.puts(
|
||||||
|
IO.ANSI.yellow() <> "Warning: cache file #{path} does not exist." <> IO.ANSI.reset()
|
||||||
|
)
|
||||||
|
|
||||||
|
{[], 0}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def fun(fun) do
|
def fun(fun) do
|
||||||
fn io_pid ->
|
fn io_pid ->
|
||||||
Process.group_leader(self(), io_pid)
|
Process.group_leader(self(), io_pid)
|
||||||
|
|
Loading…
Reference in a new issue