Skip to content

Commit

Permalink
Merge branch 'release/v8.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Oct 26, 2023
2 parents 581e266 + b3914a2 commit 9950af0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
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@v3
with:
path: ~/.mix
key: ${{ runner.arch }}-alpine-${{ inputs.alpine }}-pakman
key: ${{ runner.arch }}-alpine-${{ inputs.alpine }}-pakman-8.1.3

- 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.1.2 --force
mix escript.install hex pakman 8.1.3 --force
shell: alpine.sh {0}
env:
MIX_ENV: prod
19 changes: 19 additions & 0 deletions lib/pakman/instellar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ defmodule Pakman.Instellar do
end
end

def get_deployment(token, hash) do
package_token = System.get_env("INSTELLAR_PACKAGE_TOKEN")

headers = [
{"authorization", "Bearer #{token}"},
{"x-instellar-package-token", package_token}
]

client()
|> get("/publish/deployments/#{hash}", headers: headers)
|> case do
{:ok, %{status: 200, body: body}} ->
{:ok, body["data"]}

{:ok, %{status: 404}} ->
{:ok, :not_found}
end
end

@spec create_deployment(binary, binary, map) ::
{:ok, atom, map} | {:error, atom}
def create_deployment(token, archive_path, config_params) do
Expand Down
7 changes: 7 additions & 0 deletions lib/pakman/push.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ defmodule Pakman.Push do
archive = Keyword.get(options, :archive, "packages.zip")
config_file = Keyword.get(options, :config, "instellar.yml")
workspace = System.get_env("GITHUB_WORKSPACE")
hash = System.get_env("WORKFLOW_SHA") || System.get_env("GITHUB_SHA")

config =
workspace
|> Path.join(config_file)
|> YamlElixir.read_from_file!()

with {:ok, token} <- Instellar.authenticate(),
{:ok, :not_found} <- Instellar.get_deployment(token, hash),
{:ok, %{"attributes" => storage}} <- Instellar.get_storage(token),
{:ok, %{archive: archive_path}} <-
push_files(storage, archive, options),
Expand All @@ -41,6 +43,11 @@ defmodule Pakman.Push do

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

{:ok, :already_exists}

{:error, body} ->
raise Error, message: "[Pakman.Push] #{inspect(body)}"

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Pakman.MixProject do
def project do
[
app: :pakman,
version: "8.1.2",
version: "8.1.3",
elixir: "~> 1.13",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down
24 changes: 24 additions & 0 deletions test/pakman/push_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ defmodule Pakman.PushTest do
|> Plug.Conn.resp(201, Jason.encode!(%{data: %{token: "something"}}))
end)

Bypass.expect(bypass, "GET", "/publish/deployments/somesha", fn conn ->
conn
|> Plug.Conn.put_resp_header("content-type", "application/json")
|> Plug.Conn.resp(404, Jason.encode!(%{data: %{errors: %{detail: "not_found"}}}))
end)

Bypass.expect(bypass, "GET", "/publish/storage", fn conn ->
conn
|> Plug.Conn.put_resp_header("content-type", "application/json")
Expand Down Expand Up @@ -92,5 +98,23 @@ defmodule Pakman.PushTest do

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

test "when deployment already exists", %{
bypass: bypass
} do
Bypass.expect(bypass, "POST", "/publish/automation/callback", fn conn ->
conn
|> Plug.Conn.put_resp_header("content-type", "application/json")
|> Plug.Conn.resp(201, Jason.encode!(%{data: %{token: "something"}}))
end)

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}}}))
end)

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

0 comments on commit 9950af0

Please sign in to comment.