Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 2
updates:
- package-ecosystem: mix
directory: "/"
schedule:
interval: weekly
time: "17:00"
timezone: Europe/London
ignore:
# ignore all patch updates in dev dependencies ref: github.com/dwyl/technology-stack/issues/126
- dependency-name: "credo"
update-types: ["version-update:semver-patch"]
- dependency-name: "excoveralls"
update-types: ["version-update:semver-patch"]
- dependency-name: "ex_doc"
update-types: ["version-update:semver-patch"]
- dependency-name: "esbuild"
update-types: ["version-update:semver-patch"]
- dependency-name: "floki"
update-types: ["version-update:semver-patch"]
- dependency-name: "gettext"
update-types: ["version-update:semver-patch"]
- dependency-name: "mock"
update-types: ["version-update:semver-patch"]
- dependency-name: "phoenix_live_dashboard"
update-types: ["version-update:semver-patch"]
- dependency-name: "phoenix_live_reload"
update-types: ["version-update:semver-patch"]
32 changes: 32 additions & 0 deletions .github/scripts/review-apps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
set -e

echo "Review App Script"
# create "unique" name for fly review app
app=$APP_NAME
secrets="AUTH_API_KEY=$AUTH_API_KEY ENCRYPTION_KEYS=$ENCRYPTION_KEYS"

if [ "$EVENT_ACTION" = "closed" ]; then
flyctl apps destroy "$app" -y
exit 0
elif ! flyctl status --app "$app"; then
# create application
echo "lauch application"
flyctl launch --no-deploy --copy-config --name "$app" --region "$FLY_REGION" --org "$FLY_ORG"

# attach existing posgres
echo "attach postgres cluster - create new database based on app_name"
flyctl postgres attach "$FLY_POSTGRES_NAME" -a "$app"

# add secrets
echo "add AUTH_API_KEY and ENCRYPTION_KEYS envs"
echo $secrets | tr " " "\n" | flyctl secrets import --app "$app"

# deploy
echo "deploy application"
flyctl deploy --app "$app" --region "$FLY_REGION" --strategy immediate

else
echo "deploy updated application"
flyctl deploy --app "$app" --region "$FLY_REGION" --strategy immediate
fi

72 changes: 72 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Elixir CI

on:
push:
branches: [ main ]

jobs:

