Skip to content

Commit

Permalink
Add elixir workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwinchester committed May 2, 2024
1 parent 71802c4 commit 37084df
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 3 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/elixir-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Elixir Package
on:
workflow_dispatch:
push:
branches:
- "main"
paths:
- "eventsub.json"
- "packages/elixir/**"
jobs:
call-test:
uses: ./.github/workflows/elixir-test.yml

build-and-publish:
name: Build and Publish
needs: call-test
runs-on: ubuntu-latest
steps:
- run: echo "TODO - Build package"
92 changes: 92 additions & 0 deletions .github/workflows/elixir-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Elixir Test
on:
workflow_call:
pull_request:
branches:
- "main"
paths:
- "eventsub.json"
- "packages/elixir/**"
jobs:
test:
name: Test
runs-on: ${{matrix.os}}
strategy:
matrix:
os: ["ubuntu-latest"]
elixir: ["1.16.x"]
otp: ["26.x"]
steps:
# Setup.
- name: Checkout repo
uses: actions/checkout@v3
with:
sparse-checkout: "packages/elixir"
sparse-checkout-cone-mode: false

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

# Build cache.
- name: Build cache
uses: actions/cache/restore@v3
with:
path: _build
key: build-${{matrix.os}}-${{matrix.otp}}-${{matrix.elixir}}-${{ hashFiles('lib/**/*.ex') }}
restore-keys: build-${{matrix.os}}-${{matrix.otp}}-${{matrix.elixir}}-

# Get and compile elixir deps.
- name: Elixir Deps cache
uses: actions/cache/restore@v3
with:
path: deps
key: mix-${{ matrix.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('**/mix.lock') }}
restore-keys: mix-${{ matrix.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-
- run: mix deps.get
- run: mix deps.compile

# Compile :dev and :test.
- run: MIX_ENV=dev mix compile --warnings-as-errors
- run: MIX_ENV=test mix compile

# Check for unused dependencies.
- run: mix deps.unlock --check-unused

# Check code quality and style.
- run: mix format --check-formatted
- run: mix credo

- run: mix test --warnings-as-errors

# Restore Dialyzer cache
- name: Restore PLT cache
uses: actions/cache/restore@v3
id: plt_cache
with:
path: priv/plts
key: plt-${{ matrix.os }}-${{ matrix.elixir }}-${{ matrix.otp }}
restore-keys: plt-${{ matrix.os }}-${{ matrix.elixir }}-${{ matrix.otp }}

# Create PLTs if no cache was found
- name: Create PLTs
if: steps.plt_cache.outputs.cache-hit != 'true'
run: mix dialyzer --plt

# By default, the GitHub Cache action will only save the cache if all steps in the job succeed,
# so we separate the cache restore and save steps in case running dialyzer fails.
- name: Save PLT cache
id: plt_cache_save
uses: actions/cache/save@v3
if: steps.plt_cache.outputs.cache-hit != 'true'
with:
key: |
plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}
path: |
priv/plts
- name: Run dialyzer
run: mix dialyzer --format github
3 changes: 3 additions & 0 deletions packages/elixir/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ twitch_eventsub_types-*.tar

# Temporary files, for example, from tests.
/tmp/

/priv/plts/*.plt
/priv/plts/*.plt.hash
7 changes: 4 additions & 3 deletions packages/elixir/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ defmodule TwitchEventSub.MixProject do
version: "0.1.0",
elixir: "~> 1.16",
start_permanent: Mix.env() == :prod,
deps: deps()
deps: deps(),
dialyzer: [plt_file: {:no_warn, "priv/plts/project.plt"}]
]
end

Expand All @@ -21,8 +22,8 @@ defmodule TwitchEventSub.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}
]
end
end

0 comments on commit 37084df

Please sign in to comment.