Skip to content

Commit

Permalink
try fly cd
Browse files Browse the repository at this point in the history
  • Loading branch information
cao7113 committed Jun 29, 2024
1 parent d09ec91 commit ca9178a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 25 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 2 additions & 1 deletion lib/hello_phx.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 5 additions & 17 deletions lib/mix/tasks/version.ex → lib/hello_phx/commit.ex
Original file line number Diff line number Diff line change
@@ -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 ->
Expand Down
15 changes: 10 additions & 5 deletions lib/hello_phx_web/controllers/page_html/home.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@
v<%= Application.spec(:phoenix, :vsn) %>
</small>
</h1>
<p><.link href={~p"/products"}> Explore Products</.link></p>
<p>RunMode: <%= HelloPhx.run_mode() %> || Locale: <%= @locale %></p>
<%= if HelloPhx.run_mode() == :dev do %>
<.link href="https://hello-phx-up.fly.dev" target="_blank">Fly app</.link>
<% end %>
<p>
<.link href={~p"/products"}> Explore Products</.link>
||
<%= if HelloPhx.run_mode() == :dev do %>
<.link href="https://hello-phx-up.fly.dev" target="_blank">Go Fly app</.link>
<% end %>
</p>
<p>
RunMode: <%= HelloPhx.run_mode() %> || <%= HelloPhx.Commit.latest().version %> || Locale: <%= @locale %>
</p>

<p class="text-[2rem] mt-4 font-semibold leading-10 tracking-tighter text-zinc-900 text-balance">
Peace of mind from prototype to production.
Expand Down
13 changes: 13 additions & 0 deletions lib/mix/tasks/commit.ex
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule HelloPhx.MixProject do
use Mix.Project
# Code.require_file("lib/mix/tasks/version.ex", __DIR__)

def project do
[
Expand Down Expand Up @@ -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

0 comments on commit ca9178a

Please sign in to comment.