Skip to content

Commit

Permalink
ci: setup dialyzer & test matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed Nov 24, 2023
1 parent 8fcdad2 commit b5d2705
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 42 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/release.yml
Expand Up @@ -27,6 +27,7 @@ jobs:
persist-credentials: false

- name: Set up Elixir
id: setup-beam
uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0
with:
version-type: strict
Expand All @@ -35,20 +36,20 @@ jobs:
- name: Restore dependencies cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
env:
cache-name: mix-deps
cache-key: deps
with:
path: deps
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-${{ env.cache-name }}-
key: ${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}-git-${{ github.sha }}
restore-keys: |
${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}
${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}
path: |
deps
_build
- name: Restore build cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
env:
cache-name: mix-build
with:
path: _build
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-${{ env.cache-name }}-
- name: Install dependencies
run: |
mix local.hex --force
mix do deps.get, deps.compile
- name: Use Node.js LTS
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4
Expand Down
124 changes: 95 additions & 29 deletions .github/workflows/test.yml
Expand Up @@ -12,64 +12,130 @@ on:
permissions:
contents: read

env:
MIX_ENV: test

jobs:
# ignore the push event trigger if a PR is open for the current branch
prevent-duplicate-checks:
prevent_duplicate_checks:
runs-on: ubuntu-latest
steps:
- uses: insurgent-lab/is-in-pr-action@78ecb5daf15aca198aeb2b6f208aabd06b2cb716 # v0.1.4
- uses: insurgent-lab/is-in-pr-action@3e01b38aa0d2a0e51bbc84540300303ec850e80d # v0.1.5
id: isInPR
outputs:
should-run: ${{ !(steps.isInPR.outputs.result == 'true' && github.event_name == 'push') }}

test:
name: Build and test
test_matrix:
name: Test (Elixir ${{matrix.elixir}} | OTP ${{matrix.otp}})

runs-on: ubuntu-latest
timeout-minutes: 5
runs-on: ${{ matrix.os }}
timeout-minutes: 10

needs: prevent_duplicate_checks
if: ${{ needs.prevent_duplicate_checks.outputs.should-run == 'true' }}

needs: prevent-duplicate-checks
if: ${{ needs.prevent-duplicate-checks.outputs.should-run == 'true' }}
strategy:
fail-fast: false
matrix:
include:
- elixir: 1.12.x
otp: 22
os: ubuntu-20.04
- elixir: 1.13.x
otp: 23
os: ubuntu-20.04
- elixir: 1.14.x
otp: 24
os: ubuntu-22.04
- elixir: 1.15.x
otp: 25
os: ubuntu-22.04
- elixir: 1.16.x
otp: 26
os: ubuntu-latest

env:
MIX_ENV: test

steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set up Elixir
- name: Set up BEAM
id: setup-beam
uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0
with:
version-type: strict
version-file: .tool-versions
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}

- name: Restore dependencies cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
env:
cache-name: mix-deps
cache-key: deps
with:
path: deps
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-${{ env.cache-name }}-

- name: Restore build cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
env:
cache-name: mix-build
with:
path: _build
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-${{ env.cache-name }}-
key: ${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}-git-${{ github.sha }}
restore-keys: |
${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}
${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}
path: |
deps
_build
- name: Install dependencies
run: mix deps.get
run: |
mix local.hex --force
mix do deps.get, deps.compile
- name: Check formatting
run: mix format --check-formatted

- name: Compile code (without warning) and deps
- name: Compile code (without warning)
run: mix compile --warnings-as-errors

- name: Run tests
run: mix test

# Dialyzer

- name: Restore PLTs cache
id: restore_plts_cache
uses: actions/cache/restore@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
env:
cache-key: plts
with:
key: ${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}-git-${{ github.sha }}
restore-keys: |
${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}
${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}
path: priv/plts

- name: Create PLTs
if: steps.restore_plts_cache.outputs.cache-hit != 'true'
run: |
mkdir -p priv/plts/core.plt
mix dialyzer --plt
- name: Save PLTs cache
uses: actions/cache/save@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
env:
cache-key: plts
if: steps.restore_plts_cache.outputs.cache-hit != 'true'
with:
key: ${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}-git-${{ github.sha }}
path: priv/plts

- name: Run dialyzer
run: mix dialyzer --format github

# separate job to set as required status check in branch protection
required_check:
runs-on: ubuntu-latest
needs:
- prevent_duplicate_checks
- test_matrix

if: ${{ !cancelled() && needs.prevent_duplicate_checks.outputs.should-run == 'true' }}
steps:
- name: All required jobs and matrix versions passed
if: ${{ !(contains(needs.*.result, 'failure')) }}
run: exit 0
- name: Some required jobs or matrix versions failed
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -27,3 +27,7 @@ gpg_ex-*.tar

# Node.js dependencies directory
node_modules

# Dialyzer
/priv/plts/*.plt
/priv/plts/*.plt.hash
11 changes: 10 additions & 1 deletion mix.exs
Expand Up @@ -9,9 +9,10 @@ defmodule GPGex.MixProject do
[
app: :gpg_ex,
version: "0.1.0",
elixir: "~> 1.12.3 or ~> 1.13",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
dialyzer: dialyzer(),
description: description(),
package: package(),
docs: docs()
Expand All @@ -20,10 +21,18 @@ defmodule GPGex.MixProject do

defp deps do
[
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
]
end

defp dialyzer() do
[
plt_local_path: "priv/plts/project.plt",
plt_core_path: "priv/plts/core.plt"
]
end

defp description() do
"""
A simple wrapper to run GPG commands.
Expand Down
2 changes: 2 additions & 0 deletions mix.lock
@@ -1,5 +1,7 @@
%{
"dialyxir": {:hex, :dialyxir, "1.4.2", "764a6e8e7a354f0ba95d58418178d486065ead1f69ad89782817c296d0d746a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "516603d8067b2fd585319e4b13d3674ad4f314a5902ba8130cd97dc902ce6bbd"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.30.9", "d691453495c47434c0f2052b08dd91cc32bc4e1a218f86884563448ee2502dd2", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "d7aaaf21e95dc5cddabf89063327e96867d00013963eadf2c6ad135506a8bc10"},
"makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
Expand Down

0 comments on commit b5d2705

Please sign in to comment.