# Build and testing
build:
name: Build and test
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12
ports: ['5432:5432']
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
otp: ['25.1.2']
elixir: ['1.14.2']
steps:
- uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- name: Restore deps and _build cache
uses: actions/cache@v3
with:
path: |
deps
_build
key: deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}
- name: Install dependencies
run: mix deps.get
- name: Check code is formatted
run: mix format --check-formatted
- name: Run Tests
run: mix coveralls.json
env:
MIX_ENV: test
AUTH_API_KEY: ${{ secrets.AUTH_API_KEY }}
ENCRYPTION_KEYS: ${{ secrets.ENCRYPTION_KEYS }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3


# Continuous Deployment to Fly.io
# https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
# deploy:
# name: Deploy app
# runs-on: ubuntu-latest
# needs: [build]
# # https://stackoverflow.com/questions/58139406/only-run-job-on-specific-branch-with-github-actions
# if: github.ref == 'refs/heads/main'
# env:
# FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
# steps:
# - uses: actions/checkout@v3
# - uses: superfly/flyctl-actions@1.1
# with:
# args: "deploy"
19 changes: 19 additions & 0 deletions .github/workflows/fix-typos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Automatically fix typos
on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: main
- uses: sobolevn/misspell-fixer-action@master
- uses: peter-evans/create-pull-request@v4.2.0
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
with:
token: ${{ secrets.GITHUB_TOKEN }}
128 changes: 128 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: PR CI

on:
pull_request:
branches: [ main ]
types: [opened, reopened, synchronize, closed]

jobs:

# BUILD AND UNIT TESTING
build:

# Only run when not closed
if: github.event.pull_request.action != 'closed'

name: Build and Test
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12
ports: ['5432:5432']
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
otp: ['25.1.2']
elixir: ['1.14.2']
steps:
- uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- name: Restore deps and _build cache
uses: actions/cache@v3
with:
path: |
deps
_build
key: deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}
- name: Install dependencies
run: mix deps.get
- name: Check code is formatted
run: mix format --check-formatted
- name: Run Tests
run: mix coveralls.json
env:
MIX_ENV: test
AUTH_API_KEY: ${{ secrets.AUTH_API_KEY }}
ENCRYPTION_KEYS: ${{ secrets.ENCRYPTION_KEYS }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1



# # DEPLOY THE REVIEW APP
# # This will deploy an app to fly.io with the name 'mvp-pr-$PR_NUMBER' (check `review-apps.sh` script).
# review_app:

# # Only run when it's not a dependabot PR
# if: github.event.pull_request.user.login != 'dependabot[bot]'

# name: Review App Job
# runs-on: ubuntu-latest
# # needs: [build]
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3

# - name: Install flyctl
# uses: superfly/flyctl-actions/setup-flyctl@master

# - name: Set up Elixir
# uses: erlef/setup-beam@v1
# with:
# otp-version: 24.3.4
# elixir-version: 1.14.1

# - name: Run Review App Script
# run: ./.github/scripts/review-apps.sh
# env:
# ENCRYPTION_KEYS: ${{ secrets. ENCRYPTION_KEYS }}
# AUTH_API_KEY: ${{ secrets.FLY_AUTH_API_KEY }}
# APP_NAME: ${{ format('mvp-pr-{0}', github.event.number) }}
# EVENT_ACTION: ${{ github.event.action }}
# FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
# FLY_ORG: dwyl-mvp
# FLY_REGION: lhr
# FLY_POSTGRES_NAME: mvp-db


# API DEFINITION TESTING - https://docs.hoppscotch.io/cli
# NOTE: The tests are executed sequentially in each folder
# but all the sequence of folders are run in reverse order of what's displayed in the GUI.
# We've made use of env variables to make it work. Take this into account if you want to add more requests.
# api_definition:

# # Only run when not closed
# if: github.event.pull_request.action != 'closed'

# name: API Definition Tests
# runs-on: ubuntu-latest
# needs: [review_app]
# steps:
# - uses: actions/checkout@v3

# # After the app is deployed, we need to change the host
# # in the `lib/api/fly_dev.json` so the API tests work and target the deployed app.
# - name: Update lib/api/fly_dev.json description
# uses: jossef/action-set-json-field@v2.1
# with:
# file: ./lib/api/fly_dev.json
# field: host
# value: ${{ format('https://mvp-pr-{0}.fly.dev', github.event.number) }}

# - name: Install Hoppscotch CLI
# run: npm i -g @hoppscotch/cli@0.3.0

# - name: Running server and Hoppscotch Tests
# run: hopp test -e ./lib/api/fly_dev.json ./lib/api/MVP.json
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ before beginning.

```sh
elixir -v
Elixir 1.10.1 (compiled with Erlang/OTP 22)
Elixir 1.16.0 (compiled with Erlang/OTP 26)

mix phx.new -v
v1.4.13
Phoenix installer v1.7.10

psql --version
psql (PostgreSQL) 12.1
psql (PostgreSQL) 14.8
```

If you are new to (or rusty on) Elixir/Phoenix,
we _recommend_ reading
[dwyl/**learn-elixir**](https://github.com/dwyl/learn-elixir) <br />
Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# is restricted to this project.

# General application configuration
use Mix.Config
import Config

config :app,
ecto_repos: [App.Repo]
Expand Down
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# Configure your database
config :app, App.Repo,
Expand Down
2 changes: 1 addition & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# For production, don't forget to configure the url host
# to something meaningful, Phoenix uses this information
Expand Down
4 changes: 2 additions & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# Configure your database
config :app, App.Repo,
Expand All @@ -15,4 +15,4 @@ config :app, AppWeb.Endpoint,
server: false

# Print only warnings and errors during test
config :logger, level: :warn
config :logger, level: :warning
4 changes: 0 additions & 4 deletions lib/app_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@ defmodule AppWeb.Router do
get "/", PageController, :index
end

# Other scopes may use custom stacks.
# scope "/api", AppWeb do
# pipe_through :api
# end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule App.MixProject do
version: "1.0.0",
elixir: "~> 1.9",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
compilers: [:phoenix] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps(),
Expand Down
Loading