Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI. #5

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Main branch

on:
push:
branches:
- "main"
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
test:

name: Build and test
runs-on: ubuntu-latest

steps:
- name: Run tests
uses: bonfire-networks/bonfire-extension-ci-action@latest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ bonfire_web_phoenix-*.tar

# ignore local mess deps
deps.path

# Ignore bonfire_common mix tasks symlink
lib/mix/tasks
13 changes: 9 additions & 4 deletions config/bonfire_common.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import Config

default_locale = "en"

config :bonfire,
localisation_path: "priv/localisation"

config :bonfire_common,
otp_app: :bonfire
otp_app: :bonfire,
ecto_repos: [Bonfire.Common.Repo],
localisation_path: "priv/localisation"

## Localisation & internationalisation
# TODO: determine which keys can be set at runtime vs compile-time
Expand Down Expand Up @@ -43,3 +42,9 @@ config :ex_cldr,
default_locale: default_locale,
default_backend: Bonfire.Common.Localise.Cldr,
json_library: Jason

# Choose password hashing backend
# Note that this corresponds with our dependencies in mix.exs
hasher = if config_env() in [:dev, :test], do: Pbkdf2, else: Argon2

config :bonfire_data_identity, Bonfire.Data.Identity.Credential, hasher_module: hasher
82 changes: 82 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# recipes for the `just` command runner: https://just.systems
# how to install: https://github.com/casey/just#packages

# we load all vars from .env file into the env of just commands
set dotenv-load
# and export just vars as env vars
set export

## Main configs - override these using env vars

APP_VSN_EXTRA := ""
DB_DOCKER_VERSION := env_var_or_default('DB_DOCKER_VERSION', "16-3.4")
DB_DOCKER_IMAGE := env_var_or_default('DB_DOCKER_IMAGE', if arch() == "aarch64" { "ghcr.io/baosystems/postgis:"+DB_DOCKER_VERSION } else { "postgis/postgis:"+DB_DOCKER_VERSION+"-alpine" })
export MIX_ENV := "test"
export POSTGRES_PASSWORD := "postgres"

## Configure just
# choose shell for running recipes
set shell := ["bash", "-uc"]
# support args like $1, $2, etc, and $@ for all args
set positional-arguments


#### COMMANDS ####

help:
@echo "Just commands:"
@just --list

compile: deps-get
mix compile

clean:
mix deps.clean --all
rm -rf .hex .mix .cache _build deps lib/mix/tasks

boilerplate-update:
mkdir -p .bonfire-extension-boilerplate
git clone https://github.com/bonfire-networks/bonfire-extension-boilerplate.git --branch main --single-branch .bonfire-extension-boilerplate
cd .bonfire-extension-boilerplate && cp .envrc justfile .gitignore .. && cp .github/workflows/main.yml ../.github/workflows/main.yml && cp lib/mix/mess.ex ../mess.exs
rm -rf .bonfire-extension-boilerplate

deps-get:
mix deps.get

deps-update:
mix deps.update --all

common-mix-tasks-setup: deps-get
cd lib/mix/ && ([ -d ../../deps/bonfire_common/lib/mix_tasks ] && ln -sf ../../deps/bonfire_common/lib/mix_tasks tasks || ln -sf ../mix_tasks tasks) && cd -
cd lib/mix/tasks/release/ && MIX_ENV=prod mix escript.build && cd -

ext-migrations-copy: common-mix-tasks-setup
mkdir -p priv/repo
mix bonfire.extension.copy_migrations --to priv/repo/migrations --repo Bonfire.Common.Repo --force

run-tests:
mix test

test: start-test-db ext-migrations-copy create-test-db run-tests

create-test-db:
mix ecto.create -r Bonfire.Common.Repo

start-test-db:
docker run --name test-db -d -p "5432:5432" -e POSTGRES_PASSWORD --rm ${DB_DOCKER_IMAGE}

stop-test-db:
docker rm -f test-db

@release-increment: common-mix-tasks-setup
#!/usr/bin/env bash
set -euxo pipefail
export MIX_ENV="prod"
lib/mix/tasks/release/release ./ {{APP_VSN_EXTRA}}

release: release-increment
version="$(grep -E 'version: \"(.*)\",' mix.exs | sed -E 's/^.*version: \"(.*)\",$/\1/')"; git commit -m "Release v${version}" && git tag "v${version}"

push-release: release
git push
git push --tags
2 changes: 1 addition & 1 deletion lib/config_settings/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ defmodule Bonfire.Common.Config do
get(keys_tree, default, otp_app)
end

if Application.compile_env!(:bonfire, :env) == :test do
if Application.compile_env(:bonfire, :env, :unset) == :test do
# NOTE: enables using `ProcessTree` in test env, eg. `Process.put([:bonfire_common, :my_key], :value)`
def get(keys, default, otp_app) when is_list(keys),
do: get_for_process([otp_app] ++ keys) || get_config(keys, default, otp_app)
Expand Down
2 changes: 1 addition & 1 deletion lib/config_settings/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ defmodule Bonfire.Common.Settings do
get([key], default, opts)
end

if Application.compile_env!(:bonfire, :env) == :test do
if Application.compile_env(:bonfire, :env, :unset) == :test do
# NOTE: enables using `ProcessTree` in test env, eg. `Process.put([:bonfire_common, :my_key], :value)`
def get_settings(keys, default, otp_app, opts) when is_list(keys),
do: get_for_process([otp_app] ++ keys) || do_get_settings(keys, default, otp_app, opts)
Expand Down
1 change: 0 additions & 1 deletion lib/mix_tasks/mix_tasks

This file was deleted.

2 changes: 1 addition & 1 deletion lib/repo/repo_template.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Bonfire.Common.RepoTemplate do
alias Bonfire.Common.Errors

use Ecto.Repo,
otp_app: Config.get(:umbrella_otp_app) || Config.get!(:otp_app),
otp_app: Config.get(:umbrella_otp_app) || Config.get(:otp_app, :bonfire),
adapter: Ecto.Adapters.Postgres

import Ecto.Query
Expand Down
Loading
Loading