Skip to content

Commit

Permalink
Separate slug and name
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Jan 29, 2024
1 parent 92edca7 commit 8ba0e2a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 8 deletions.
15 changes: 8 additions & 7 deletions lib/pakman/bootstrap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ defmodule Pakman.Bootstrap do

@system.cmd("sudo", ["chown", "-R", "runner:abuild", workspace])

%{organization: namespace, name: name} = Environment.repository()
%{organization: namespace, name: name, slug: slug} =
Environment.repository()

{version, _} = System.cmd("git", ["describe", "--tags", "--always"])

Expand Down Expand Up @@ -55,21 +56,21 @@ defmodule Pakman.Bootstrap do
"custom" ->
create_apkbuild(
base_path,
name,
slug,
String.trim(version),
String.trim(build),
config
)

create_file(base_path, name, :pre_install)
create_file(base_path, slug, :pre_install)

Map.get(config, "hook", %{})
|> Enum.map(&create_hook_file(&1, base_path, name))
|> Enum.map(&create_hook_file(&1, base_path, slug))

_ ->
create_apkbuild(
base_path,
name,
slug,
String.trim(version),
String.trim(build),
config
Expand All @@ -79,10 +80,10 @@ defmodule Pakman.Bootstrap do
create_life_cycle_files(base_path, run_config)
end

create_build_files(base_path, name, config["type"])
create_build_files(base_path, slug, config["type"])

Map.get(config, "hook", %{})
|> Enum.map(&create_hook_file(&1, base_path, name))
|> Enum.map(&create_hook_file(&1, base_path, slug))
end

Setup.perform()
Expand Down
2 changes: 1 addition & 1 deletion lib/pakman/environment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ defmodule Pakman.Environment do
|> System.get_env()
|> String.split("/")

%{organization: organization, name: Slug.slugify(name)}
%{organization: organization, name: name, slug: Slug.slugify(name)}
end
end
51 changes: 51 additions & 0 deletions test/fixtures/astro.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
dependencies:
build:
- nodejs-current
- npm
runtime:
- caddy
- bash
- curl
- s6
- jq
- ca-certificates
- artellectual-com-openrc

stack: alpine/3.19

build:
command: |
npm install
npm run build
destinations:
- dist
- Caddyfile

run:
name: artellectual-com
services:
- binary: caddy
name: web
path: /usr/sbin
start:
call: run --config /var/lib/artellectual-com/Caddyfile

hook:
post-deinstall: |
rc-service artellectual-com stop
rc-update del artellectual-com
post-install: |
rc-update add artellectual-com
post-upgrade: |
rc-service artellectual-com start
pre-upgrade: |
rc-service artellectual-com stop
kits:
- description: static site server
main: true
name: web
ports:
- main: true
name: web
target: 3000
14 changes: 14 additions & 0 deletions test/pakman/bootstrap_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ defmodule Pakman.BootstrapTest do
end

describe "perform" do
test "astro config" do
System.put_env("HOME", "tmp/caddy")
System.put_env("GITHUB_WORKSPACE", "tmp/astro")
System.put_env("GITHUB_REPOSITORY", "artellectual/artellectual.com")

Pakman.SystemMock
|> expect(:cmd, 2, fn _binary, _options ->
:ok
end)

assert :ok ==
Pakman.Bootstrap.perform(config: "test/fixtures/astro.yml")
end

test "caddy config" do
System.put_env("HOME", "tmp/caddy")
System.put_env("GITHUB_WORKSPACE", "tmp/caddy")
Expand Down

0 comments on commit 8ba0e2a

Please sign in to comment.