Skip to content

Commit

Permalink
Merge pull request #69 from nimblehq/release/2.1.0
Browse files Browse the repository at this point in the history
Release/2.1.0
  • Loading branch information
andyduong1920 authored Dec 16, 2020
2 parents 1f5840d + 660f9be commit b73e730
Show file tree
Hide file tree
Showing 48 changed files with 807 additions and 143 deletions.
10 changes: 7 additions & 3 deletions .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 100]},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, false},
{Credo.Check.Readability.ModuleNames, []},
Expand Down Expand Up @@ -136,7 +136,7 @@
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.LazyLogging, []},
{Credo.Check.Warning.MixEnv, false},
{Credo.Check.Warning.MixEnv, []},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
Expand All @@ -156,7 +156,11 @@
#
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
#
{Credo.Check.Readability.StrictModuleLayout, []},
{Credo.Check.Readability.StrictModuleLayout,
[
order:
~w/shortdoc moduledoc behaviour use import alias require module_attribute defstruct callback/a
]},
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{Credo.Check.Consistency.UnusedVariableNames, []},
{Credo.Check.Design.DuplicatedCode, []},
Expand Down
5 changes: 3 additions & 2 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
line_length: 100,
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"]
]
47 changes: 47 additions & 0 deletions .github/workflows/publish_to_hex_pm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Publish to Hex.pm"

on:
workflow_run:
workflows:
- Test template
branches:
- master
types:
- completed
workflow_dispatch:

env:
OTP_VERSION: 23.1.4
ELIXIR_VERSION: 1.11.2

jobs:
publish:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.workflow_run.head_branch || github.ref }}

- uses: actions/setup-elixir@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}

- name: Cache Elixir build
uses: actions/cache@v2
with:
path: |
_build
deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-
- name: Install Dependencies
run: mix deps.get

- name: Publish to Hex.pm
run: mix hex.publish --yes
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
8 changes: 4 additions & 4 deletions .github/workflows/test_api_variant_on_custom_api_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: "Test API variant on custom API project"
on: push

env:
OTP_VERSION: 23.1.1
ELIXIR_VERSION: 1.11.1
PHOENIX_VERSION: 1.5.5
OTP_VERSION: 23.1.4
ELIXIR_VERSION: 1.11.2
PHOENIX_VERSION: 1.5.7

jobs:
unit_test:
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
restore-keys: |
${{ runner.os }}-mix-
- uses: nimblehq/elixir-templates@composite_1.0
- uses: nimblehq/elixir-templates@composite_1.1
with:
new_project_options: '--no-html --no-webpack --module=CustomModule --app=custom_app'
variant: 'api'
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: "Test API variant on standard API project"
on: push

env:
OTP_VERSION: 23.1.1
ELIXIR_VERSION: 1.11.1
PHOENIX_VERSION: 1.5.5
OTP_VERSION: 23.1.4
ELIXIR_VERSION: 1.11.2
PHOENIX_VERSION: 1.5.7

jobs:
unit_test:
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
restore-keys: |
${{ runner.os }}-mix-
- uses: nimblehq/elixir-templates@composite_1.0
- uses: nimblehq/elixir-templates@composite_1.1
with:
new_project_options: '--no-html --no-webpack'
variant: 'api'
13 changes: 4 additions & 9 deletions .github/workflows/test_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: "Test template"
on: push

env:
OTP_VERSION: 23.1.1
ELIXIR_VERSION: 1.11.1
PHOENIX_VERSION: 1.5.5
OTP_VERSION: 23.1.4
ELIXIR_VERSION: 1.11.2
PHOENIX_VERSION: 1.5.7

jobs:
unit_test:
Expand Down Expand Up @@ -36,16 +36,11 @@ jobs:

- name: Install Phoenix ${{ env.PHOENIX_VERSION }}
run: make install_phoenix PHOENIX_VERSION=${{ env.PHOENIX_VERSION }}

- name: Compile
run: mix compile --warnings-as-errors
env:
MIX_ENV: test

