Skip to content

Commit

Permalink
config: github CI
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedsoupe committed Nov 18, 2023
1 parent 8b053b2 commit aeaa78d
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 58 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: deps

on:
push:
pull_request:

env:
MIX_ENV: test

jobs:
deps:
name: Dependencies
runs-on: ubuntu-latest
strategy:
matrix:
elixir: [1.15.7]
otp: [26.1.2]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
mix deps.compile
95 changes: 70 additions & 25 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,78 @@ name: lint

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
workflow_run:
workflows: [deps]
types:
- completed

env:
MIX_ENV: test

jobs:
build:
runs-on: ubuntu-latest
env:
GHCR_USERNAME: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
FORCE_COLOR: 1
compile:
name: Check compile warning
run-ons: ubuntu-latest
strategy:
matrix:
elixir: [1.15.7]
otp: [26.1.2]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- run: mix compile --warnings-as-errors
format:
name: Code format
run-ons: ubuntu-latest
strategy:
matrix:
elixir: [1.15.7]
otp: [26.1.2]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-elixir
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- run: mix format --check-formatted
credo:
name: Static Code Analysis
run-ons: ubuntu-latest
strategy:
matrix:
elixir: [1.15.7]
otp: [26.1.2]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-elixir
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- run: mix credo --strict
dialyzer:
name: Dialyzer
run-ons: ubuntu-latest
strategy:
matrix:
elixir: [1.15.7]
otp: [26.1.2]
steps:
- uses: actions/checkout@v3
- name: Put back the git branch into git (Earthly uses it for tagging)
run: |
branch=""
if [ -n "$GITHUB_HEAD_REF" ]; then
branch="$GITHUB_HEAD_REF"
else
branch="${GITHUB_REF##*/}"
fi
git checkout -b "$branch" || true
- name: Docker Login
run: docker login https://ghcr.io --username "$GHCR_USERNAME" --password "$GHCR_TOKEN"
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Earthly version
run: earthly --version
- name: Run lint
run: earthly -P +ci
with:
fetch-depth: 0
- uses: actions/setup-elixir
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- run: mix dialyzer --no-check
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: release

on:
push:
tags:
- '*'
workflow_run:
workflows: [deps lint test]
types:
- completed

jobs:
publish:
runs-ons: ubuntu-latest
matrix:
elixir: [1.15.7]
otp: [26.1.2]
steps:
- uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Publish to Hex
uses: synchronal/hex-publish-action@v3
with:
name: supabase_potion
key: ${{ secrets.HEX_PM_KEY }}
tag-release: true
53 changes: 27 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
name: test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
push:
branches: [main]
pull_request:
workflow_run:
workflows: [deps lint]
types:
- completed

env:
MIX_ENV: test

jobs:
build:
test:
name: Run tests
runs-on: ubuntu-latest
env:
GHCR_USERNAME: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
FORCE_COLOR: 1
needs:
- deps
- lint
strategy:
matrix:
elixir: [1.15.7]
otp: [26.1.2]
steps:
- uses: actions/checkout@v3
- name: Put back the git branch into git (Earthly uses it for tagging)
run: |
branch=""
if [ -n "$GITHUB_HEAD_REF" ]; then
branch="$GITHUB_HEAD_REF"
else
branch="${GITHUB_REF##*/}"
fi
git checkout -b "$branch" || true
- name: Docker Login
run: docker login https://ghcr.io --username "$GHCR_USERNAME" --password "$GHCR_TOKEN"
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Earthly version
run: earthly --version
- name: Run unit tests
run: earthly -P +unit-test
with:
fetch-depth: 0
- uses: actions/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- run: mix test

5 changes: 0 additions & 5 deletions lib/supabase.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,11 @@ defmodule Supabase do
@spec init_client(params) :: {:ok, pid} | {:error, changeset}
when params: Client.params()
def init_client(%{} = opts) do
conn = Map.get(opts, :conn, %{})
opts = maybe_merge_config_from_application(conn, opts)

with {:ok, opts} <- Client.parse(opts) do
name = ClientRegistry.named(opts.name)
client_opts = [name: name, client_info: opts]
ClientSupervisor.start_child({Client, client_opts})
end
rescue
_ -> {:error, :missing_config}
end

def init_client!(%{} = opts) do
Expand Down
4 changes: 2 additions & 2 deletions test/supabase_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule SupabaseTest do
})

assert pid == ClientRegistry.lookup(:test)
assert client = Client.retrieve_client(:test)
assert {:ok, client} = Client.retrieve_client(:test)
assert client.name == :test
assert client.conn.base_url == "https://test.supabase.co"
assert client.conn.api_key == "test"
Expand Down Expand Up @@ -53,7 +53,7 @@ defmodule SupabaseTest do
})

assert pid == ClientRegistry.lookup(:test2)
assert client = Client.retrieve_client(:test2)
assert {:ok, client} = Client.retrieve_client(:test2)
assert client.name == :test2
assert client.conn.base_url == "https://test.supabase.co"
assert client.conn.api_key == "test"
Expand Down

0 comments on commit aeaa78d

Please sign in to comment.