Fix path to deploy apps with attachments (#3084)

This commit is contained in:
Alexandre de Souza 2025-10-23 16:46:04 -03:00 committed by Jonatan Kłosko
parent 9fa66a0d74
commit 179f1e5cbf
2 changed files with 66 additions and 2 deletions

View file

@ -145,8 +145,11 @@ defmodule LivebookCLI.Deploy do
for path <- config.paths do
log_info(" * Preparing to deploy notebook #{Path.basename(path)}")
absolute_path = Path.expand(path)
files_dir = Livebook.FileSystem.File.local(absolute_path)
files_dir =
path
|> Path.expand()
|> Livebook.FileSystem.File.local()
|> Livebook.FileSystem.File.resolve("files/")
with {:ok, content} <- File.read(path),
{:ok, app_deployment} <- prepare_app_deployment(path, content, files_dir) do

View file

@ -112,6 +112,67 @@ defmodule LivebookCLI.Integration.DeployTest do
end
end
test "successfully deploys a notebook with attachments via CLI",
%{team: team, node: node, org: org, tmp_dir: tmp_dir} do
title = "App with attachments"
slug = Utils.random_short_id()
app_path = Path.join(tmp_dir, "#{slug}.livemd")
{key, _} = TeamsRPC.create_org_token(node, org: org)
deployment_group = TeamsRPC.create_deployment_group(node, org: org, url: @url)
hub_id = team.id
deployment_group_id = to_string(deployment_group.id)
files_dir = Path.join(tmp_dir, "files")
File.mkdir!(files_dir)
attachment_path = Path.join(files_dir, "file.txt")
File.write!(attachment_path, "some content")
stamp_notebook(app_path, """
<!-- livebook:{"app_settings":{"access_type":"public","slug":"#{slug}"},"file_entries":[{"name":"file.txt","type":"attachment"}],"hub_id":"#{hub_id}"} -->
# #{title}
```elixir
Mix.install([
{:kino, "~> 0.17.0"}
])
```
## Section
```elixir
path = Kino.FS.file_path("file.txt")
content = File.read!(path)
content = String.trim(content)
IO.puts(content)
```
""")
output =
ExUnit.CaptureIO.capture_io(fn ->
assert deploy(
key,
team.teams_key,
deployment_group.id,
app_path
) == :ok
end)
assert output =~ "* Preparing to deploy notebook #{slug}.livemd"
assert output =~ " * #{title} deployed successfully. (#{@url}/apps/#{slug})"
assert_receive {:app_deployment_started,
%{
title: ^title,
slug: ^slug,
deployment_group_id: ^deployment_group_id,
hub_id: ^hub_id,
deployed_by: "CLI"
}}
end
test "fails with unauthorized org token",
%{team: team, node: node, org: org, tmp_dir: tmp_dir} do
title = "Test CLI Deploy App"