From 2075688940594e492435f821f618636cb7965669 Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Sun, 25 Feb 2024 15:53:09 +0100 Subject: [PATCH 1/6] Add .envrc. --- .envrc | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3b588d7 --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +if has guix; then + use guix erlang elixir elixir-hex just +fi From f02a5ca3522bc04541be94e0bc2a678ce1c1ad09 Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Sun, 25 Feb 2024 17:06:17 +0100 Subject: [PATCH 2/6] Add justfile. --- justfile | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 justfile diff --git a/justfile b/justfile new file mode 100644 index 0000000..91f5a2b --- /dev/null +++ b/justfile @@ -0,0 +1,76 @@ +# 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_IMAGE := if arch() == "aarch64" { "ghcr.io/baosystems/postgis:12-3.3" } else { env_var_or_default('DB_DOCKER_IMAGE', "postgis/postgis:12-3.3-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 lib/mix + +deps-get: + mix deps.get + +deps-update: + mix deps.update --all + +common-mix-tasks-setup: deps-get + mkdir -p lib/mix/ + cd lib/mix/ && (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 From 46ca203f7bd6a05688c6413951384610ef58d17f Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Sun, 25 Feb 2024 17:06:28 +0100 Subject: [PATCH 3/6] Add CI. --- .github/workflows/main.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..a8b9d41 --- /dev/null +++ b/.github/workflows/main.yml @@ -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 From 559c013ed542a178837b2f4aad55f69a44e76721 Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Sun, 25 Feb 2024 18:49:06 +0100 Subject: [PATCH 4/6] Add release CI. --- .github/workflows/release.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0705e2b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,23 @@ +name: Release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Run tests + uses: bonfire-networks/bonfire-extension-ci-action@latest + + - name: Github Release + uses: ncipollo/release-action@v1 + + - name: Publish to Hex.pm + uses: erlangpack/github-action@v3 + env: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} From b78b2631684b26ccae98dd147d517d3914f182d8 Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Sun, 25 Feb 2024 21:39:21 +0100 Subject: [PATCH 5/6] Update .gitignore --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 96b4e95..a85b1c1 100755 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,10 @@ deps.path .\#* assets/js/_hooks/ -assets/css \ No newline at end of file +assets/css + +# Mix tasks +lib/mix + +# Migrations +priv/repo/migrations/*.exs From 703865d627d2c7c069437d8b5f9c92ff423e5f2c Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Sun, 3 Mar 2024 17:20:13 +0100 Subject: [PATCH 6/6] Load runtime config before running tests. --- config/runtime.exs | 5 +++++ test/test_helper.exs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 config/runtime.exs diff --git a/config/runtime.exs b/config/runtime.exs new file mode 100644 index 0000000..d1bc057 --- /dev/null +++ b/config/runtime.exs @@ -0,0 +1,5 @@ +import Config + + +IO.puts("Load runtime config...") +Bonfire.Common.Config.LoadExtensionsConfig.load_configs(Bonfire.Common.RuntimeConfig) diff --git a/test/test_helper.exs b/test/test_helper.exs index f47a698..b05ad52 100755 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,6 +1,6 @@ -IO.puts("Prepare to run tests...") - +IO.puts("Start app...") Application.ensure_all_started(:bonfire) +IO.puts("Prepare to run tests...") Code.ensure_loaded!(Bonfire.Testing) Bonfire.Testing.configure_start_test()