Skip to content

Commit

Permalink
Merge pull request #177 from nimblehq/release/4.0.0
Browse files Browse the repository at this point in the history
Release - 4.0.0
  • Loading branch information
andyduong1920 authored Mar 4, 2022
2 parents 7d9a367 + 18ed81b commit cf5cd4f
Show file tree
Hide file tree
Showing 202 changed files with 6,473 additions and 1,648 deletions.
10 changes: 8 additions & 2 deletions .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
"apps/*/test/",
"apps/*/web/"
],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
excluded: [
~r"/_build/",
~r"/deps/",
~r"/node_modules/",
~r"/lib/nimble_template/addons/addon.ex",
~r"/test/support/addon_case.ex"
]
},
#
# Load and configure plugins here:
Expand Down Expand Up @@ -87,7 +93,7 @@
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
#
{Credo.Check.Design.TagTODO, [exit_status: 2]},
{Credo.Check.Design.TagTODO, [exit_status: 0]},
{Credo.Check.Design.TagFIXME, []},

#
Expand Down
6 changes: 3 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ https://github.com/nimblehq/elixir-templates/issues/??

## What happened

Describe the big picture of your changes here to communicate to the team why we should accept this pull request.
Describe the big picture of your changes here to communicate to the team why we should accept this pull request.

## Insight

Describe in details how to test the changes, which solution you tried but did not go with, referenced documentation is welcome as well.

## Proof Of Work