- name: Run codebase check
run: mix codebase

- name: Run Tests
run: mix test
run: mix do compile --warnings-as-errors, test
env:
MIX_ENV: test
8 changes: 4 additions & 4 deletions .github/workflows/test_variant_on_custom_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: "Test variant on custom Web project"
on: push

env:
OTP_VERSION: 23.1.1
ELIXIR_VERSION: 1.11.1
PHOENIX_VERSION: 1.5.5
OTP_VERSION: 23.1.4
ELIXIR_VERSION: 1.11.2
PHOENIX_VERSION: 1.5.7
NODE_VERSION: 12

jobs:
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
restore-keys: |
${{ runner.os }}-npm-packages-
- uses: nimblehq/elixir-templates@composite_1.0
- uses: nimblehq/elixir-templates@composite_1.1
with:
new_project_options: '--module=CustomModule --app=custom_app'
variant: ${{ matrix.variant }}
8 changes: 4 additions & 4 deletions .github/workflows/test_variant_on_standard_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: "Test variant on standard Web project"
on: push

env:
OTP_VERSION: 23.1.1
ELIXIR_VERSION: 1.11.1
PHOENIX_VERSION: 1.5.5
OTP_VERSION: 23.1.4
ELIXIR_VERSION: 1.11.2
PHOENIX_VERSION: 1.5.7
NODE_VERSION: 12

jobs:
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
restore-keys: |
${{ runner.os }}-npm-packages-
- uses: nimblehq/elixir-templates@composite_1.0
- uses: nimblehq/elixir-templates@composite_1.1
with:
new_project_options: ''
variant: ${{ matrix.variant }}
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 23.1.1
elixir 1.11.0-otp-23
erlang 23.1.4
elixir 1.11.2-otp-23
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@ create_project:
# Y - in response to Will you host this project on Github?
# Y - in response to Do you want to generate the .github/ISSUE_TEMPLATE and .github/PULL_REQUEST_TEMPLATE?
# Y - in response to Do you want to generate the Github Action workflow?
# Y - in response to Would you like to add the Oban addon?
common_addon_prompts = Y\nY\nY\nY\n

web_addon_prompts =

api_addon_prompts =

# Y - in response to Fetch and install dependencies?
post_setup_addon_prompts = Y\n

apply_template:
cd ${PROJECT_DIRECTORY} && \
echo '{:nimble_phx_gen_template, path: "../", only: :dev},' > nimble_phx_gen_template.txt && \
echo '{:nimble_phx_gen_template, path: "../", only: :dev, runtime: false},' > nimble_phx_gen_template.txt && \
sed -i -e '/{:phoenix, "~> /r nimble_phx_gen_template.txt' mix.exs && \
rm nimble_phx_gen_template.txt && \
mix deps.get && \
mix format && \
printf "Y\nY\nY\nY\n" | mix nimble.phx.gen.template --${VARIANT}
if [ $(VARIANT) = web ]; then \
printf "${common_addon_prompts}${web_addon_prompts}${post_setup_addon_prompts}" | mix nimble.phx.gen.template --web; \
elif [ $(VARIANT) = api ]; then \
printf "${common_addon_prompts}${api_addon_prompts}${post_setup_addon_prompts}" | mix nimble.phx.gen.template --api; \
fi;

