diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml new file mode 100644 index 0000000..debb473 --- /dev/null +++ b/.github/workflows/fly-deploy.yml @@ -0,0 +1,16 @@ +name: Fly Deploy +on: + push: + branches: + - main +jobs: + deploy: + name: Deploy app + runs-on: ubuntu-latest + concurrency: deploy-group + steps: + - uses: actions/checkout@v4 + - uses: superfly/flyctl-actions/setup-flyctl@master + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/lib/hello_phx.ex b/lib/hello_phx.ex index b7ba728..a0a97df 100644 --- a/lib/hello_phx.ex +++ b/lib/hello_phx.ex @@ -7,7 +7,8 @@ defmodule HelloPhx do if it comes from the database, an external API or others. """ - @app Application.get_application(__MODULE__) + # Application.get_application(__MODULE__) + @app :hello_phx def app, do: @app def vsn, do: Application.spec(app(), :vsn) diff --git a/lib/mix/tasks/version.ex b/lib/hello_phx/commit.ex similarity index 78% rename from lib/mix/tasks/version.ex rename to lib/hello_phx/commit.ex index 9fccacc..7cba6e8 100644 --- a/lib/mix/tasks/version.ex +++ b/lib/hello_phx/commit.ex @@ -1,27 +1,15 @@ -defmodule Mix.Tasks.Version do - use Mix.Task - - @shortdoc "Get project version" - +defmodule HelloPhx.Commit do @moduledoc """ - Support version info from git commands or .git/refs/heads/main file + Get commit info from git command or .git/refs/heads/main file git log -1 --format="%H %ct" git log -1 origin/main --format="%H %cd" --date=local """ - @impl Mix.Task - - def run(_args) do - latest_commit() - |> inspect(pretty: true, width: 80) - |> Mix.shell().info - end - - @branch "main" - @head_file ".git/refs/heads/#{@branch}" + @git_branch "main" + @head_file ".git/refs/heads/#{@git_branch}" - def latest_commit do + def latest do git_cmd_path() |> case do nil -> diff --git a/lib/hello_phx_web/controllers/page_html/home.html.heex b/lib/hello_phx_web/controllers/page_html/home.html.heex index 4fa55f8..6cda1c0 100644 --- a/lib/hello_phx_web/controllers/page_html/home.html.heex +++ b/lib/hello_phx_web/controllers/page_html/home.html.heex @@ -52,11 +52,16 @@ v<%= Application.spec(:phoenix, :vsn) %> -

<.link href={~p"/products"}> Explore Products

-

RunMode: <%= HelloPhx.run_mode() %> || Locale: <%= @locale %>

- <%= if HelloPhx.run_mode() == :dev do %> - <.link href="https://hello-phx-up.fly.dev" target="_blank">Fly app - <% end %> +

+ <.link href={~p"/products"}> Explore Products + || + <%= if HelloPhx.run_mode() == :dev do %> + <.link href="https://hello-phx-up.fly.dev" target="_blank">Go Fly app + <% end %> +

+

+ RunMode: <%= HelloPhx.run_mode() %> || <%= HelloPhx.Commit.latest().version %> || Locale: <%= @locale %> +

Peace of mind from prototype to production. diff --git a/lib/mix/tasks/commit.ex b/lib/mix/tasks/commit.ex new file mode 100644 index 0000000..cbcea12 --- /dev/null +++ b/lib/mix/tasks/commit.ex @@ -0,0 +1,13 @@ +defmodule Mix.Tasks.Commit do + use Mix.Task + + @shortdoc "Get commit info" + @requirements ["app.start"] + + @impl Mix.Task + def run(_args) do + HelloPhx.Commit.latest() + |> inspect(pretty: true, width: 80) + |> Mix.shell().info + end +end diff --git a/mix.exs b/mix.exs index 5981d9d..a508c6b 100644 --- a/mix.exs +++ b/mix.exs @@ -1,6 +1,5 @@ defmodule HelloPhx.MixProject do use Mix.Project - # Code.require_file("lib/mix/tasks/version.ex", __DIR__) def project do [ @@ -119,6 +118,5 @@ defmodule HelloPhx.MixProject do def test_demo_task(_args) do Mix.shell().info("mix env: #{Mix.env()}") - Mix.Tasks.Version.run(nil) end end