Show us the implementation: screenshots, gif, etc.
32 changes: 32 additions & 0 deletions .github/wiki/Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Prefer to use the image from the Hexpm team instead of the Docker team, the reason below
was mentioned on the [Elixir Forums](https://elixirforum.com/t/yet-another-elixir-and-erlang-docker-image/28740):

- Image tags are not immutable.
- Delay in the availability of new versions.
- Cannot pick the combination of Elixir and Erlang versions you want.

Refer:

- [hexpm/elixir](https://hub.docker.com/r/hexpm/elixir)
- [hexpm/erlang](https://hub.docker.com/r/hexpm/erlang)

Example Dockerfile:

```dockerfile
FROM hexpm/elixir:1.11.0-erlang-23.1.1-alpine-3.12.0 AS build

....
FROM alpine:3.12.0 AS app
...

COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/app ./
...
```

Based on the image tag, it's clear which versions we use in the Build Release step

- Elixir: 1.11.0
- Erlang: 23.1.1
- Alpine: 3.12.0

Easily we can choose the OS to run the app on, that is `alpine:3.12.0`
1 change: 1 addition & 0 deletions .github/wiki/Home.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Phoenix/Mix template for projects at Nimble.
135 changes: 135 additions & 0 deletions .github/wiki/Testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
NimbleTemplate uses Github Actions as the CI, the workflow files are located under the [.github/workflows/](https://github.com/nimblehq/elixir-templates/tree/develop/.github/workflows) directory.

There are 2 types of tests, **Template tests** and **Variant tests**

## 1/ Template test

All test files are located under `test/` directory.

```text
.
├── ...
├── test
│ ├── ...
│ ├── nimble_template
│ │ └── addons
│ │ │ ├── ...
│ │ │ ├── common_mix_phoenix_addon_test.exs
│ │ │ └── variants
│ │ │ │ └── mix
│ │ │ │ │ ├── ...
│ │ │ │ │ └── mix_addon_test.exs
│ │ │ │ └── phoenix
│ │ │ │ │ └── common_phoenix_addon_test.exs
│ │ │ │ │ └── api
│ │ │ │ │ │ ├── ...
│ │ │ │ │ │ └── api_addon_test.exs
│ │ │ │ │ └── live
│ │ │ │ │ │ ├── ...
│ │ │ │ │ │ └── live_addon_test.exs
│ │ │ │ │ └── web
│ │ │ │ │ │ ├── ...
│ │ │ │ │ │ └── web_addon_test.exs
```

## 2/ Variant test

NimbleTemplate supports 4 variants:

- Mix
- Web
- API
- Live

### 2.1/ Mix project

A Mix project could be either a Standard project or a Custom project.

- `mix new awesome_project`
- `mix new awesome_project --module=CustomModuleName`
- `mix new awesome_project --app=custom_otp_app_name`
- `mix new awesome_project --module=CustomModuleName --app=custom_otp_app_name`

Each project could include a `supervision tree`.

- `mix new awesome_project`
- `mix new awesome_project --sup`
- `mix new awesome_project --module=CustomModuleName --app=custom_otp_app_name`
- `mix new awesome_project --module=CustomModuleName --app=custom_otp_app_name --sup`

Adding it all together, totals to 4 variant test cases.

- Applying the `Mix variant` to a `Standard Mix project`
- Applying the `Mix variant` to a `Custom Mix project`
- Applying the `Mix variant` to a `Standard Mix project with the --sup option`
- Applying the `Mix variant` to a `Custom Mix project with the --sup option`

### 2.2/ Phoenix project

A Phoenix project could be either a Web, LiveView, or API.

- Web variants support HTML and Assets.

```bash
mix phx.new awesome_project --no-live
```

- LiveView projects include HTML and Assets configuration.

```bash
mix phx.new awesome_project
```

- API variants do NOT support HTML and Assets configuration.

```bash
mix phx.new awesome_project --no-html --no-assets
```

- Custom project variants allow us to modify the app name or module name.

```bash
# Use CustomModuleName
mix phx.new awesome_project --module=CustomModuleName

# Use custom OTP app name
mix phx.new awesome_project --app=custom_otp_app_name

# Use custom module and app name
mix phx.new awesome_project --module=CustomModuleName --app=custom_otp_app_name
```

So it ends up with 6 project types:

Web project

- Standard (`mix phx.new awesome_project --no-live`)
- Custom (`mix phx.new awesome_project --no-live --module=CustomModuleName --app=custom_otp_app_name`)

API project

- Standard (`mix phx.new awesome_project --no-html --no-assets`)
- Custom (`mix phx.new awesome_project --no-html --no-assets --module=CustomModuleName --app=custom_otp_app_name`)

LiveView project

- Standard (`mix phx.new awesome_project`)
- Custom (`mix phx.new awesome_project --module=CustomModuleName --app=custom_otp_app_name`)

Putting it all together, there are 8 variants of test cases.

- Applying the `API variant` to a `Standard Web project`
- Applying the `API variant` to a `Custom Web project`
- Applying the `API variant` to a `Standard API project`
- Applying the `API variant` to a `Custom API project`
- Applying the `Web variant` to a `Standard Web project`
- Applying the `Web variant` to a `Custom Web project`
- Applying the `Live variant` to a `Standard LiveView project`
- Applying the `Live variant` to a `Custom LiveView project`

## Note

Make sure the Phoenix version is the same between local development and CI, otherwise there will be some error in the unit test.

- Phoenix version on CI can be found in: `.github/workflows/test_template.yml`
- Install a correct Phoenix version on local via command: `mix archive.install hex phx_new __PHOENIX_VERSION__`
1 change: 1 addition & 0 deletions .github/wiki/_Footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**Developed by [Nimble](https://nimblehq.co/)**
8 changes: 8 additions & 0 deletions .github/wiki/_Sidebar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Table of Contents

- [[Home]]

## Architecture

- [[Docker]]
- [[Testing]]
File renamed without changes.
32 changes: 32 additions & 0 deletions .github/workflows/apply_api_variant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Apply API variant

on: push

jobs:
standard_api_project:
name: Test on a Standard API project
uses: ./.github/workflows/reusable_phoenix_project.yml
with:
new_project_options: "--no-html --no-assets"
variant: "api"

non-standard_api_project:
name: Test on a Non-Standard API project
uses: ./.github/workflows/reusable_phoenix_project.yml
with:
new_project_options: "--no-html --no-assets --module=SampleCustomModule --app=sample_custom_app"
variant: "api"

standard_web_project:
name: Test on a Standard Web project
uses: ./.github/workflows/reusable_phoenix_project.yml
with:
new_project_options: ""
variant: "api"

non-standard_web_project:
name: Test on a Non-Standard Web project
uses: ./.github/workflows/reusable_phoenix_project.yml
with:
new_project_options: "--module=SampleCustomModule --app=sample_custom_app"
variant: "api"
18 changes: 18 additions & 0 deletions .github/workflows/apply_live_variant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Apply Live variant

on: push

jobs:
standard_project:
name: Test on a Standard Live project
uses: ./.github/workflows/reusable_phoenix_project.yml
with:
new_project_options: ""
variant: "live"

non-standard_project:
name: Test on a Non-Standard Live project
uses: ./.github/workflows/reusable_phoenix_project.yml
with:
new_project_options: "--module=SampleCustomModule --app=sample_custom_app"
variant: "live"
28 changes: 28 additions & 0 deletions .github/workflows/apply_mix_variant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Apply Mix variant

on: push

jobs:
standard_mix_project:
name: Test on a Standard Mix project
uses: ./.github/workflows/reusable_mix_project.yml
with:
new_project_options: ""

non-standard_mix_project:
name: Test on a Non-Standard Mix project
uses: ./.github/workflows/reusable_mix_project.yml
with:
new_project_options: "--module=SampleCustomModule --app=sample_custom_app"

standard_mix_supervision_project:
name: Test on a Standard Supervision Mix project
uses: ./.github/workflows/reusable_mix_project.yml
with:
new_project_options: "--sup"

non-standard_mix_supervision_project:
name: Test on a Non-Standard Supervision Mix project
uses: ./.github/workflows/reusable_mix_project.yml
with:
new_project_options: "--sup --module=SampleCustomModule --app=sample_custom_app"
18 changes: 18 additions & 0 deletions .github/workflows/apply_web_variant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Apply Web variant

on: push

jobs:
standard_project:
name: Test on a Standard Web project
uses: ./.github/workflows/reusable_phoenix_project.yml
with:
new_project_options: "--no-live"
variant: "web"

non-standard_project:
name: Test on a Non-Standard Web project
uses: ./.github/workflows/reusable_phoenix_project.yml
with:
new_project_options: "--no-live --module=SampleCustomModule --app=sample_custom_app"
variant: "web"
20 changes: 13 additions & 7 deletions .github/workflows/publish_to_hex_pm.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Publish to Hex.pm"
name: Publish to Hex package manager

on:
workflow_run:
Expand All @@ -11,24 +11,30 @@ on:
workflow_dispatch:

env:
OTP_VERSION: 23.3
ELIXIR_VERSION: 1.11.4
OTP_VERSION: 24.2.2
ELIXIR_VERSION: 1.13.3

jobs:
jobs:
publish:
name: Publish hex package

runs-on: ubuntu-latest

if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2

- name: Checkout repository
uses: actions/checkout@v2
with:
ref: ${{ github.event.workflow_run.head_branch || github.ref }}

- uses: erlef/setup-elixir@v1
- name: Set up Elixir ${{ env.ELIXIR_VERSION }} and OTP ${{ env.OTP_VERSION }}
uses: erlef/setup-elixir@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/publish_wiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Publish Wiki

on:
push:
branches:
- develop
paths:
- .github/wiki/**

jobs:
publish:
name: Publish wiki
uses: nimblehq/github-actions-workflows/.github/workflows/[email protected]
with:
USER_NAME: github-wiki-action
USER_EMAIL: [email protected]
secrets:
USER_TOKEN: ${{ secrets.WIKI_ACTION_TOKEN }}
Loading

0 comments on commit cf5cd4f

Please sign in to comment.