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

When deployment already exists copy the archive path #15

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ runs:
uses: actions/cache@v4
with:
path: ~/.mix
key: ${{ runner.arch }}-alpine-${{ inputs.alpine }}-pakman-8.2.12
key: ${{ runner.arch }}-alpine-${{ inputs.alpine }}-pakman-develop

- name: Install Pakman
if: steps.cache-pakman.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix escript.install hex pakman 8.2.12 --force
mix escript.install github upmaru/pakman branch develop --force
shell: alpine.sh {0}
env:
MIX_ENV: prod
25 changes: 22 additions & 3 deletions lib/pakman/push.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,35 @@ defmodule Pakman.Push do
{:error, error} ->
raise Error, message: "[Pakman.Push] #{inspect(error)}"

{:ok, %{"attributes" => _}} ->
Logger.info("[Pakman.Push] Deployment already exists...")
{:ok, %{"attributes" => attributes}} ->
Logger.info(
"[Pakman.Push] Deployment already exists copying existing..."
)

{:ok, :already_exists}
copy(attributes, config)

_ ->
raise Error, message: "[Pakman.Push] Deployment creation failed..."
end
end

defp copy(%{"archive_path" => archive_path} = existing_deployment, config) do
with {:ok, token} <- Instellar.authenticate(),
{:ok, deployment_message, response} <-
Instellar.create_deployment(token, archive_path, config),
{:ok, configuration_message, _response} <-
Instellar.create_configuration(
token,
response["attributes"]["id"],
config
) do
print_deployment_message(deployment_message)
print_configuration_message(configuration_message)

{:ok, :copied}
end
end

def push_files(storage, archive, options) do
home = System.get_env("HOME")
sha = System.get_env("WORKFLOW_SHA") || System.get_env("GITHUB_SHA")
Expand Down
42 changes: 39 additions & 3 deletions test/pakman/push_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,47 @@ defmodule Pakman.PushTest do
Bypass.expect(bypass, "GET", "/publish/deployments/somesha", fn conn ->
conn
|> Plug.Conn.put_resp_header("content-type", "application/json")
|> Plug.Conn.resp(200, Jason.encode!(%{data: %{attributes: %{id: 1}}}))
|> Plug.Conn.resp(
200,
Jason.encode!(%{
data: %{
attributes: %{
"id" => 1,
"archive_path" => "archives/some-uuid/packages.zip"
}
}
})
)
end)

Bypass.expect(bypass, "POST", "/publish/deployments", fn conn ->
conn
|> Plug.Conn.put_resp_header("content-type", "application/json")
|> Plug.Conn.resp(
201,
Jason.encode!(%{
data: %{
attributes: %{
"id" => 1,
"archive_path" => "archives/some-uuid/packages.zip"
}
}
})
)
end)

assert {:ok, :already_exists} =
Push.perform(config: "test/fixtures/rails.yml")
Bypass.expect_once(
bypass,
"POST",
"/publish/deployments/1/configurations",
fn conn ->
conn
|> Plug.Conn.put_resp_header("content-type", "application/json")
|> Plug.Conn.resp(201, Jason.encode!(%{data: %{id: 1}}))
end
)

assert {:ok, :copied} = Push.perform(config: "test/fixtures/rails.yml")
end
end
end