Skip to content

Commit

Permalink
workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanminutillo committed Jan 10, 2025
1 parent 83a30b7 commit f34bbc6
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if has guix; then
use guix erlang elixir elixir-hex just
fi
109 changes: 109 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Main branch

on:
push:
branches:
- "main"
paths-ignore:
- '.envrc'
- '.gitignore'
- README.*
- LICENSE
pull_request:
paths-ignore:
- '.envrc'
- '.gitignore'
- README.*
- LICENSE
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

permissions:
contents: read

# Stop previous jobs if they are still running.
# https://docs.github.com/en/actions/learn-github-actions/expressions
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
concurrency:
# Use github.run_id on main branch
# Use github.event.pull_request.number on pull requests, so it's unique per pull request
# Use github.ref on other branches, so it's unique per branch
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
lint:

name: lint
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
# the following can be uncommented if viable resource-wise
# - pair: # Test very old Elixir and Erlang
# elixir: "1.14"
# otp: "25"
# - pair: # Test Erlang without -doc attribute support
# elixir: "1.16"
# otp: "26"
- pair: # Test Erlang with -doc attribute support
elixir: "1.17.3"
otp: "27"

steps:
- uses: actions/checkout@v4

- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.pair.elixir }}
otp-version: ${{ matrix.pair.otp }}

- name: Add Prebuilt-MPR Repository
run: |
wget -qO - 'https://proget.makedeb.org/debian-feeds/prebuilt-mpr.pub' | gpg --dearmor | sudo tee /usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg 1> /dev/null
echo "deb [arch=all,$(dpkg --print-architecture) signed-by=/usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg] https://proget.makedeb.org prebuilt-mpr $(lsb_release -cs)" | sudo tee /etc/apt/sources.list.d/prebuilt-mpr.list
sudo apt update
shell: bash

- name: Install just
run: sudo apt install just
shell: bash

- name: Setup deps
run: just deps-get deps-compile

- name: Dialyzer
run: just dialyzer --format github

- name: Lint
run: just lint


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

strategy:
fail-fast: false
matrix:
include:
# the following can be uncommented if viable resource-wise
# - pair: # Test very old Elixir and Erlang
# elixir: "1.14"
# otp: "25"
# - pair: # Test Erlang without -doc attribute support
# elixir: "1.16"
# otp: "26"
- pair: # Test Erlang with -doc attribute support
elixir: "1.17.3"
otp: "27"

steps:
- name: Run tests
uses: bonfire-networks/bonfire-extension-ci-action@latest
with:
elixir-version: ${{ matrix.pair.elixir }}
otp-version: ${{ matrix.pair.otp }}
17 changes: 11 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# The directory Mix will write compiled artifacts to.
# The directories Mix/etc will write compiled artifacts to.
/_build/
.cache
.hex
.mix
assets/node_modules
assets/*.log
priv/cldr

# If you run "mix test --cover", coverage assets end up here.
/cover/
Expand All @@ -20,10 +26,9 @@ erl_crash.dump
*.ez

# Ignore package tarball (built via "mix hex.build").
bonfire_social-*.tar


# Temporary files for e.g. tests
/tmp
bonfire_*-*.tar

# ignore local mess deps
deps.path

/data
147 changes: 147 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# recipes for the `just` command runner: https://just.systems
# how to install: https://github.com/casey/just#packages

# the central source of truth for Bonfire extension project boilerplate
# is tracked at https://github.com/bonfire-networks/bonfire-extension-boilerplate

# 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 := env_var_or_default("APP_VSN_EXTRA", "")
DB_TESTS := env_var_or_default('DB_TESTS', "1")
WARNINGS_AS_ERRORS := env_var_or_default('WARNINGS_AS_ERRORS', "0")
DB_DOCKER_VERSION := env_var_or_default('DB_DOCKER_VERSION', "17-3.5")
DB_DOCKER_IMAGE := env_var_or_default('DB_DOCKER_IMAGE', if arch() == "aarch64" { "ghcr.io/baosystems/postgis:"+DB_DOCKER_VERSION } else { "docker.io/postgis/postgis:"+DB_DOCKER_VERSION+"-alpine" })
DB_STARTUP_TIME := env_var_or_default("DB_STARTUP_TIME", "10")
POSTGRES_PORT := env_var_or_default("POSTGRES_PORT", "5432")
MIX_ENV := env_var_or_default("MIX_ENV", "test")
POSTGRES_USER := env_var_or_default("POSTGRES_USER", "postgres")
POSTGRES_PASSWORD := env_var_or_default("POSTGRES_PASSWORD", "postgres")
POSTGRES_DB := env_var_or_default("POSTGRES_DB", "localhost:" + POSTGRES_PORT)
OCI_RUNTIME := if `command -v docker || true` =~ 'docker' {
"docker"
} else if `command -v podman || true` =~ "podman" {
"podman"
} else {
""
}

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


#### COMMANDS ####

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

check-unused:
mix deps.unlock --check-unused

check-formatted:
mix format --check-formatted

lint: check-unused check-formatted

dialyzer *args:
mix dialyzer {{args}}

deps-compile:
mix deps.compile

compile:
#!/usr/bin/env bash
set -eu
if [ "$WARNINGS_AS_ERRORS" = "1" ]; then
args="--warnings-as-errors"
else
args=""
fi

mix compile $args

clean: stop-test-db clean-symlinks
mix deps.clean --all
rm -rf .hex .mix .cache _build deps

clean-symlinks:
find lib/ -type l -delete

boilerplate-update:
mkdir -p .bonfire-extension-boilerplate .github/workflows
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 +FLAGS='--all':
mix deps.update {{FLAGS}}

@common-mix-tasks-setup:
#!/usr/bin/env bash
set -eu
mkdir -p lib/mix

cd lib/mix

if [ -d ../../deps/bonfire_common/lib/mix_tasks ]; then
ln -sf ../../deps/bonfire_common/lib/mix_tasks tasks
else
ln -sf ../mix_tasks tasks
fi

cd tasks/release

MIX_ENV=prod mix escript.build

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 *args:
mix test {{args}}

test *args: setup-db (run-tests args)

@setup-db:
#!/usr/bin/env bash
set -eu
if [ "$DB_TESTS" = "1" ]; then
just --justfile {{justfile()}} start-test-db ext-migrations-copy create-test-db
fi
create-test-db:
mix ecto.create -r Bonfire.Common.Repo

start-test-db:
{{OCI_RUNTIME}} run --name test-db -d -p {{POSTGRES_PORT}}:5432 -e POSTGRES_USER=${POSTGRES_USER} -e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} --rm ${DB_DOCKER_IMAGE}
# Let the db start
sleep {{DB_STARTUP_TIME}}

stop-test-db:
{{OCI_RUNTIME}} 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 add mix.exs && git commit -m "Release v${version}" && git tag "v${version}"

push-release: release
git push
git push --tags

0 comments on commit f34bbc6

Please sign in to comment.