remove_nimble_phx_gen_template:
cd ${PROJECT_DIRECTORY} && \
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ Project repository template to set up all public Phoenix projects at [Nimble](ht

## Installation

NimblePhxGenTemplate is published on Hex. Add it to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:nimble_phx_gen_template, git: "https://github.com/nimblehq/elixir-templates", branch: "master", only: :dev}
{:nimble_phx_gen_template, "~> 2.1.0", only: :dev, runtime: false}
]
end
```
Expand Down Expand Up @@ -94,6 +96,16 @@ Putting it all together, it is 6 variant test cases.
- Applying the `Web variant` to a `Standard Web project`
- Applying the `Web variant` to a `Custom Web project`

### Release

Set the `HEX_API_KEY` as a Github secret (skip this step if it has been done).

The release process follows the [Git flow](https://nimblehq.co/compass/development/version-control/#releases-).

Once a `release/<version number>` is created, to publish the new version to Hex.pm, the version number in the `mix.ex` file needs to be updated on the release branch before merging.

Once the release branch is merged into the `master` branch, Github Action will automatically publish the template to https://hex.pm/packages/nimble_phx_gen_template.

## License

This project is Copyright (c) 2014-2020 Nimble. It is free software,
Expand Down
13 changes: 5 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ runs:
run: make apply_template PROJECT_DIRECTORY=sample_project VARIANT=${{ inputs.variant }}
shell: bash

- name: Install Dependencies
- name: Install Elixir Dependencies
run: cd sample_project && mix deps.get
shell: bash

- name: Run mix compile
run: cd sample_project && mix compile --warnings-as-errors
- name: Install Node Dependencies
run: cd sample_project && npm install --prefix assets
shell: bash
env:
MIX_ENV: test
DB_HOST: localhost


- name: Run mix ecto.create
run: cd sample_project && mix ecto.create
shell: bash
Expand All @@ -57,7 +54,7 @@ runs:
DB_HOST: localhost

- name: Run mix test
run: cd sample_project && mix coverage
run: cd sample_project && mix do compile --warnings-as-errors, coverage
shell: bash
env:
MIX_ENV: test
Expand Down
6 changes: 2 additions & 4 deletions lib/nimble.phx.gen.template/addon.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule Nimble.Phx.Gen.Template.Addon do
@behaviour Addon

alias Nimble.Phx.Gen.Template.{Generator, Project}
alias Nimble.Phx.Gen.Template.Hex.Package

def apply(%Project{} = project, opts \\ %{}) when is_map(opts) do
Generator.print_log("* applying ", inspect(__MODULE__))
Expand All @@ -19,12 +20,9 @@ defmodule Nimble.Phx.Gen.Template.Addon do
def do_apply(%Project{} = project, opts) when is_map(opts), do: project

defp latest_package_version(package) do
"~> " <> hex_package(Mix.env()).get_latest_version(package)
"~> " <> Package.get_latest_version(package)
end

defp hex_package(:test), do: Nimble.Phx.Gen.Template.Hex.PackageMock
defp hex_package(_env), do: Nimble.Phx.Gen.Template.Hex.Package

defoverridable do_apply: 2
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/nimble.phx.gen.template/addons/credo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ defmodule Nimble.Phx.Gen.Template.Addons.Credo do
Generator.replace_content(
"mix.exs",
"""
codebase: ["format --check-formatted"],
codebase: ["deps.unlock --check-unused", "format --check-formatted"],
""",
"""
codebase: ["format --check-formatted", "credo --strict"],
codebase: ["deps.unlock --check-unused", "format --check-formatted", "credo --strict"],
"""
)

Expand Down
17 changes: 15 additions & 2 deletions lib/nimble.phx.gen.template/addons/ex_machina.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,28 @@ defmodule Nimble.Phx.Gen.Template.Addons.ExMachina do
defp edit_files(%Project{} = project) do
project
|> inject_mix_dependency()
|> edit_mix_elixirc_paths()
|> edit_test_helper()
|> import_factory()

project
end

defp inject_mix_dependency(%Project{} = project) do
Generator.inject_mix_dependency(
{:ex_machina, latest_package_version(:ex_machina), only: :test}
Generator.inject_mix_dependency({:ex_machina, latest_package_version(:ex_machina), only: :test})

project
end

def edit_mix_elixirc_paths(%Project{} = project) do
Generator.replace_content(
"mix.exs",
"""
defp elixirc_paths(:test), do: ["lib", "test/support"]
""",
"""
defp elixirc_paths(:test), do: ["lib", "test/support", "test/factories"]
"""
)

project
Expand Down
Loading

0 comments on commit b73e730

Please sign in to comment.